diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/LegalizeJSInterface.cpp | 5 | ||||
-rw-r--r-- | src/passes/RemoveNonJSOps.cpp | 5 | ||||
-rw-r--r-- | src/wasm2js.h | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index 63e4b1a6b..6002c7ad7 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -71,8 +71,7 @@ struct LegalizeJSInterface : public Pass { } // for each illegal import, we must call a legalized stub instead for (auto* im : originalFunctions) { - if (im->imported() && isIllegal(module->getFunctionType(im->type)) - && shouldBeLegalized(im)) { + if (im->imported() && isIllegal(im) && shouldBeLegalized(im)) { auto funcName = makeLegalStubForCalledImport(im, module); illegalImportsToLegal[im->name] = funcName; // we need to use the legalized version in the table, as the import from JS @@ -209,7 +208,7 @@ private: auto* call = module->allocator.alloc<Call>(); call->target = legal->name; - auto* imFunctionType = module->getFunctionType(im->type); + auto* imFunctionType = ensureFunctionType(getSig(im), module); for (auto param : imFunctionType->params) { if (param == i64) { diff --git a/src/passes/RemoveNonJSOps.cpp b/src/passes/RemoveNonJSOps.cpp index a98189584..906c34bc4 100644 --- a/src/passes/RemoveNonJSOps.cpp +++ b/src/passes/RemoveNonJSOps.cpp @@ -128,7 +128,10 @@ struct RemoveNonJSOpsPass : public WalkerPass<PostWalker<RemoveNonJSOpsPass>> { auto function = m.getFunction(name); FindAll<Call> calls(function->body); for (auto* call : calls.list) { - this->addNeededFunctions(m, call->target, needed); + auto* called = m.getFunction(call->target); + if (!called->imported()) { + this->addNeededFunctions(m, call->target, needed); + } } } diff --git a/src/wasm2js.h b/src/wasm2js.h index 34471e213..faad6c3fa 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -290,6 +290,7 @@ private: Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { PassRunner runner(wasm); runner.add<AutoDrop>(); + runner.add("legalize-js-interface"); // First up remove as many non-JS operations we can, including things like // 64-bit integer multiplication/division, `f32.nearest` instructions, etc. // This may inject intrinsics which use i64 so it needs to be run before the @@ -303,6 +304,7 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { runner.add("simplify-locals-notee-nostructure"); runner.add("reorder-locals"); runner.add("vacuum"); + runner.add("remove-unused-module-elements"); runner.setDebug(flags.debug); runner.run(); @@ -311,7 +313,7 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { #ifndef NDEBUG if (!WasmValidator().validate(*wasm)) { WasmPrinter::printModule(wasm); - Fatal() << "error in validating input"; + Fatal() << "error in validating wasm2js output"; } #endif |