diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-13 15:03:12 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-13 15:03:12 -0800 |
commit | 4b5c9e7fb5e5323cd558e33ac4c6c8f85cba2fbb (patch) | |
tree | 3f292045e95bdefe045a4a59cad4e7073eae32b6 | |
parent | de14ec0b8b1d6a40b5ec9a2e0131c2fe89b4f268 (diff) | |
download | binaryen-4b5c9e7fb5e5323cd558e33ac4c6c8f85cba2fbb.tar.gz binaryen-4b5c9e7fb5e5323cd558e33ac4c6c8f85cba2fbb.tar.bz2 binaryen-4b5c9e7fb5e5323cd558e33ac4c6c8f85cba2fbb.zip |
mention s2wasm usage
-rw-r--r-- | README.md | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -121,6 +121,26 @@ For basic tests, that command should work, but in general you need a few more ar * `ALIASING_FUNCTION_POINTERS=0` because WebAssembly does not allow aliased function pointers (there is a single table). * `GLOBAL_BASE=1000` because WebAssembly lacks global variables, so `asm2wasm` maps them onto addresses in memory. This requires that you have some reserved space for those variables. With that argument, we reserve the area up to `1000`. +### C/C++ Source => WebAssembly LLVM backend => s2wasm => WebAssembly + +Binaryen's `s2wasm` tool can translate the `.s` output from the LLVM WebAssembly backend into WebAssembly. You can receive `.s` output from `llc`, and then run `s2wasm` on that: + +```` +llc code.ll -march=wasm32 -filetype=asm -o code.s +s2wasm code.s > code.wast +```` + +You can also use Emscripten, which will do those steps for you (as well as link to system libraries, etc.): + +```` +./emcc input.cpp -s WASM_BACKEND=1 -s 'BINARYEN="path-to-binaryen"' +```` + +The `WASM_BACKEND` option tells it to use the WebAssembly backend instead of the asm.js backend. + + * Due to current limitations of the WebAssembly backend, you might want to build with `-s ONLY_MY_CODE=1 -O1`, which will avoid linking in libc (which contains varargs, which are not yet supported), and optimizes so that the stack is not used (which is also not yet supported). + * The output when building in this mode is similar to what you get in general when building with Binaryen in Emscripten: a main `.js` file, and the compiled code in a `.wast` file alongside it. + ## Testing ``` |