diff options
-rw-r--r-- | src/s2wasm.h | 12 | ||||
-rw-r--r-- | test/dot_s/asm_const.wast | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 20cdce0c4..5f2e1d497 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -866,6 +866,8 @@ public: // extra emscripten processing void emscriptenGlue(std::ostream& o) { + wasm.removeImport(EMSCRIPTEN_ASM_CONST); // we create _sig versions + o << "; METADATA: { "; // find asmConst calls, and emit their metadata struct AsmConstWalker : public WasmWalker { @@ -874,6 +876,7 @@ public: std::map<std::string, std::set<std::string>> sigsForCode; std::map<std::string, size_t> ids; + std::set<std::string> allSigs; AsmConstWalker(S2WasmBuilder* parent) : parent(parent), o(o) {} @@ -895,6 +898,14 @@ public: fixedTarget += '_' + sig; curr->target = cashew::IString(fixedTarget.c_str(), false); arg->value = Literal(id); + // add import, if necessary + if (allSigs.count(sig) == 0) { + allSigs.insert(sig); + auto import = parent->allocator.alloc<Import>(); + import->name = import->base = curr->target; + import->module = ENV; + parent->wasm.addImport(import); + } } } @@ -922,6 +933,7 @@ public: }; AsmConstWalker walker(this); walker.startWalk(&wasm); + // print o << "\"asmConsts\": {"; bool first = true; for (auto& pair : walker.sigsForCode) { diff --git a/test/dot_s/asm_const.wast b/test/dot_s/asm_const.wast index cdfd6f1c2..76b0f4220 100644 --- a/test/dot_s/asm_const.wast +++ b/test/dot_s/asm_const.wast @@ -1,6 +1,6 @@ (module (memory 0 4294967295 (segment 16 "{ Module.print(\"hello, world!\"); }\00")) - (import $emscripten_asm_const "env" "emscripten_asm_const") + (import $emscripten_asm_const_vi "env" "emscripten_asm_const_vi") (export "main" $main) (func $main (result i32) (block $fake_return_waka123 |