Commit a9882da6 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Clean up interface for exception handling

Avoid splitting functionality in two interface calls and passing around
a void* between them.

R=kschimpf@chromium.org

Change-Id: I0e12ff0295852ce5c36f7c3fb3b2c51dc0f2677e
Reviewed-on: https://chromium-review.googlesource.com/702484Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48335}
parent ea891e87
......@@ -573,8 +573,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> {
F(Throw, const ExceptionIndexOperand<validate>&, Control* block, \
const Vector<Value>& args) \
F(CatchException, const ExceptionIndexOperand<validate>& operand, \
Control* block, void** caught_values) \
F(SetCaughtValue, void* caught_values, Value* value, size_t index) \
Control* block, Vector<Value> caught_values) \
F(AtomicOp, WasmOpcode opcode, Vector<Value> args, \
const MemoryAccessOperand<validate>& operand, Value* result)
......@@ -1323,13 +1322,13 @@ class WasmFullDecoder : public WasmDecoder<validate> {
c->kind = kControlTryCatch;
FallThruTo(c);
stack_.resize(c->stack_depth);
void* caught_values = nullptr;
interface_.CatchException(this, operand, c, &caught_values);
const WasmExceptionSig* sig = operand.exception->sig;
for (size_t i = 0, e = sig->parameter_count(); i < e; ++i) {
auto* value = Push(sig->GetParam(i));
interface_.SetCaughtValue(this, caught_values, value, i);
Push(sig->GetParam(i));
}
Vector<Value> values(stack_.data() + c->stack_depth,
sig->parameter_count());
interface_.CatchException(this, operand, c, values);
break;
}
case kExprCatchAll: {
......
......@@ -422,13 +422,12 @@ class WasmGraphBuildingInterface {
void CatchException(Decoder* decoder,
const ExceptionIndexOperand<true>& operand,
Control* block, void** caught_values_ptr) {
Control* block, Vector<Value> values) {
DCHECK(block->is_try_catch());
current_catch_ = block->previous_catch;
SsaEnv* catch_env = block->try_info->catch_env;
SetEnv(catch_env);
TFNode*** caught_values = reinterpret_cast<TFNode***>(caught_values_ptr);
TFNode* compare_i32 = nullptr;
if (block->try_info->exception == nullptr) {
// Catch not applicable, no possible throws in the try
......@@ -466,23 +465,19 @@ class WasmGraphBuildingInterface {
SetEnv(if_catch_env);
if (block->try_info->exception == nullptr) {
*caught_values = nullptr;
// No caught value, make up filler nodes so that catch block still
// compiles.
for (Value& value : values) {
value.node = DefaultValue(value.type);
}
} else {
// TODO(kschimpf): Can't use BUILD() here, GetExceptionValues() returns
// TFNode** rather than TFNode*. Fix to add landing pads.
*caught_values = builder_->GetExceptionValues(operand.exception);
}
}
void SetCaughtValue(Decoder* decoder, void* caught_values_ptr, Value* value,
size_t index) {
if (caught_values_ptr) {
TFNode** caught_values = reinterpret_cast<TFNode**>(caught_values_ptr);
value->node = caught_values[index];
return;
TFNode** caught_values = builder_->GetExceptionValues(operand.exception);
for (size_t i = 0, e = values.size(); i < e; ++i) {
values[i].node = caught_values[i];
}
}
// No caught value, make up filler node so that catch block still compiles.
value->node = DefaultValue(value->type);
}
void AtomicOp(Decoder* decoder, WasmOpcode opcode, Vector<Value> args,
......
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