diff options
author | Jacob Gravelle <jgravelle@google.com> | 2018-11-14 16:33:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 16:33:28 -0800 |
commit | a259699cfed19b56469ccff88e1c76c7199e4a45 (patch) | |
tree | 67eb708ae8146914596b9514a8a63844625adaf9 /src | |
parent | 4442d98dbfcd54c8e920bd11bb376a1003957daa (diff) | |
download | binaryen-a259699cfed19b56469ccff88e1c76c7199e4a45.tar.gz binaryen-a259699cfed19b56469ccff88e1c76c7199e4a45.tar.bz2 binaryen-a259699cfed19b56469ccff88e1c76c7199e4a45.zip |
Handle EM_ASM functions in Tables (#1739)
Not at all sure why we're seeing any there, but it's easy enough to
handle that we might as well.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index a99482d39..c61e40b1d 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -376,10 +376,12 @@ struct AsmConstWalker : public PostWalker<AsmConstWalker> { segmentOffsets(getSegmentOffsets(wasm)) { } void visitCall(Call* curr); + void visitTable(Table* curr); void process(); private: + std::string fixupNameWithSig(Name& name, std::string baseSig); Literal idLiteralForCode(std::string code); std::string asmConstSig(std::string baseSig); Name nameForImportWithSig(std::string sig); @@ -392,18 +394,24 @@ private: void AsmConstWalker::visitCall(Call* curr) { auto* import = wasm.getFunction(curr->target); if (import->imported() && import->base.hasSubstring(EMSCRIPTEN_ASM_CONST)) { + auto baseSig = getSig(curr); + auto sig = fixupNameWithSig(curr->target, baseSig); + auto arg = curr->operands[0]->cast<Const>(); auto code = codeForConstAddr(wasm, segmentOffsets, arg); arg->value = idLiteralForCode(code); - auto baseSig = getSig(curr); - auto sig = asmConstSig(baseSig); sigsForCode[code].insert(sig); - auto importName = nameForImportWithSig(sig); - curr->target = importName; + } +} - if (allSigs.count(sig) == 0) { - allSigs.insert(sig); - queueImport(importName, baseSig); +void AsmConstWalker::visitTable(Table* curr) { + for (auto& segment : curr->segments) { + for (auto& name : segment.data) { + auto* func = wasm.getFunction(name); + if (func->imported() && func->base.hasSubstring(EMSCRIPTEN_ASM_CONST)) { + std::string baseSig = getSig(func); + fixupNameWithSig(name, baseSig); + } } } } @@ -416,6 +424,18 @@ void AsmConstWalker::process() { addImports(); } +std::string AsmConstWalker::fixupNameWithSig(Name& name, std::string baseSig) { + auto sig = asmConstSig(baseSig); + auto importName = nameForImportWithSig(sig); + name = importName; + + if (allSigs.count(sig) == 0) { + allSigs.insert(sig); + queueImport(importName, baseSig); + } + return sig; +} + Literal AsmConstWalker::idLiteralForCode(std::string code) { int32_t id; if (ids.count(code) == 0) { |