diff options
author | Alon Zakai <azakai@google.com> | 2019-05-13 20:29:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-13 20:29:24 -0700 |
commit | 104d52a0e8c2e76e9496de7dae5f3e28fdd9b49e (patch) | |
tree | ea4e1bb6aae54838abb2d0245eb8496d87172153 /src | |
parent | b4eb90ce9bc43d9f3897bd13d6fd11f40f706b5a (diff) | |
download | binaryen-104d52a0e8c2e76e9496de7dae5f3e28fdd9b49e.tar.gz binaryen-104d52a0e8c2e76e9496de7dae5f3e28fdd9b49e.tar.bz2 binaryen-104d52a0e8c2e76e9496de7dae5f3e28fdd9b49e.zip |
wasm2js: Emit table in a way that is friendly to emscripten minification (#2102)
Set it to a local in the asmFunc scope, so that minifiers can easily see it's a simple local value (instead of using it as an upvar from the parameters higher up, which was how the emscripten glue was emitting it).
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm2js.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h index 78bfd30ff..3b563a7db 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -354,6 +354,14 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) { ValueBuilder::makeDot(ValueBuilder::makeName(ENV), ValueBuilder::makeName("memory"))); } + // for emscripten, add a table import - otherwise we would have + // FUNCTION_TABLE be an upvar, and not as easy to be minified. + if (flags.emscripten && wasm->table.exists && wasm->table.imported()) { + Ref theVar = ValueBuilder::makeVar(); + asmFunc[3]->push_back(theVar); + ValueBuilder::appendToVar( + theVar, FUNCTION_TABLE, ValueBuilder::makeName("wasmTable")); + } // create heaps, etc addBasics(asmFunc[3]); ModuleUtils::iterImportedFunctions( @@ -1781,8 +1789,7 @@ void Wasm2JSGlue::emitPre() { } void Wasm2JSGlue::emitPreEmscripten() { - out - << "function instantiate(asmLibraryArg, wasmMemory, FUNCTION_TABLE) {\n\n"; + out << "function instantiate(asmLibraryArg, wasmMemory, wasmTable) {\n\n"; } void Wasm2JSGlue::emitPreES6() { |