Commit dc226e61 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Factor trap codes out of wasm-compiler.cc

R=ahaas@chromium.org,bradnelson@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1862633002

Cr-Commit-Position: refs/heads/master@{#35274}
parent 77a8c2ea
This diff is collapsed.
...@@ -329,6 +329,19 @@ enum WasmOpcode { ...@@ -329,6 +329,19 @@ enum WasmOpcode {
#undef DECLARE_NAMED_ENUM #undef DECLARE_NAMED_ENUM
}; };
// The reason for a trap.
enum TrapReason {
kTrapUnreachable,
kTrapMemOutOfBounds,
kTrapDivByZero,
kTrapDivUnrepresentable,
kTrapRemByZero,
kTrapFloatUnrepresentable,
kTrapFuncInvalid,
kTrapFuncSigMismatch,
kTrapCount
};
// A collection of opcode-related static methods. // A collection of opcode-related static methods.
class WasmOpcodes { class WasmOpcodes {
public: public:
...@@ -495,6 +508,29 @@ class WasmOpcodes { ...@@ -495,6 +508,29 @@ class WasmOpcodes {
return "<unknown>"; return "<unknown>";
} }
} }
static const char* TrapReasonName(TrapReason reason) {
switch (reason) {
case kTrapUnreachable:
return "unreachable";
case kTrapMemOutOfBounds:
return "memory access out of bounds";
case kTrapDivByZero:
return "divide by zero";
case kTrapDivUnrepresentable:
return "divide result unrepresentable";
case kTrapRemByZero:
return "remainder by zero";
case kTrapFloatUnrepresentable:
return "integer result unrepresentable";
case kTrapFuncInvalid:
return "invalid function";
case kTrapFuncSigMismatch:
return "function signature mismatch";
default:
return "<?>";
}
}
}; };
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment