diff options
author | Sam Clegg <sbc@chromium.org> | 2018-08-29 13:34:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-29 13:34:04 -0700 |
commit | 9723f53ec46ad83e3ff8c89b60eb64a71a8eb74c (patch) | |
tree | b8512af73202e25297db0024000342e3ecd600db | |
parent | f35b208a360882570bf97bfa7ff8d1293017dc95 (diff) | |
download | binaryen-9723f53ec46ad83e3ff8c89b60eb64a71a8eb74c.tar.gz binaryen-9723f53ec46ad83e3ff8c89b60eb64a71a8eb74c.tar.bz2 binaryen-9723f53ec46ad83e3ff8c89b60eb64a71a8eb74c.zip |
Run legalize-js-interface during wasm-emscripten-finalize (#1653)
This ensures that 64-bit values are correctly handled on the
JS boundary.
-rw-r--r-- | src/pass.h | 9 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 17 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 2 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/pass.h b/src/pass.h index 384dcf791..159d1c765 100644 --- a/src/pass.h +++ b/src/pass.h @@ -98,9 +98,12 @@ struct PassRunner { PassRunner(const PassRunner&) = delete; PassRunner& operator=(const PassRunner&) = delete; - void setDebug(bool debug_) { - options.debug = debug_; - options.validateGlobally = debug_; // validate everything by default if debugging + void setDebug(bool debug) { + options.debug = debug; + options.validateGlobally = debug; // validate everything by default if debugging + } + void setDebugInfo(bool debugInfo) { + options.debugInfo = debugInfo; } void setValidateGlobally(bool validate) { options.validateGlobally = validate; diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index b2c0cef89..4c9f8df36 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -42,6 +42,7 @@ int main(int argc, const char *argv[]) { std::string outputSourceMapUrl; bool emitBinary = true; bool debugInfo = false; + bool legalizeJavaScriptFFI = true; unsigned numReservedFunctionPointers = 0; uint64_t globalBase; Options options("wasm-emscripten-finalize", @@ -77,9 +78,16 @@ int main(int argc, const char *argv[]) { [&globalBase](Options*, const std::string&argument ) { globalBase = std::stoull(argument); }) + .add("--input-source-map", "-ism", "Consume source map from the specified file", Options::Arguments::One, [&inputSourceMapFilename](Options *o, const std::string& argument) { inputSourceMapFilename = argument; }) + .add("--no-legalize-javascript-ffi", "-nj", "Do not legalize (i64->i32, " + "f32->f64) the imports and exports for interfacing with JS", + Options::Arguments::Zero, + [&legalizeJavaScriptFFI](Options *o, const std::string& ) { + legalizeJavaScriptFFI = false; + }) .add("--output-source-map", "-osm", "Emit source map to the specified file", Options::Arguments::One, [&outputSourceMapFilename](Options *o, const std::string& argument) { outputSourceMapFilename = argument; }) @@ -139,6 +147,15 @@ int main(int argc, const char *argv[]) { EmscriptenGlueGenerator generator(wasm); generator.fixInvokeFunctionNames(); + + if (legalizeJavaScriptFFI) { + PassRunner passRunner(&wasm); + passRunner.setDebug(options.debug); + passRunner.setDebugInfo(debugInfo); + passRunner.add("legalize-js-interface"); + passRunner.run(); + } + generator.generateRuntimeFunctions(); generator.generateMemoryGrowthFunction(); generator.generateDynCallThunks(); diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 580510ecb..7b0df6827 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -605,7 +605,7 @@ struct FixInvokeFunctionNamesWalker : public PostWalker<FixInvokeFunctionNamesWa assert(importRenames.count(curr->name) == 0); importRenames[curr->name] = newname; - // Either rename of remove the existing import + // Either rename or remove the existing import if (wasm.getImportOrNull(newname) || !newImports.insert(newname).second) { toRemove.push_back(curr->name); } else { |