diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-09 21:02:05 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-09 21:02:05 -0800 |
commit | 54eec1104b34be2c8342942870fb62390606dedf (patch) | |
tree | e6b1829b60373ca020060f2ab7db84ae9e89dc0c /src | |
parent | 5598931f54d2aefc0ea1550e41f424b830331a22 (diff) | |
parent | a3d89e6a1973670230fe304d8c204150b33263ff (diff) | |
download | binaryen-54eec1104b34be2c8342942870fb62390606dedf.tar.gz binaryen-54eec1104b34be2c8342942870fb62390606dedf.tar.bz2 binaryen-54eec1104b34be2c8342942870fb62390606dedf.zip |
Merge pull request #239 from WebAssembly/s2wasm-prefixing
Fix up exports when arriving from wasm backend output
Diffstat (limited to 'src')
-rw-r--r-- | src/js/wasm.js-post.js | 21 | ||||
-rw-r--r-- | src/s2wasm.h | 2 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index ff52e9868..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) { @@ -145,11 +159,11 @@ function integrateWasmJS(Module) { info['env'] = env; var instance; instance = Wasm.instantiateModule(binary, info); - mergeMemory(instance.memory); + mergeMemory(instance.exports.memory); applyMappedGlobals(); - return instance; + return instance.exports; }; return; @@ -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 |