diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 17:22:16 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 17:22:16 -0800 |
commit | bea7c5af891e0a6dee9b2551cd3632848f652fa1 (patch) | |
tree | f7010829c5877a21d34f46615b5e5b7025925930 /src | |
parent | d2e86e43d69252f7262c5a17f9c4e0ff8ba75753 (diff) | |
download | binaryen-bea7c5af891e0a6dee9b2551cd3632848f652fa1.tar.gz binaryen-bea7c5af891e0a6dee9b2551cd3632848f652fa1.tar.bz2 binaryen-bea7c5af891e0a6dee9b2551cd3632848f652fa1.zip |
detect which calls are to imports in s2wasm
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 45f12fdb7..1c3568aff 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -41,6 +41,8 @@ private: typedef std::pair<std::vector<char>*, Name> Relocation; // the data, and the name whose address we should place there std::vector<Relocation> relocations; + std::set<Name> implementedFunctions; + // utilities void skipWhitespace() { @@ -227,6 +229,17 @@ private: // processors void scan() { + while (*s) { + s = strstr(s, "\n .type "); + if (!s) break; + mustMatch("\n .type "); + Name name = getCommaSeparated(); + skipComma(); + if (!match("@function")) continue; + mustMatch(name.str); + mustMatch(":"); + implementedFunctions.insert(name); + } } void process() { @@ -434,24 +447,26 @@ private: }; auto makeCall = [&](WasmType type) { CallBase* curr; - if (match("_import")) { - curr = allocator.alloc<CallImport>(); - } else if (match("_indirect")) { - curr = allocator.alloc<CallIndirect>(); + Name assign; + if (match("_indirect")) { + auto indirect = allocator.alloc<CallIndirect>(); + assign = getAssign(); + indirect->target = getInput(); + curr = indirect; } else { - curr = allocator.alloc<Call>(); - } - Name assign = getAssign(); - if (curr->is<Call>()) { - Name name = curr->dyn_cast<Call>()->target = getCommaSeparated(); - curr->type = type; - } else if (curr->is<CallImport>()) { - Name name = curr->dyn_cast<CallImport>()->target = getCommaSeparated(); - // XXX import definitions would help here, but still undecided in .s format - } else { - curr->dyn_cast<CallIndirect>()->target = getInput(); - // XXX no way to know return type, https://github.com/WebAssembly/experimental/issues/53 + assign = getAssign(); + Name target = getCommaSeparated(); + if (implementedFunctions.count(target) > 0) { + auto plain = allocator.alloc<Call>(); + plain->target = target; + curr = plain; + } else { + auto import = allocator.alloc<CallImport>(); + import->target = target; + curr = import; + } } + curr->type = type; while (1) { if (!skipComma()) break; curr->operands.push_back(getInput()); |