diff options
-rw-r--r-- | src/js/wasm.js-post.js | 17 | ||||
-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, 22 insertions, 5 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 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 47661a90935633c5a409a87e130a2f5119824a5 |