Skip to content

Commit

Permalink
Track locations of Vars in BinaryReaderIR and BinaryReaderInterp (#1963)
Browse files Browse the repository at this point in the history
- Rebase test output to match new location tracking on Vars
- Eliminate single-argument Var() constructor.
  • Loading branch information
keithw authored Aug 15, 2022
1 parent 7f51b5a commit 3bf73a8
Show file tree
Hide file tree
Showing 41 changed files with 282 additions and 242 deletions.
65 changes: 34 additions & 31 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void BinaryReaderIR::SetBlockDeclaration(BlockDeclaration* decl,
Type sig_type) {
if (sig_type.IsIndex()) {
Index type_index = sig_type.GetIndex();
SetFuncDeclaration(decl, Var(type_index));
SetFuncDeclaration(decl, Var(type_index, GetLocation()));
} else {
decl->has_func_type = false;
decl->sig.param_types.clear();
Expand Down Expand Up @@ -796,33 +796,33 @@ Result BinaryReaderIR::OnBlockExpr(Type sig_type) {
}

Result BinaryReaderIR::OnBrExpr(Index depth) {
return AppendExpr(MakeUnique<BrExpr>(Var(depth)));
return AppendExpr(MakeUnique<BrExpr>(Var(depth, GetLocation())));
}

Result BinaryReaderIR::OnBrIfExpr(Index depth) {
return AppendExpr(MakeUnique<BrIfExpr>(Var(depth)));
return AppendExpr(MakeUnique<BrIfExpr>(Var(depth, GetLocation())));
}

Result BinaryReaderIR::OnBrTableExpr(Index num_targets,
Index* target_depths,
Index default_target_depth) {
auto expr = MakeUnique<BrTableExpr>();
expr->default_target = Var(default_target_depth);
expr->default_target = Var(default_target_depth, GetLocation());
expr->targets.resize(num_targets);
for (Index i = 0; i < num_targets; ++i) {
expr->targets[i] = Var(target_depths[i]);
expr->targets[i] = Var(target_depths[i], GetLocation());
}
return AppendExpr(std::move(expr));
}

Result BinaryReaderIR::OnCallExpr(Index func_index) {
return AppendExpr(MakeUnique<CallExpr>(Var(func_index)));
return AppendExpr(MakeUnique<CallExpr>(Var(func_index, GetLocation())));
}

Result BinaryReaderIR::OnCallIndirectExpr(Index sig_index, Index table_index) {
auto expr = MakeUnique<CallIndirectExpr>();
SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
expr->table = Var(table_index);
expr->table = Var(table_index, GetLocation());
return AppendExpr(std::move(expr));
}

Expand All @@ -831,14 +831,14 @@ Result BinaryReaderIR::OnCallRefExpr() {
}

Result BinaryReaderIR::OnReturnCallExpr(Index func_index) {
return AppendExpr(MakeUnique<ReturnCallExpr>(Var(func_index)));
return AppendExpr(MakeUnique<ReturnCallExpr>(Var(func_index, GetLocation())));
}

Result BinaryReaderIR::OnReturnCallIndirectExpr(Index sig_index,
Index table_index) {
auto expr = MakeUnique<ReturnCallIndirectExpr>();
SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
expr->table = Var(table_index);
expr->table = Var(table_index, GetLocation());
return AppendExpr(std::move(expr));
}

Expand Down Expand Up @@ -949,8 +949,8 @@ Result BinaryReaderIR::OnLoadExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<LoadExpr>(opcode, Var(memidx), 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<LoadExpr>(opcode, Var(memidx, GetLocation()),
1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnLoopExpr(Type sig_type) {
Expand All @@ -963,64 +963,67 @@ Result BinaryReaderIR::OnLoopExpr(Type sig_type) {
}

Result BinaryReaderIR::OnMemoryCopyExpr(Index srcmemidx, Index destmemidx) {
return AppendExpr(
MakeUnique<MemoryCopyExpr>(Var(srcmemidx), Var(destmemidx)));
return AppendExpr(MakeUnique<MemoryCopyExpr>(Var(srcmemidx, GetLocation()),
Var(destmemidx, GetLocation())));
}

Result BinaryReaderIR::OnDataDropExpr(Index segment) {
return AppendExpr(MakeUnique<DataDropExpr>(Var(segment)));
return AppendExpr(MakeUnique<DataDropExpr>(Var(segment, GetLocation())));
}

Result BinaryReaderIR::OnMemoryFillExpr(Index memidx) {
return AppendExpr(MakeUnique<MemoryFillExpr>(Var(memidx)));
return AppendExpr(MakeUnique<MemoryFillExpr>(Var(memidx, GetLocation())));
}

Result BinaryReaderIR::OnMemoryGrowExpr(Index memidx) {
return AppendExpr(MakeUnique<MemoryGrowExpr>(Var(memidx)));
return AppendExpr(MakeUnique<MemoryGrowExpr>(Var(memidx, GetLocation())));
}

Result BinaryReaderIR::OnMemoryInitExpr(Index segment, Index memidx) {
return AppendExpr(MakeUnique<MemoryInitExpr>(Var(segment), Var(memidx)));
return AppendExpr(MakeUnique<MemoryInitExpr>(Var(segment, GetLocation()),
Var(memidx, GetLocation())));
}

Result BinaryReaderIR::OnMemorySizeExpr(Index memidx) {
return AppendExpr(MakeUnique<MemorySizeExpr>(Var(memidx)));
return AppendExpr(MakeUnique<MemorySizeExpr>(Var(memidx, GetLocation())));
}

Result BinaryReaderIR::OnTableCopyExpr(Index dst_index, Index src_index) {
return AppendExpr(MakeUnique<TableCopyExpr>(Var(dst_index), Var(src_index)));
return AppendExpr(MakeUnique<TableCopyExpr>(Var(dst_index, GetLocation()),
Var(src_index, GetLocation())));
}

Result BinaryReaderIR::OnElemDropExpr(Index segment) {
return AppendExpr(MakeUnique<ElemDropExpr>(Var(segment)));
return AppendExpr(MakeUnique<ElemDropExpr>(Var(segment, GetLocation())));
}

Result BinaryReaderIR::OnTableInitExpr(Index segment, Index table_index) {
return AppendExpr(MakeUnique<TableInitExpr>(Var(segment), Var(table_index)));
return AppendExpr(MakeUnique<TableInitExpr>(Var(segment, GetLocation()),
Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnTableGetExpr(Index table_index) {
return AppendExpr(MakeUnique<TableGetExpr>(Var(table_index)));
return AppendExpr(MakeUnique<TableGetExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnTableSetExpr(Index table_index) {
return AppendExpr(MakeUnique<TableSetExpr>(Var(table_index)));
return AppendExpr(MakeUnique<TableSetExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnTableGrowExpr(Index table_index) {
return AppendExpr(MakeUnique<TableGrowExpr>(Var(table_index)));
return AppendExpr(MakeUnique<TableGrowExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnTableSizeExpr(Index table_index) {
return AppendExpr(MakeUnique<TableSizeExpr>(Var(table_index)));
return AppendExpr(MakeUnique<TableSizeExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnTableFillExpr(Index table_index) {
return AppendExpr(MakeUnique<TableFillExpr>(Var(table_index)));
return AppendExpr(MakeUnique<TableFillExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnRefFuncExpr(Index func_index) {
return AppendExpr(MakeUnique<RefFuncExpr>(Var(func_index)));
return AppendExpr(MakeUnique<RefFuncExpr>(Var(func_index, GetLocation())));
}

Result BinaryReaderIR::OnRefNullExpr(Type type) {
Expand Down Expand Up @@ -1062,8 +1065,8 @@ Result BinaryReaderIR::OnStoreExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<StoreExpr>(opcode, Var(memidx), 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<StoreExpr>(opcode, Var(memidx, GetLocation()),
1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnThrowExpr(Index tag_index) {
Expand Down Expand Up @@ -1173,7 +1176,7 @@ Result BinaryReaderIR::OnSimdLoadLaneExpr(Opcode opcode,
Address offset,
uint64_t value) {
return AppendExpr(MakeUnique<SimdLoadLaneExpr>(
opcode, Var(memidx), 1 << alignment_log2, offset, value));
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset, value));
}

Result BinaryReaderIR::OnSimdStoreLaneExpr(Opcode opcode,
Expand All @@ -1182,7 +1185,7 @@ Result BinaryReaderIR::OnSimdStoreLaneExpr(Opcode opcode,
Address offset,
uint64_t value) {
return AppendExpr(MakeUnique<SimdStoreLaneExpr>(
opcode, Var(memidx), 1 << alignment_log2, offset, value));
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset, value));
}

Result BinaryReaderIR::OnSimdShuffleOpExpr(Opcode opcode, v128 value) {
Expand Down
4 changes: 2 additions & 2 deletions src/c-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ void CWriter::Write(const GotoLabel& goto_label) {
// We've generated names for all labels, so we should only be using an
// index when branching to the implicit function label, which can't be
// named.
Write("goto ", Var(kImplicitFuncLabel), ";");
Write("goto ", Var(kImplicitFuncLabel, {}), ";");
}
}

Expand Down Expand Up @@ -1979,7 +1979,7 @@ void CWriter::Write(const ExprList& exprs) {
case ExprType::Return:
// Goto the function label instead; this way we can do shared function
// cleanup code in one place.
Write(GotoLabel(Var(label_stack_.size() - 1)), Newline());
Write(GotoLabel(Var(label_stack_.size() - 1, {})), Newline());
// Stop processing this ExprList, since the following are unreachable.
return;

Expand Down
2 changes: 1 addition & 1 deletion src/decompiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ struct Decompiler {
Index index,
std::string_view name) {
// Figure out if this thing is imported, exported, or neither.
auto is_import = mc.module.IsImport(kind, Var(index));
auto is_import = mc.module.IsImport(kind, Var(index, Location()));
// TODO: is this the best way to check for export?
// FIXME: this doesn't work for functions that get renamed in some way,
// as the export has the original name..
Expand Down
Loading

0 comments on commit 3bf73a8

Please sign in to comment.