summaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/trapping.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ast/trapping.h b/src/ast/trapping.h
index 80cc14da9..184e6059b 100644
--- a/src/ast/trapping.h
+++ b/src/ast/trapping.h
@@ -17,6 +17,8 @@
#ifndef wasm_ast_trapping_h
#define wasm_ast_trapping_h
+#include <exception>
+
#include "pass.h"
namespace wasm {
@@ -95,6 +97,20 @@ private:
Expression* makeTrappingBinary(Binary* curr, TrappingFunctionContainer &trappingFunctions);
Expression* makeTrappingUnary(Unary* curr, TrappingFunctionContainer &trappingFunctions);
+inline TrapMode trapModeFromString(std::string const& str) {
+ if (str == "allow") {
+ return TrapMode::Allow;
+ } else if (str == "clamp") {
+ return TrapMode::Clamp;
+ } else if (str == "js") {
+ return TrapMode::JS;
+ } else {
+ throw std::invalid_argument(
+ "Unsupported trap mode \"" + str + "\". "
+ "Valid modes are \"allow\", \"js\", and \"clamp\"");
+ }
+}
+
} // wasm
#endif // wasm_ast_trapping_h