summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2017-05-01 17:55:02 -0500
committerAlon Zakai <alonzakai@gmail.com>2017-05-01 15:55:02 -0700
commit6ae56e73d0eb3a5769af3920a2e75e0a910777bb (patch)
tree667ddee347a6e15cef6f2811f1b8f1e03a9dd3a2 /src
parentb6d42e0c28460667d9e9c992833be668d0897362 (diff)
downloadbinaryen-6ae56e73d0eb3a5769af3920a2e75e0a910777bb.tar.gz
binaryen-6ae56e73d0eb3a5769af3920a2e75e0a910777bb.tar.bz2
binaryen-6ae56e73d0eb3a5769af3920a2e75e0a910777bb.zip
--no-js-ffi opt to disable JS FFI mangling. (#984)
* Always use scripts.test.shared for bin paths. Update scripts/test/shared.py to add WASM_MERGE relative to build directory. Update auto_update_tests.py to use scripts.test.shared variables for all bin paths. Update check.py to use scripts.test.shared for wasm-merge path (this was missing). This allows check.py and auto_update_tests.py to be run from the source directory using built binaries in a different location. * --no-legalize-javascript-ffi disables JS FFI mangling. For JS/Web platform, calls to JS imports are wrapped to convert i64 to i32 and f32 to f64. Likewise calls from JS into exports do the inverse wrapping. This change provides an option to disable that wrapping and use the original types for the call. Includes tests test/noffi_f32.asm.js and test/noffi_i64.asm.js to make sure neither f32->f64 nor i64->i32 type mangling is happening when --no-legalize-javascript-ffi is specified. To fully disable JS FFI mangling when using emscripten, the fastcomp FFI mangling must also be disabled using the -emscripten-legalize-javascript-ffi=0 flag.
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h8
-rw-r--r--src/tools/asm2wasm.cpp7
-rw-r--r--src/wasm-js.cpp2
3 files changed, 13 insertions, 4 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index f78b9df55..00481c9bd 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -380,6 +380,7 @@ public:
TrapMode trapMode;
PassOptions passOptions;
+ bool legalizeJavaScriptFFI;
bool runOptimizationPasses;
bool wasmOnly;
@@ -483,7 +484,7 @@ private:
}
public:
- Asm2WasmBuilder(Module& wasm, Asm2WasmPreProcessor& preprocessor, bool debug, TrapMode trapMode, PassOptions passOptions, bool runOptimizationPasses, bool wasmOnly)
+ Asm2WasmBuilder(Module& wasm, Asm2WasmPreProcessor& preprocessor, bool debug, TrapMode trapMode, PassOptions passOptions, bool legalizeJavaScriptFFI, bool runOptimizationPasses, bool wasmOnly)
: wasm(wasm),
allocator(wasm.allocator),
builder(wasm),
@@ -491,6 +492,7 @@ public:
debug(debug),
trapMode(trapMode),
passOptions(passOptions),
+ legalizeJavaScriptFFI(legalizeJavaScriptFFI),
runOptimizationPasses(runOptimizationPasses),
wasmOnly(wasmOnly) {}
@@ -1395,7 +1397,9 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
passRunner.add<FinalizeCalls>(this);
passRunner.add<ReFinalize>(); // FinalizeCalls changes call types, need to percolate
passRunner.add<AutoDrop>(); // FinalizeCalls may cause us to require additional drops
- passRunner.add("legalize-js-interface");
+ if (legalizeJavaScriptFFI) {
+ passRunner.add("legalize-js-interface");
+ }
if (runOptimizationPasses) {
// autodrop can add some garbage
passRunner.add("vacuum");
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp
index 4ad5a5814..dd2b6a791 100644
--- a/src/tools/asm2wasm.cpp
+++ b/src/tools/asm2wasm.cpp
@@ -32,6 +32,7 @@ using namespace wasm;
int main(int argc, const char *argv[]) {
PassOptions passOptions;
+ bool legalizeJavaScriptFFI = true;
bool runOptimizationPasses = false;
Asm2WasmBuilder::TrapMode trapMode = Asm2WasmBuilder::TrapMode::JS;
bool wasmOnly = false;
@@ -95,6 +96,10 @@ int main(int argc, const char *argv[]) {
[&wasmOnly](Options *o, const std::string &) {
wasmOnly = true;
})
+ .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("--debuginfo", "-g", "Emit names section and debug info (for debug info you must emit text, -S, for this to work)",
Options::Arguments::Zero,
[&](Options *o, const std::string &arguments) { passOptions.debugInfo = true; })
@@ -139,7 +144,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "wasming..." << std::endl;
Module wasm;
wasm.memory.initial = wasm.memory.max = totalMemory / Memory::kPageSize;
- Asm2WasmBuilder asm2wasm(wasm, pre, options.debug, trapMode, passOptions, runOptimizationPasses, wasmOnly);
+ Asm2WasmBuilder asm2wasm(wasm, pre, options.debug, trapMode, passOptions, legalizeJavaScriptFFI, runOptimizationPasses, wasmOnly);
asm2wasm.processAsm(asmjs);
// import mem init file, if provided
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index 94404aeb9..dba194ee2 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -80,7 +80,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm2wasm(char *input) {
module->memory.max = pre.memoryGrowth ? Address(Memory::kMaxSize) : module->memory.initial;
if (wasmJSDebug) std::cerr << "wasming...\n";
- asm2wasm = new Asm2WasmBuilder(*module, pre, debug, Asm2WasmBuilder::TrapMode::JS, PassOptions(), false /* TODO: support optimizing? */, false /* TODO: support asm2wasm-i64? */);
+ asm2wasm = new Asm2WasmBuilder(*module, pre, debug, Asm2WasmBuilder::TrapMode::JS, PassOptions(), true /* runJSFFIPass */, false /* TODO: support optimizing? */, false /* TODO: support asm2wasm-i64? */);
asm2wasm->processAsm(asmjs);
}