| Index: src/wasm/wasm-interpreter.cc
|
| diff --git a/src/wasm/wasm-interpreter.cc b/src/wasm/wasm-interpreter.cc
|
| index d7e58796b730656babd09d961d2f189270c2829b..ed4dd64a5e07f418e629c668d449302143fb96a6 100644
|
| --- a/src/wasm/wasm-interpreter.cc
|
| +++ b/src/wasm/wasm-interpreter.cc
|
| @@ -761,104 +761,101 @@ class ControlTransfers : public ZoneObject {
|
|
|
| std::vector<Control> control_stack;
|
| size_t value_depth = 0;
|
| - Decoder decoder(start, end); // for reading operands.
|
| - const byte* pc = start + locals_encoded_size;
|
| -
|
| - while (pc < end) {
|
| - WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
|
| - TRACE("@%td: control %s (depth = %zu)\n", (pc - start),
|
| + for (BytecodeIterator i(start + locals_encoded_size, end); i.has_next();
|
| + i.next()) {
|
| + WasmOpcode opcode = i.current();
|
| + TRACE("@%u: control %s (depth = %zu)\n", i.pc_offset(),
|
| WasmOpcodes::OpcodeName(opcode), value_depth);
|
| switch (opcode) {
|
| case kExprBlock: {
|
| - TRACE("control @%td $%zu: Block\n", (pc - start), value_depth);
|
| + TRACE("control @%u $%zu: Block\n", i.pc_offset(), value_depth);
|
| CLabel* label = new (zone) CLabel(zone, value_depth);
|
| - control_stack.push_back({pc, label, nullptr});
|
| + control_stack.push_back({i.pc(), label, nullptr});
|
| break;
|
| }
|
| case kExprLoop: {
|
| - TRACE("control @%td $%zu: Loop\n", (pc - start), value_depth);
|
| + TRACE("control @%u $%zu: Loop\n", i.pc_offset(), value_depth);
|
| CLabel* label1 = new (zone) CLabel(zone, value_depth);
|
| CLabel* label2 = new (zone) CLabel(zone, value_depth);
|
| - control_stack.push_back({pc, label1, nullptr});
|
| - control_stack.push_back({pc, label2, nullptr});
|
| - label2->Bind(&map_, start, pc, false);
|
| + control_stack.push_back({i.pc(), label1, nullptr});
|
| + control_stack.push_back({i.pc(), label2, nullptr});
|
| + label2->Bind(&map_, start, i.pc(), false);
|
| break;
|
| }
|
| case kExprIf: {
|
| - TRACE("control @%td $%zu: If\n", (pc - start), value_depth);
|
| + TRACE("control @%u $%zu: If\n", i.pc_offset(), value_depth);
|
| value_depth--;
|
| CLabel* end_label = new (zone) CLabel(zone, value_depth);
|
| CLabel* else_label = new (zone) CLabel(zone, value_depth);
|
| - control_stack.push_back({pc, end_label, else_label});
|
| - else_label->Ref(&map_, start, {pc, value_depth, false});
|
| + control_stack.push_back({i.pc(), end_label, else_label});
|
| + else_label->Ref(&map_, start, {i.pc(), value_depth, false});
|
| break;
|
| }
|
| case kExprElse: {
|
| Control* c = &control_stack.back();
|
| - TRACE("control @%td $%zu: Else\n", (pc - start), value_depth);
|
| - c->end_label->Ref(&map_, start, {pc, value_depth, false});
|
| + TRACE("control @%u $%zu: Else\n", i.pc_offset(), value_depth);
|
| + c->end_label->Ref(&map_, start, {i.pc(), value_depth, false});
|
| value_depth = c->end_label->value_depth;
|
| DCHECK_NOT_NULL(c->else_label);
|
| - c->else_label->Bind(&map_, start, pc + 1, false);
|
| + c->else_label->Bind(&map_, start, i.pc() + 1, false);
|
| c->else_label = nullptr;
|
| break;
|
| }
|
| case kExprEnd: {
|
| Control* c = &control_stack.back();
|
| - TRACE("control @%td $%zu: End\n", (pc - start), value_depth);
|
| + TRACE("control @%u $%zu: End\n", i.pc_offset(), value_depth);
|
| if (c->end_label->target) {
|
| // only loops have bound labels.
|
| DCHECK_EQ(kExprLoop, *c->pc);
|
| control_stack.pop_back();
|
| c = &control_stack.back();
|
| }
|
| - if (c->else_label) c->else_label->Bind(&map_, start, pc + 1, true);
|
| - c->end_label->Ref(&map_, start, {pc, value_depth, false});
|
| - c->end_label->Bind(&map_, start, pc + 1, true);
|
| + if (c->else_label)
|
| + c->else_label->Bind(&map_, start, i.pc() + 1, true);
|
| + c->end_label->Ref(&map_, start, {i.pc(), value_depth, false});
|
| + c->end_label->Bind(&map_, start, i.pc() + 1, true);
|
| value_depth = c->end_label->value_depth + 1;
|
| control_stack.pop_back();
|
| break;
|
| }
|
| case kExprBr: {
|
| - BreakDepthOperand operand(&decoder, pc);
|
| - TRACE("control @%td $%zu: Br[arity=%u, depth=%u]\n", (pc - start),
|
| + BreakDepthOperand operand(&i, i.pc());
|
| + TRACE("control @%u $%zu: Br[arity=%u, depth=%u]\n", i.pc_offset(),
|
| value_depth, operand.arity, operand.depth);
|
| value_depth -= operand.arity;
|
| control_stack[control_stack.size() - operand.depth - 1].Ref(
|
| - &map_, start, pc, value_depth, operand.arity > 0);
|
| + &map_, start, i.pc(), value_depth, operand.arity > 0);
|
| value_depth++;
|
| break;
|
| }
|
| case kExprBrIf: {
|
| - BreakDepthOperand operand(&decoder, pc);
|
| - TRACE("control @%td $%zu: BrIf[arity=%u, depth=%u]\n", (pc - start),
|
| + BreakDepthOperand operand(&i, i.pc());
|
| + TRACE("control @%u $%zu: BrIf[arity=%u, depth=%u]\n", i.pc_offset(),
|
| value_depth, operand.arity, operand.depth);
|
| value_depth -= (operand.arity + 1);
|
| control_stack[control_stack.size() - operand.depth - 1].Ref(
|
| - &map_, start, pc, value_depth, operand.arity > 0);
|
| + &map_, start, i.pc(), value_depth, operand.arity > 0);
|
| value_depth++;
|
| break;
|
| }
|
| case kExprBrTable: {
|
| - BranchTableOperand operand(&decoder, pc);
|
| - TRACE("control @%td $%zu: BrTable[arity=%u count=%u]\n", (pc - start),
|
| + BranchTableOperand operand(&i, i.pc());
|
| + TRACE("control @%u $%zu: BrTable[arity=%u count=%u]\n", i.pc_offset(),
|
| value_depth, operand.arity, operand.table_count);
|
| value_depth -= (operand.arity + 1);
|
| - for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
|
| - uint32_t target = operand.read_entry(&decoder, i);
|
| + for (uint32_t j = 0; j < operand.table_count + 1; ++j) {
|
| + uint32_t target = operand.read_entry(&i, j);
|
| control_stack[control_stack.size() - target - 1].Ref(
|
| - &map_, start, pc + i, value_depth, operand.arity > 0);
|
| + &map_, start, i.pc() + j, value_depth, operand.arity > 0);
|
| }
|
| value_depth++;
|
| break;
|
| }
|
| default: {
|
| - value_depth = value_depth - OpcodeArity(pc, end) + 1;
|
| + value_depth = value_depth - OpcodeArity(i.pc(), end) + 1;
|
| break;
|
| }
|
| }
|
| -
|
| - pc += OpcodeLength(pc, end);
|
| }
|
| }
|
|
|
|
|