Commit ce669d79 authored by clemensh's avatar clemensh Committed by Commit bot

Move TrapReason messages over to messages.h

This prepares a patch to throw actual errors instead of just strings on
wasm traps. In order to accomplish this, the messages need to be known
to the runtime, as the generated code will just pass the message id.

R=mstarzinger@chromium.org, titzer@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#35628}
parent de5aaad6
......@@ -198,7 +198,7 @@ class WasmTrapHelper : public ZoneObject {
void BuildTrapCode(wasm::TrapReason reason) {
Node* exception =
builder_->String(wasm::WasmOpcodes::TrapReasonName(reason));
builder_->String(wasm::WasmOpcodes::TrapReasonMessage(reason));
Node* end;
Node** control_ptr = builder_->control_;
Node** effect_ptr = builder_->effect_;
......
......@@ -471,7 +471,16 @@ class CallSite {
/* EvalError */ \
T(CodeGenFromStrings, "%") \
/* URIError */ \
T(URIMalformed, "URI malformed")
T(URIMalformed, "URI malformed") \
/* Wasm errors (currently Error) */ \
T(WasmTrapUnreachable, "unreachable") \
T(WasmTrapMemOutOfBounds, "memory access out of bounds") \
T(WasmTrapDivByZero, "divide by zero") \
T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \
T(WasmTrapRemByZero, "remainder by zero") \
T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \
T(WasmTrapFuncInvalid, "invalid function") \
T(WasmTrapFuncSigMismatch, "function signature mismatch")
class MessageTemplate {
public:
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "src/wasm/wasm-opcodes.h"
#include "src/messages.h"
#include "src/signature.h"
namespace v8 {
......@@ -145,6 +146,22 @@ bool WasmOpcodes::IsSupported(WasmOpcode opcode) {
return true;
#endif
}
int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
switch (reason) {
#define TRAPREASON_TO_MESSAGE(name) \
case k##name: \
return MessageTemplate::kWasm##name;
FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
#undef TRAPREASON_TO_MESSAGE
default:
return MessageTemplate::kNone;
}
}
const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -330,16 +330,21 @@ enum WasmOpcode {
};
// The reason for a trap.
#define FOREACH_WASM_TRAPREASON(V) \
V(TrapUnreachable) \
V(TrapMemOutOfBounds) \
V(TrapDivByZero) \
V(TrapDivUnrepresentable) \
V(TrapRemByZero) \
V(TrapFloatUnrepresentable) \
V(TrapFuncInvalid) \
V(TrapFuncSigMismatch)
enum TrapReason {
kTrapUnreachable,
kTrapMemOutOfBounds,
kTrapDivByZero,
kTrapDivUnrepresentable,
kTrapRemByZero,
kTrapFloatUnrepresentable,
kTrapFuncInvalid,
kTrapFuncSigMismatch,
#define DECLARE_ENUM(name) k##name,
FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
kTrapCount
#undef DECLARE_ENUM
};
// A collection of opcode-related static methods.
......@@ -349,6 +354,9 @@ class WasmOpcodes {
static const char* OpcodeName(WasmOpcode opcode);
static FunctionSig* Signature(WasmOpcode opcode);
static int TrapReasonToMessageId(TrapReason reason);
static const char* TrapReasonMessage(TrapReason reason);
static byte MemSize(MachineType type) {
return 1 << ElementSizeLog2Of(type.representation());
}
......@@ -508,29 +516,6 @@ class WasmOpcodes {
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 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