diff options
author | jgravelle-google <jgravelle@google.com> | 2017-10-03 10:30:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 10:30:50 -0700 |
commit | 8283229f6bccdcfa60d7613be10d0f93531fdd34 (patch) | |
tree | 538aa36a6bb1b6d012ce5a7512345f628e68d494 /src/tools | |
parent | 1f8d8a53e8fcee0791c11345fd7f328255cfa22c (diff) | |
download | binaryen-8283229f6bccdcfa60d7613be10d0f93531fdd34.tar.gz binaryen-8283229f6bccdcfa60d7613be10d0f93531fdd34.tar.bz2 binaryen-8283229f6bccdcfa60d7613be10d0f93531fdd34.zip |
Add --trap-mode=allow/clamp/js argument to asm2wasm and s2wasm (#1210)
* Add --trap-mode=allow/clamp/js argument to asm2wasm and s2wasm
* Update asm2wasm and auto_update_tests scripts to use --trap-mode
* Throw std::invalid_argument instead of adding a new Invalid TrapMode type
* Remove legacy asm2wasm trap mode arguments
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/asm2wasm.cpp | 28 | ||||
-rw-r--r-- | src/tools/s2wasm.cpp | 32 |
2 files changed, 27 insertions, 33 deletions
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp index cbc3c486b..3ce140b04 100644 --- a/src/tools/asm2wasm.cpp +++ b/src/tools/asm2wasm.cpp @@ -18,6 +18,8 @@ // asm2wasm console tool // +#include <exception> + #include "ast/trapping.h" #include "support/colors.h" #include "support/command-line.h" @@ -78,21 +80,17 @@ int main(int argc, const char *argv[]) { [](Options *o, const std::string &) { std::cerr << "--no-opts is deprecated (use -O0, etc.)\n"; }) - .add("--emit-potential-traps", "-i", "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", "-i", "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", "-i", "Avoid instructions that might trap, handling them exactly like JS would", Options::Arguments::Zero, - [&trapMode](Options *o, const std::string &) { - trapMode = TrapMode::JS; - }) - .add("--imprecise", "-i", "Imprecise optimizations (old name for --emit-potential-traps)", Options::Arguments::Zero, - [&trapMode](Options *o, const std::string &) { - trapMode = TrapMode::Allow; + .add("--trap-mode", "", + "Strategy for handling potentially trapping instructions. Valid " + "values are \"allow\", \"js\", and \"clamp\"", + Options::Arguments::One, + [&trapMode](Options *o, const std::string &argument) { + try { + trapMode = trapModeFromString(argument); + } catch (std::invalid_argument e) { + std::cerr << "Error: " << e.what() << "\n"; + exit(EXIT_FAILURE); + } }) .add("--wasm-only", "-w", "Input is in WebAssembly-only format, and not actually valid asm.js", Options::Arguments::Zero, [&wasmOnly](Options *o, const std::string &) { diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index 559188d1f..8411d4046 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -15,9 +15,11 @@ */ // -// wasm2asm console tool +// s2wasm console tool // +#include <exception> + #include "ast/trapping.h" #include "support/colors.h" #include "support/command-line.h" @@ -83,23 +85,17 @@ 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("--trap-mode", "", + "Strategy for handling potentially trapping instructions. Valid " + "values are \"allow\", \"js\", and \"clamp\"", + Options::Arguments::One, + [&trapMode](Options *o, const std::string &argument) { + try { + trapMode = trapModeFromString(argument); + } catch (std::invalid_argument e) { + std::cerr << "Error: " << e.what() << "\n"; + exit(EXIT_FAILURE); + } }) .add("--emscripten-glue", "-e", "Generate emscripten glue", Options::Arguments::Zero, |