[wasm] Macro-ify checking of prototype flags.
R=ahaas@chromium.org BUG= Review-Url: https://codereview.chromium.org/2253543003 Cr-Commit-Position: refs/heads/master@{#38658}
This commit is contained in:
parent
d941b52d73
commit
b73376b908
@ -31,6 +31,12 @@ namespace wasm {
|
||||
#define TRACE(...)
|
||||
#endif
|
||||
|
||||
#define CHECK_PROTOTYPE_OPCODE(flag) \
|
||||
if (!FLAG_##flag) { \
|
||||
error("Invalid opcode (enable with --" #flag ")"); \
|
||||
break; \
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -671,23 +677,14 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kExprThrow: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(jpp): validate the poped value.
|
||||
Pop();
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
Pop(0, kAstI32);
|
||||
|
||||
// TODO(jpp): start exception propagation.
|
||||
break;
|
||||
}
|
||||
case kExprTryCatch: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
SsaEnv* outer_env = ssa_env_;
|
||||
SsaEnv* try_env = Steal(outer_env);
|
||||
SsaEnv* catch_env = Split(try_env);
|
||||
@ -696,11 +693,7 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kExprTryCatchFinally: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
SsaEnv* outer_env = ssa_env_;
|
||||
SsaEnv* try_env = Steal(outer_env);
|
||||
SsaEnv* catch_env = Split(try_env);
|
||||
@ -710,11 +703,7 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kExprTryFinally: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
SsaEnv* outer_env = ssa_env_;
|
||||
SsaEnv* try_env = Steal(outer_env);
|
||||
SsaEnv* finally_env = Split(outer_env);
|
||||
@ -723,11 +712,7 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kExprCatch: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
LocalIndexOperand operand(this, pc_);
|
||||
len = 1 + operand.length;
|
||||
|
||||
@ -766,11 +751,7 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kExprFinally: {
|
||||
if (!FLAG_wasm_eh_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_eh_prototype);
|
||||
if (control_.empty()) {
|
||||
error(pc_, "finally does not match a any try");
|
||||
break;
|
||||
@ -885,8 +866,6 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
name = "if_else:merge";
|
||||
}
|
||||
} else if (c->is_try()) {
|
||||
DCHECK(FLAG_wasm_eh_prototype);
|
||||
|
||||
name = "try:end";
|
||||
|
||||
// try blocks do not yield a value.
|
||||
@ -1201,10 +1180,7 @@ class WasmFullDecoder : public WasmDecoder {
|
||||
break;
|
||||
}
|
||||
case kSimdPrefix: {
|
||||
if (!FLAG_wasm_simd_prototype) {
|
||||
error("Invalid opcode");
|
||||
return;
|
||||
}
|
||||
CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype);
|
||||
len++;
|
||||
byte simd_index = *(pc_ + 1);
|
||||
opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index);
|
||||
|
@ -1833,13 +1833,12 @@ TEST_F(AstDecoderTest, Throw) {
|
||||
FLAG_wasm_eh_prototype = true;
|
||||
EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprThrow);
|
||||
|
||||
// TODO(jpp): can't throw d, f, or l.
|
||||
EXPECT_VERIFIES_INLINE(sigs.i_d(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I32V(0));
|
||||
EXPECT_VERIFIES_INLINE(sigs.i_f(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I32V(0));
|
||||
EXPECT_VERIFIES_INLINE(sigs.l_l(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I64V(0));
|
||||
EXPECT_FAILURE_INLINE(sigs.i_d(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I32V(0));
|
||||
EXPECT_FAILURE_INLINE(sigs.i_f(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I32V(0));
|
||||
EXPECT_FAILURE_INLINE(sigs.l_l(), WASM_GET_LOCAL(0), kExprThrow,
|
||||
WASM_I64V(0));
|
||||
}
|
||||
|
||||
#define WASM_CATCH(local) kExprCatch, static_cast<byte>(local)
|
||||
|
Loading…
Reference in New Issue
Block a user