[wasm] Implement {StackEffect} for exception opcodes.

This adds missing cases for exception handling opcodes to the stack
effect helper {WasmDecoder::StackEffect}. It is a first step towards
adding exception handling support to the {WasmInterpreter}.

R=clemensh@chromium.org
BUG=v8:8091

Change-Id: Idacf440a894e5c71a180502c1d2f10fa15c8f5fa
Reviewed-on: https://chromium-review.googlesource.com/c/1425911
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58995}
This commit is contained in:
Michael Starzinger 2019-01-22 15:28:42 +01:00 committed by Commit Bot
parent 71cb4777e7
commit 7d4ece425f

View File

@ -847,16 +847,23 @@ class WasmDecoder : public Decoder {
return true;
}
inline bool Validate(const byte* pc, ExceptionIndexImmediate<validate>& imm) {
inline bool Complete(const byte* pc, ExceptionIndexImmediate<validate>& imm) {
if (!VALIDATE(module_ != nullptr &&
imm.index < module_->exceptions.size())) {
errorf(pc + 1, "Invalid exception index: %u", imm.index);
return false;
}
imm.exception = &module_->exceptions[imm.index];
return true;
}
inline bool Validate(const byte* pc, ExceptionIndexImmediate<validate>& imm) {
if (!Complete(pc, imm)) {
errorf(pc + 1, "Invalid exception index: %u", imm.index);
return false;
}
return true;
}
inline bool Validate(const byte* pc, GlobalIndexImmediate<validate>& imm) {
if (!VALIDATE(module_ != nullptr && imm.index < module_->globals.size())) {
errorf(pc + 1, "invalid global index: %u", imm.index);
@ -1277,7 +1284,9 @@ class WasmDecoder : public Decoder {
case kExprBrIf:
case kExprBrTable:
case kExprIf:
case kExprRethrow:
return {1, 0};
case kExprCatch:
case kExprGetLocal:
case kExprGetGlobal:
case kExprI32Const:
@ -1299,11 +1308,19 @@ class WasmDecoder : public Decoder {
return {imm.sig->parameter_count() + 1,
imm.sig->return_count()};
}
case kExprThrow: {
ExceptionIndexImmediate<validate> imm(this, pc);
CHECK(Complete(pc, imm));
DCHECK_EQ(0, imm.exception->sig->return_count());
return {imm.exception->sig->parameter_count(), 0};
}
case kExprBr:
case kExprBlock:
case kExprLoop:
case kExprEnd:
case kExprElse:
case kExprTry:
case kExprBrOnExn:
case kExprNop:
case kExprReturn:
case kExprUnreachable: