diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index 28bc5dbbde..39669cd98b 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -2014,7 +2014,16 @@ class WasmFullDecoder : public WasmDecoder { #ifdef DEBUG class TraceLine { public: - explicit TraceLine(WasmFullDecoder* decoder) : decoder_(decoder) {} + explicit TraceLine(WasmFullDecoder* decoder) : decoder_(decoder) { + WasmOpcode opcode = static_cast(*decoder->pc()); + if (!WasmOpcodes::IsPrefixOpcode(opcode)) AppendOpcode(opcode); + } + + void AppendOpcode(WasmOpcode opcode) { + DCHECK(!WasmOpcodes::IsPrefixOpcode(opcode)); + Append(TRACE_INST_FORMAT, decoder_->startrel(decoder_->pc_), + WasmOpcodes::OpcodeName(opcode)); + } ~TraceLine() { if (!FLAG_trace_wasm_decoder) return; @@ -2114,6 +2123,8 @@ class WasmFullDecoder : public WasmDecoder { public: explicit TraceLine(WasmFullDecoder*) {} + void AppendOpcode(WasmOpcode) {} + PRINTF_FORMAT(2, 3) void Append(const char* format, ...) {} }; @@ -2129,10 +2140,6 @@ class WasmFullDecoder : public WasmDecoder { template int DecodeOp() { TraceLine trace_msg(this); - if (!WasmOpcodes::IsPrefixOpcode(opcode)) { - trace_msg.Append(TRACE_INST_FORMAT, startrel(this->pc_), - WasmOpcodes::OpcodeName(opcode)); - } // TODO(clemensb): Break this up into individual functions. switch (opcode) { @@ -2787,8 +2794,7 @@ class WasmFullDecoder : public WasmDecoder { } else if (full_opcode >= kExprMemoryInit) { CHECK_PROTOTYPE_OPCODE(bulk_memory); } - trace_msg.Append(TRACE_INST_FORMAT, startrel(this->pc_), - WasmOpcodes::OpcodeName(full_opcode)); + trace_msg.AppendOpcode(full_opcode); return DecodeNumericOpcode(full_opcode); } case kSimdPrefix: { @@ -2797,8 +2803,7 @@ class WasmFullDecoder : public WasmDecoder { WasmOpcode full_opcode = this->template read_prefixed_opcode( this->pc_, &opcode_length); if (!VALIDATE(this->ok())) return 0; - trace_msg.Append(TRACE_INST_FORMAT, startrel(this->pc_), - WasmOpcodes::OpcodeName(full_opcode)); + trace_msg.AppendOpcode(full_opcode); return DecodeSimdOpcode(full_opcode, 1 + opcode_length); } case kAtomicPrefix: { @@ -2807,8 +2812,7 @@ class WasmFullDecoder : public WasmDecoder { this->template read_u8(this->pc_ + 1, "atomic index"); WasmOpcode full_opcode = static_cast(opcode << 8 | atomic_index); - trace_msg.Append(TRACE_INST_FORMAT, startrel(this->pc_), - WasmOpcodes::OpcodeName(full_opcode)); + trace_msg.AppendOpcode(full_opcode); return DecodeAtomicOpcode(full_opcode); } case kGCPrefix: { @@ -2817,8 +2821,7 @@ class WasmFullDecoder : public WasmDecoder { this->template read_u8(this->pc_ + 1, "gc index"); WasmOpcode full_opcode = static_cast(opcode << 8 | gc_index); - trace_msg.Append(TRACE_INST_FORMAT, startrel(this->pc_), - WasmOpcodes::OpcodeName(full_opcode)); + trace_msg.AppendOpcode(full_opcode); return DecodeGCOpcode(full_opcode); } // Note that prototype opcodes are not handled in the fastpath