summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-14 19:52:18 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-14 19:52:18 -0800
commitdcef40dbc73de2496c05476379603bdf521b34fe (patch)
treec2738fec2081b6db4eade2e45ab135580fec4dd8
parent2ce78b61261357ce1c9391e318ed87e992a02587 (diff)
downloadbinaryen-dcef40dbc73de2496c05476379603bdf521b34fe.tar.gz
binaryen-dcef40dbc73de2496c05476379603bdf521b34fe.tar.bz2
binaryen-dcef40dbc73de2496c05476379603bdf521b34fe.zip
fix imports for asm const methods
-rw-r--r--src/s2wasm.h12
-rw-r--r--test/dot_s/asm_const.wast2
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