summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-05-13 20:29:24 -0700
committerGitHub <noreply@github.com>2019-05-13 20:29:24 -0700
commit104d52a0e8c2e76e9496de7dae5f3e28fdd9b49e (patch)
treeea4e1bb6aae54838abb2d0245eb8496d87172153
parentb4eb90ce9bc43d9f3897bd13d6fd11f40f706b5a (diff)
downloadbinaryen-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).
-rw-r--r--src/wasm2js.h11
-rw-r--r--test/wasm2js/emscripten.2asm.js3
-rw-r--r--test/wasm2js/emscripten.2asm.js.opt3
3 files changed, 13 insertions, 4 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() {
diff --git a/test/wasm2js/emscripten.2asm.js b/test/wasm2js/emscripten.2asm.js
index 91838daf9..1d8de170a 100644
--- a/test/wasm2js/emscripten.2asm.js
+++ b/test/wasm2js/emscripten.2asm.js
@@ -1,8 +1,9 @@
-function instantiate(asmLibraryArg, wasmMemory, FUNCTION_TABLE) {
+function instantiate(asmLibraryArg, wasmMemory, wasmTable) {
function asmFunc(global, env, buffer) {
"almost asm";
var memory = env.memory;
+ var FUNCTION_TABLE = wasmTable;
var HEAP8 = new global.Int8Array(buffer);
var HEAP16 = new global.Int16Array(buffer);
var HEAP32 = new global.Int32Array(buffer);
diff --git a/test/wasm2js/emscripten.2asm.js.opt b/test/wasm2js/emscripten.2asm.js.opt
index 0c0a295e1..58c6b1c0c 100644
--- a/test/wasm2js/emscripten.2asm.js.opt
+++ b/test/wasm2js/emscripten.2asm.js.opt
@@ -1,8 +1,9 @@
-function instantiate(asmLibraryArg, wasmMemory, FUNCTION_TABLE) {
+function instantiate(asmLibraryArg, wasmMemory, wasmTable) {
function asmFunc(global, env, buffer) {
"almost asm";
var memory = env.memory;
+ var FUNCTION_TABLE = wasmTable;
var HEAP8 = new global.Int8Array(buffer);
var HEAP16 = new global.Int16Array(buffer);
var HEAP32 = new global.Int32Array(buffer);