diff options
author | jgravelle-google <jgravelle@google.com> | 2017-10-02 13:51:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 13:51:55 -0700 |
commit | a9f91b9774d117a13c231ef0f40861372456878f (patch) | |
tree | 1bda2f8fed8a3affe5538732f4ac11c6b8b2599a /src/tools/s2wasm.cpp | |
parent | 28d670ade33ab7a1d091bafee243a2c5ffc93bc9 (diff) | |
download | binaryen-a9f91b9774d117a13c231ef0f40861372456878f.tar.gz binaryen-a9f91b9774d117a13c231ef0f40861372456878f.tar.bz2 binaryen-a9f91b9774d117a13c231ef0f40861372456878f.zip |
Share trap mode between asm2wasm and s2wasm (#1168)
* Extract Asm2WasmBuilder::TrapMode to shared FloatTrapMode
* Extract makeTrappingI32Binary
* Extract makeTrappingI64Binary
* Extract asm2wasm test script into scripts/test/asm2wasm.py
This matches s2wasm.py, and makes iterating on asm2wasm slightly faster.
* Simplify callsites with an arg struct
* Combine func adding across i32 and i64
* Support f32-to-int in asm2wasm
* Add BinaryenTrapMode pass, run pass from s2wasm
* BinaryenTrapMode pass takes trap context as a parameter
* Pass fully supports non-trapping binary ops
* Defer adding functions until after iteration (hackily)
* Update asm2wasm to work with deferred function adding, rebuild tests
* Extract makeTrappingFloatToInt32
* Extract makeTrappingFloatToInt64
* Add unary conversions to trap pass
* Add functions in the pass itself
* Set s2wasm trap mode with command-line arguments
* Print BINARYEN_PASS_DEBUG state when testing
* Get asm2wasm using the BinaryenTrapMode pass instead of handling it inline
* Also handle f32 to int in asm2wasm
* Make BinaryenTrapMode only need a FloatTrapMode from the caller
* Just pass the current binary Expression directly
* Combine makeTrappingI32Binary with makeTrappingI64Binary
* Pass Unary expr to makeTrappingFloatToInt32
* Unify makeTrappingFloatToInt32 & 64
* Move makeTrapping* functions inside BinaryenTrapMode, make addedFunctions non-static
* Remove FloatTrapContext
* Minor cleanups
* Extract some smaller subfunctions
* Emit name switch/casing, rename is32Bit to isI64 for consistency
* Rename BinaryenTrapMode to FloatTrap, make trap mode a nested enum
* Add some comments explaining why FloatTrap is non-parallel
* Rename addedFunctions to generatedFunctions for precision
* Rename move and split float-clamp.h to passes/FloatTrap.(h|cpp)
* Use builder instead of allocator
* Instantiate trap handling passes via the pass manager
* Move passes/FloatTrap.h to ast/trapping.h
* Add helper function to add trap-handling passes
* Add trap mode pass tests
* Rename FloatTrap.cpp to TrapMode.cpp
* Add s2wasm trap mode tests. Force float->int conversion to be signed
* Add trapping_sint_div_s test to unit.asm.js
* Fix flake8 issues with test scripts
* Update pass description comment
* Extract building functions methods
* Make generate functions into top-level functions
* Add GeneratedTrappingFunctions class to manage function/import additions
* Move ensure/makeTrapping functions outside class scope
* Use GeneratedTrappingFunctions to add immediately in asm2wasm mode
* Remove trapping_sint_div_s test
We only added it to test that trapping divisions would get
constant-folded at the correct time. Now that we're not changing the
timing of trapping modes, the test is unneeded (and problematic).
* Review feedback, add validator/*.wasm to .gitignore
* Add support for unsigned float-to-int conversion
* Use opcode directly instead of bools
* Update s2wasm clamp test for unsigned ftoi
Diffstat (limited to 'src/tools/s2wasm.cpp')
-rw-r--r-- | src/tools/s2wasm.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index a35783479..559188d1f 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -18,6 +18,7 @@ // wasm2asm console tool // +#include "ast/trapping.h" #include "support/colors.h" #include "support/command-line.h" #include "support/file.h" @@ -37,6 +38,7 @@ int main(int argc, const char *argv[]) { bool importMemory = false; std::string startFunction; std::vector<std::string> archiveLibraries; + TrapMode trapMode = TrapMode::Allow; Options options("s2wasm", "Link .s file into .wast"); options.extra["validate"] = "wasm"; options @@ -81,6 +83,24 @@ int main(int argc, const char *argv[]) { [&allowMemoryGrowth](Options *, const std::string &) { allowMemoryGrowth = true; }) + .add("--emit-potential-traps", "", + "Emit instructions that might trap, like div/rem of 0", + Options::Arguments::Zero, + [&trapMode](Options *o, const std::string &) { + trapMode = TrapMode::Allow; + }) + .add("--emit-clamped-potential-traps", "", + "Clamp instructions that might trap, like float => int", + Options::Arguments::Zero, + [&trapMode](Options *o, const std::string &) { + trapMode = TrapMode::Clamp; + }) + .add("--emit-jsified-potential-traps", "", + "Avoid instructions that might trap, handling them exactly like JS would", + Options::Arguments::Zero, + [&trapMode](Options *o, const std::string &) { + trapMode = TrapMode::JS; + }) .add("--emscripten-glue", "-e", "Generate emscripten glue", Options::Arguments::Zero, [&generateEmscriptenGlue](Options *, const std::string &) { @@ -144,6 +164,13 @@ int main(int argc, const char *argv[]) { S2WasmBuilder mainbuilder(input.c_str(), options.debug); linker.linkObject(mainbuilder); + if (trapMode != TrapMode::Allow) { + Module* wasm = &(linker.getOutput().wasm); + PassRunner runner(wasm); + addTrapModePass(runner, trapMode); + runner.run(); + } + for (const auto& m : archiveLibraries) { auto archiveFile(read_file<std::vector<char>>(m, Flags::Binary, debugFlag)); bool error; |