Index: src/wasm/ast-decoder.cc |
diff --git a/src/wasm/ast-decoder.cc b/src/wasm/ast-decoder.cc |
index d63037aef7676b38f709201cb152c3428c06e7ae..a33ef1c047d15f08293e410adb362141f9ef6cc5 100644 |
--- a/src/wasm/ast-decoder.cc |
+++ b/src/wasm/ast-decoder.cc |
@@ -718,6 +718,7 @@ class SR_WasmDecoder : public WasmDecoder { |
break; |
} |
case kExprUnreachable: { |
+ // TODO(clemensh): add source position for unreachable |
BUILD0(Unreachable); |
ssa_env_->Kill(SsaEnv::kControlEnd); |
Leaf(kAstEnd, nullptr); |
@@ -954,6 +955,7 @@ class SR_WasmDecoder : public WasmDecoder { |
} else { |
UNREACHABLE(); |
} |
+ if (IsSimpleOpTrapping(p->opcode())) AddSourcePosition(p); |
} |
return; |
} |
@@ -1235,6 +1237,7 @@ class SR_WasmDecoder : public WasmDecoder { |
buffer[i] = p->tree->children[i - 1]->node; |
} |
p->tree->node = builder_->CallDirect(operand.index, buffer); |
+ AddSourcePosition(p); |
} |
break; |
} |
@@ -1253,6 +1256,7 @@ class SR_WasmDecoder : public WasmDecoder { |
buffer[i] = p->tree->children[i]->node; |
} |
p->tree->node = builder_->CallIndirect(operand.index, buffer); |
+ AddSourcePosition(p); |
} |
break; |
} |
@@ -1270,6 +1274,7 @@ class SR_WasmDecoder : public WasmDecoder { |
buffer[i] = p->tree->children[i - 1]->node; |
} |
p->tree->node = builder_->CallImport(operand.index, buffer); |
+ AddSourcePosition(p); |
} |
break; |
} |
@@ -1325,6 +1330,7 @@ class SR_WasmDecoder : public WasmDecoder { |
MemoryAccessOperand operand(this, p->pc()); |
p->tree->node = |
builder_->LoadMem(type, mem_type, p->last()->node, operand.offset); |
+ AddSourcePosition(p); |
} |
} |
@@ -1340,6 +1346,7 @@ class SR_WasmDecoder : public WasmDecoder { |
builder_->StoreMem(mem_type, p->tree->children[0]->node, operand.offset, |
val); |
p->tree->node = val; |
+ AddSourcePosition(p); |
} |
} |
} |
@@ -1631,6 +1638,28 @@ class SR_WasmDecoder : public WasmDecoder { |
} |
return assigned; |
} |
+ |
+ void AddSourcePosition(Production* p) { |
+ DCHECK_NOT_NULL(p->tree->node); |
+ AddSourcePosition(p->tree->node, p->pc()); |
+ } |
+ |
+ void AddSourcePosition(TFNode* node, const byte* pc) { |
+ int offset = static_cast<int>(pc - start_); |
+ DCHECK_EQ(pc - start_, offset); // overflows cannot happen |
+ builder_->SetSourcePosition(node, offset); |
+ } |
+ |
+ bool IsSimpleOpTrapping(WasmOpcode opcode) { |
+ switch (opcode) { |
+#define V(name) case WasmOpcode::kExpr##name: |
+ FOREACH_SIMPLE_TRAPPING_OPCODE(V) |
+#undef V |
+ return true; |
+ default: |
+ return false; |
+ } |
+ } |
}; |
bool DecodeLocalDecls(AstLocalDecls& decls, const byte* start, |