diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 19:52:18 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 19:52:18 -0800 |
commit | dcef40dbc73de2496c05476379603bdf521b34fe (patch) | |
tree | c2738fec2081b6db4eade2e45ab135580fec4dd8 /src | |
parent | 2ce78b61261357ce1c9391e318ed87e992a02587 (diff) | |
download | binaryen-dcef40dbc73de2496c05476379603bdf521b34fe.tar.gz binaryen-dcef40dbc73de2496c05476379603bdf521b34fe.tar.bz2 binaryen-dcef40dbc73de2496c05476379603bdf521b34fe.zip |
fix imports for asm const methods
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 12 |
1 files changed, 12 insertions, 0 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) { |