Commit 0a5cbce4 authored by Karl Schimpf's avatar Karl Schimpf Committed by Commit Bot

Complete set of exception handling opcodes in decoder.

Adds missing opcodes for exception handling for the function body decoder.
Also adds error messages if the exception handling construct is not yet
functional.

Note that the previous prototype for catch and throw have been marked
as not yet functional. This was done because it doesn't model
exceptions the way the proposal suggests. Rather, they implement a
hard-coded (c++ model) of exceptions.

Bug: v8:6577
Change-Id: Ife170b9f0cb2be91b11082e43c4795ce81a427dc
Reviewed-on: https://chromium-review.googlesource.com/564138Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Karl Schimpf <kschimpf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46540}
parent 9c431505
......@@ -44,6 +44,10 @@ namespace wasm {
break; \
}
#define PROTOTYPE_NOT_FUNCTIONAL(opcode) \
errorf(pc_, "Prototype still not functional: %s", \
WasmOpcodes::OpcodeName(opcode));
// An SsaEnv environment carries the current local variable renaming
// as well as the current effect and control dependency in the TF graph.
// It maintains a control state that tracks whether the environment
......@@ -801,8 +805,16 @@ class WasmFullDecoder : public WasmDecoder {
len = 1 + operand.length;
break;
}
case kExprRethrow: {
// TODO(kschimpf): Implement.
CHECK_PROTOTYPE_OPCODE(eh);
PROTOTYPE_NOT_FUNCTIONAL(opcode);
break;
}
case kExprThrow: {
// TODO(kschimpf): Fix to use type signature of exception.
CHECK_PROTOTYPE_OPCODE(eh);
PROTOTYPE_NOT_FUNCTIONAL(opcode);
Value value = Pop(0, kWasmI32);
BUILD(Throw, value.node);
// TODO(titzer): Throw should end control, but currently we build a
......@@ -824,7 +836,9 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
case kExprCatch: {
// TODO(kschimpf): Fix to use type signature of exception.
CHECK_PROTOTYPE_OPCODE(eh);
PROTOTYPE_NOT_FUNCTIONAL(opcode);
LocalIndexOperand<true> operand(this, pc_);
len = 1 + operand.length;
......@@ -863,6 +877,12 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
case kExprCatchAll: {
// TODO(kschimpf): Implement.
CHECK_PROTOTYPE_OPCODE(eh);
PROTOTYPE_NOT_FUNCTIONAL(opcode);
break;
}
case kExprLoop: {
BlockTypeOperand<true> operand(this, pc_);
SsaEnv* finish_try_env = Steal(ssa_env_);
......
......@@ -146,7 +146,9 @@ const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
// Non-standard opcodes.
CASE_OP(Try, "try")
CASE_OP(Throw, "throw")
CASE_OP(Rethrow, "rethrow")
CASE_OP(Catch, "catch")
CASE_OP(CatchAll, "catch_all")
// asm.js-only opcodes.
CASE_F64_OP(Acos, "acos")
......
......@@ -48,20 +48,22 @@ using WasmCodePosition = int;
constexpr WasmCodePosition kNoCodePosition = -1;
// Control expressions and blocks.
#define FOREACH_CONTROL_OPCODE(V) \
V(Unreachable, 0x00, _) \
V(Nop, 0x01, _) \
V(Block, 0x02, _) \
V(Loop, 0x03, _) \
V(If, 0x004, _) \
V(Else, 0x05, _) \
V(Try, 0x06, _ /* eh_prototype */) \
V(Catch, 0x07, _ /* eh_prototype */) \
V(Throw, 0x08, _ /* eh_prototype */) \
V(End, 0x0b, _) \
V(Br, 0x0c, _) \
V(BrIf, 0x0d, _) \
V(BrTable, 0x0e, _) \
#define FOREACH_CONTROL_OPCODE(V) \
V(Unreachable, 0x00, _) \
V(Nop, 0x01, _) \
V(Block, 0x02, _) \
V(Loop, 0x03, _) \
V(If, 0x004, _) \
V(Else, 0x05, _) \
V(Try, 0x06, _ /* eh_prototype */) \
V(Catch, 0x07, _ /* eh_prototype */) \
V(Throw, 0x08, _ /* eh_prototype */) \
V(Rethrow, 0x09, _ /* eh_prototype */) \
V(CatchAll, 0x0a, _ /* eh prototype */) \
V(End, 0x0b, _) \
V(Br, 0x0c, _) \
V(BrIf, 0x0d, _) \
V(BrTable, 0x0e, _) \
V(Return, 0x0f, _)
// Constants, locals, globals, and calls.
......
......@@ -178,6 +178,9 @@
# BUG(v8:6306).
'wasm/huge-memory': [SKIP],
# BUG(v8:6577).
'wasm/exceptions': [SKIP],
}], # ALWAYS
['novfp3 == True', {
......
......@@ -2238,7 +2238,8 @@ TEST_F(FunctionBodyDecoderTest, Select_TypeCheck) {
TEST_F(FunctionBodyDecoderTest, Throw) {
EXPERIMENTAL_FLAG_SCOPE(eh);
EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow);
// TODO(kschimpf): Need to fix throw to use declared exception.
EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprThrow);
EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0));
EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0));
......@@ -2257,7 +2258,8 @@ TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) {
TEST_F(FunctionBodyDecoderTest, TryCatch) {
EXPERIMENTAL_FLAG_SCOPE(eh);
EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd);
// TODO(kschimpf): Need to fix catch to use declared exception.
EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd);
// Missing catch.
EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd);
......
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