diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-09 17:59:56 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-09 18:30:27 -0800 |
commit | 2eab69ff78311c03757de89d0020306d4977eb83 (patch) | |
tree | 4bf7bf56b867afe7ee55c8139b18ad381b91e7f2 /src | |
parent | b91486c4e796e3a50bd1afe3a00135024131ff9f (diff) | |
download | binaryen-2eab69ff78311c03757de89d0020306d4977eb83.tar.gz binaryen-2eab69ff78311c03757de89d0020306d4977eb83.tar.bz2 binaryen-2eab69ff78311c03757de89d0020306d4977eb83.zip |
fix imports when arriving from wasm backend, which does not prefix
Diffstat (limited to 'src')
-rw-r--r-- | src/js/wasm.js-post.js | 17 | ||||
-rw-r--r-- | src/s2wasm.h | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index 98b828076..10a49254f 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -122,11 +122,25 @@ function integrateWasmJS(Module) { } } + function fixImports(imports) { + if (!{{{ WASM_BACKEND }}}) return imports; + var ret = {}; + for (var i in imports) { + var fixed = i; + if (fixed[0] == '_') fixed = fixed.substr(1); + ret[fixed] = imports[i]; + } + return ret; + } + if (typeof Wasm === 'object') { // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate // the wasm module at that time, and it receives imports and provides exports and so forth, the app // doesn't need to care that it is wasm and not asm. Module['asm'] = function(global, env, providedBuffer) { + global = fixImports(global); + env = fixImports(env); + // Load the wasm module var binary; if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { @@ -169,6 +183,9 @@ function integrateWasmJS(Module) { // The asm.js function, called to "link" the asm.js module. At that time, we are provided imports // and respond with exports, and so forth. Module['asm'] = function(global, env, providedBuffer) { + global = fixImports(global); + env = fixImports(env); + assert(providedBuffer === Module['buffer']); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way. info.global = global; diff --git a/src/s2wasm.h b/src/s2wasm.h index f87742bd0..24f39ae8d 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -1305,7 +1305,7 @@ public: } std::string sig = getSig(curr); sigsForCode[code].insert(sig); - std::string fixedTarget = std::string("_") + EMSCRIPTEN_ASM_CONST.str + '_' + sig; + std::string fixedTarget = EMSCRIPTEN_ASM_CONST.str + std::string("_") + sig; curr->target = cashew::IString(fixedTarget.c_str(), false); arg->value = Literal(id); // add import, if necessary |