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 | |
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
-rw-r--r-- | src/js/wasm.js-post.js | 21 | ||||
-rw-r--r-- | src/s2wasm.h | 2 | ||||
-rw-r--r-- | test/dot_s/asm_const.wast | 4 | ||||
-rw-r--r-- | test/dot_s/memops.wast | 4 | ||||
m--------- | test/emscripten | 0 |
5 files changed, 24 insertions, 7 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 diff --git a/test/dot_s/asm_const.wast b/test/dot_s/asm_const.wast index e0d34365e..01db6592d 100644 --- a/test/dot_s/asm_const.wast +++ b/test/dot_s/asm_const.wast @@ -3,10 +3,10 @@ (segment 16 "{ Module.print(\"hello, world!\"); }\00") ) (type $FUNCSIG$vi (func (param i32))) - (import $_emscripten_asm_const_vi "env" "_emscripten_asm_const_vi" (param i32)) + (import $emscripten_asm_const_vi "env" "emscripten_asm_const_vi" (param i32)) (export "main" $main) (func $main (result i32) - (call_import $_emscripten_asm_const_vi + (call_import $emscripten_asm_const_vi (i32.const 0) ) (return diff --git a/test/dot_s/memops.wast b/test/dot_s/memops.wast index fec2ac9be..a1519a3e9 100644 --- a/test/dot_s/memops.wast +++ b/test/dot_s/memops.wast @@ -3,7 +3,7 @@ (segment 16 "{ Module.print(\"hello, world! \" + HEAP32[8>>2]); }\00") ) (type $FUNCSIG$vi (func (param i32))) - (import $_emscripten_asm_const_vi "env" "_emscripten_asm_const_vi" (param i32)) + (import $emscripten_asm_const_vi "env" "emscripten_asm_const_vi" (param i32)) (export "_Z6reporti" $_Z6reporti) (export "main" $main) (func $_Z6reporti (param $$0 i32) @@ -11,7 +11,7 @@ (i32.const 8) (get_local $$0) ) - (call_import $_emscripten_asm_const_vi + (call_import $emscripten_asm_const_vi (i32.const 0) ) (return) diff --git a/test/emscripten b/test/emscripten -Subproject 31f4ede8026f10117000be2aea95f013df84993 +Subproject 098b241c787019f54ce447d801f652dfddab2b6 |