wat2wasm can do that (part of https://github.com/webassembly/wabt). Since it's C++, I guess you could compile to it (wat2wasm) to webassembly to run in the browser as a library, and if it's works, no need for separate web/desktop version.
You might be able to find something more lightweight over here though: https://github.com/xtuc/webassemblyjs but I didn't find what you were looking for (but just did a quick look)
You might be able to find something more lightweight over here though: https://github.com/xtuc/webassemblyjs but I didn't find what you were looking for (but just did a quick look)