Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

Commit

Permalink
[wasm] Fix wasm decoder tracing for prefix opcodes.
Browse files Browse the repository at this point in the history
Using --trace-wasm-decoder prints unknowns for prefix opcodes, example:

  @3      #1:Block               |  env = 0x5547c10, state = R, reason = block:start, control = #0:Start

  @4      v8#14:GetLocal            | i@4:GetLocal[0]
  @6      #e5:Unknown             | s@6:Unknown
  @8      v8#15:SetLocal            | s@8:SetLocal[1]
  @10     v8#14:GetLocal            | s@8:SetLocal[1] i@10:GetLocal[0]
  @12     v8#14:GetLocal            | s@8:SetLocal[1] i@10:GetLocal[0] s@12:GetLocal[1]
  @14     #cb:I8Const             | s@8:SetLocal[1] i@10:GetLocal[0] s@12:GetLocal[1] i@14:I8Const
  @16     #e5:Unknown             | s@8:SetLocal[1] i@10:GetLocal[0] i@16:Unknown

Fixed to print:

  @3        #1:Block               |  env = 0x45cac10, state = R, reason = block:start, control = #0:Start

  @4        v8#14:GetLocal            | i@4:GetLocal[0]
  @6    #e5 #1b:I32x4Splat          | s@6:I32x4Splat
  @8        v8#15:SetLocal            | s@8:SetLocal[1]
  @10       v8#14:GetLocal            | s@8:SetLocal[1] i@10:GetLocal[0]
  @12       v8#14:GetLocal            | s@8:SetLocal[1] i@10:GetLocal[0] s@12:GetLocal[1]
  @14       #cb:I8Const             | s@8:SetLocal[1] i@10:GetLocal[0] s@12:GetLocal[1] i@14:I8Const
  @16   #e5 #1c:I32x4ExtractLane    | s@8:SetLocal[1] i@10:GetLocal[0] i@16:I32x4ExtractLane

[email protected], [email protected]

Review-Url: https://codereview.chromium.org/2307733002
Cr-Commit-Position: refs/heads/master@{#39142}
  • Loading branch information
dtig authored and Commit bot committed Sep 2, 2016
1 parent 6dd2bc2 commit eed164b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/wasm/ast-decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class WasmFullDecoder : public WasmDecoder {
}

if (ssa_env_->go()) {
TRACE(" @%-6d #xx:%-20s|", startrel(pc_), "ImplicitReturn");
TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "ImplicitReturn");
DoReturn();
if (failed()) return TraceFailed();
TRACE("\n");
Expand Down Expand Up @@ -707,8 +707,10 @@ class WasmFullDecoder : public WasmDecoder {
while (true) { // decoding loop.
unsigned len = 1;
WasmOpcode opcode = static_cast<WasmOpcode>(*pc_);
TRACE(" @%-6d #%02x:%-20s|", startrel(pc_), opcode,
WasmOpcodes::ShortOpcodeName(opcode));
if (!WasmOpcodes::IsPrefixOpcode(opcode)) {
TRACE(" @%-8d #%02x:%-20s|", startrel(pc_), opcode,
WasmOpcodes::ShortOpcodeName(opcode));
}

FunctionSig* sig = WasmOpcodes::Signature(opcode);
if (sig) {
Expand Down Expand Up @@ -1271,6 +1273,8 @@ class WasmFullDecoder : public WasmDecoder {
len++;
byte simd_index = *(pc_ + 1);
opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index);
TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix,
simd_index, WasmOpcodes::ShortOpcodeName(opcode));
DecodeSimdOpcode(opcode);
break;
}
Expand All @@ -1285,6 +1289,9 @@ class WasmFullDecoder : public WasmDecoder {
for (size_t i = 0; i < stack_.size(); ++i) {
Value& val = stack_[i];
WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc);
if (WasmOpcodes::IsPrefixOpcode(opcode)) {
opcode = static_cast<WasmOpcode>(opcode << 8 | *(val.pc + 1));
}
PrintF(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type),
static_cast<int>(val.pc - start_),
WasmOpcodes::ShortOpcodeName(opcode));
Expand Down
12 changes: 12 additions & 0 deletions src/wasm/wasm-opcodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ const char* WasmOpcodes::ShortOpcodeName(WasmOpcode opcode) {
return "Unknown";
}

bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) {
switch (opcode) {
#define CHECK_PREFIX(name, opcode) \
case k##name##Prefix: \
return true;
FOREACH_PREFIX(CHECK_PREFIX)
#undef CHECK_PREFIX
default:
return false;
}
}

std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
if (sig.return_count() == 0) os << "v";
for (size_t i = 0; i < sig.return_count(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions src/wasm/wasm-opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class WasmOpcodes {
static const char* OpcodeName(WasmOpcode opcode);
static const char* ShortOpcodeName(WasmOpcode opcode);
static FunctionSig* Signature(WasmOpcode opcode);
static bool IsPrefixOpcode(WasmOpcode opcode);

static int TrapReasonToMessageId(TrapReason reason);
static const char* TrapReasonMessage(TrapReason reason);
Expand Down

0 comments on commit eed164b

Please sign in to comment.