diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-29 13:15:34 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-29 13:15:34 -0700 |
commit | 4fc6bdf853d112f235cd70ff6608f5b38283a733 (patch) | |
tree | 2382509639e1d4fdc30b75290da566a6140f8430 | |
parent | 29bea2e426d3506a3fd510c9539797a57f542204 (diff) | |
download | binaryen-4fc6bdf853d112f235cd70ff6608f5b38283a733.tar.gz binaryen-4fc6bdf853d112f235cd70ff6608f5b38283a733.tar.bz2 binaryen-4fc6bdf853d112f235cd70ff6608f5b38283a733.zip |
support emcc --separate-asm output
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | src/asm2wasm.cpp | 19 | ||||
-rw-r--r-- | test/hello_world.wast (renamed from test/hello_world.wasm) | 0 |
3 files changed, 27 insertions, 8 deletions
@@ -32,12 +32,18 @@ Set `ASM2WASM_DEBUG=1` in the env to see debug info, about asm.js nodes as they ## Starting from C/C++ Source -[Grab Emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html), and build +[Grab Emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html), and build the source file into asm.js, for example using -Limitations: +``` +emcc src.cpp -o a.html --separate-asm +``` + +That will emit `a.html`, `a.js`, and `a.asm.js`. That last file is the asm.js module, which you can pass into `asm2wasm`. + +## TODO * WebAssembly lacks global variables, so `asm2wasm` maps them onto addresses in memory. This requires that you have some reserved space for those variables. You can do that with `emcc -s GLOBAL_BASE=1000`. We still need to write the code to copy the globals there. - * Emscripten emits asm.js and JavaScript, that work together using web APIs to do things like print, render, etc. Not sure if there is a way to test that full output yet. + * Emscripten emits asm.js and JavaScript, that work together using web APIs to do things like print, render, etc. Need to figure out how to test that. ## Testing @@ -49,5 +55,7 @@ Limitations: ## License & Contributing -Same as Emscripten: MIT license. This code is sync'ed with Emscripten's repo. +Same as Emscripten: MIT license. + +For changes to `src/`, please make pulls into emscripten's `asm2wasm` branch (this code is sync'ed with there, for convenience). diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp index f46d86c13..bdba9dac0 100644 --- a/src/asm2wasm.cpp +++ b/src/asm2wasm.cpp @@ -980,13 +980,24 @@ int main(int argc, char **argv) { fclose(f); input[num] = 0; - /* - // Separate asm modules look like + // emcc --separate-asm modules look like // // Module["asm"] = (function(global, env, buffer) { + // .. + // }); // - // , we can remove the part until the function. - */ + // we need to clean that up. + if (*input == 'M') { + while (*input != 'f') { + input++; + num--; + } + char *end = input + num - 1; + while (*end != '}') { + *end = 0; + end--; + } + } if (debug) std::cerr << "parsing...\n"; cashew::Parser<Ref, ValueBuilder> builder; diff --git a/test/hello_world.wasm b/test/hello_world.wast index 66dd61c42..66dd61c42 100644 --- a/test/hello_world.wasm +++ b/test/hello_world.wast |