summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ir.cc65
-rw-r--r--src/c-writer.cc4
-rw-r--r--src/decompiler.cc2
-rw-r--r--src/interp/binary-reader-interp.cc138
-rw-r--r--src/ir.cc6
-rw-r--r--src/ir.h5
-rw-r--r--src/validator.cc2
-rw-r--r--src/wast-parser.cc6
-rw-r--r--src/wat-writer.cc2
9 files changed, 135 insertions, 95 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index ff3eafab..44e93782 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -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();
@@ -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));
}
@@ -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));
}
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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,
@@ -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) {
diff --git a/src/c-writer.cc b/src/c-writer.cc
index 2b488d92..356d1981 100644
--- a/src/c-writer.cc
+++ b/src/c-writer.cc
@@ -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, {}), ";");
}
}
@@ -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;
diff --git a/src/decompiler.cc b/src/decompiler.cc
index 91272301..09fa6950 100644
--- a/src/decompiler.cc
+++ b/src/decompiler.cc
@@ -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..
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index 47a2d256..5429a88a 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -503,7 +503,8 @@ Result BinaryReaderInterp::OnImportFunc(Index import_index,
std::string_view field_name,
Index func_index,
Index sig_index) {
- CHECK_RESULT(validator_.OnFunction(GetLocation(), Var(sig_index)));
+ CHECK_RESULT(
+ validator_.OnFunction(GetLocation(), Var(sig_index, GetLocation())));
FuncType& func_type = module_.func_types[sig_index];
module_.imports.push_back(ImportDesc{ImportType(
std::string(module_name), std::string(field_name), func_type.Clone())});
@@ -557,7 +558,7 @@ Result BinaryReaderInterp::OnImportTag(Index import_index,
std::string_view field_name,
Index tag_index,
Index sig_index) {
- CHECK_RESULT(validator_.OnTag(GetLocation(), Var(sig_index)));
+ CHECK_RESULT(validator_.OnTag(GetLocation(), Var(sig_index, GetLocation())));
FuncType& func_type = module_.func_types[sig_index];
TagType tag_type{TagAttr::Exception, func_type.params};
module_.imports.push_back(ImportDesc{ImportType(
@@ -572,7 +573,8 @@ Result BinaryReaderInterp::OnFunctionCount(Index count) {
}
Result BinaryReaderInterp::OnFunction(Index index, Index sig_index) {
- CHECK_RESULT(validator_.OnFunction(GetLocation(), Var(sig_index)));
+ CHECK_RESULT(
+ validator_.OnFunction(GetLocation(), Var(sig_index, GetLocation())));
FuncType& func_type = module_.func_types[sig_index];
module_.funcs.push_back(FuncDesc{func_type, {}, Istream::kInvalidOffset, {}});
func_types_.push_back(func_type);
@@ -654,7 +656,7 @@ Result BinaryReaderInterp::OnTagCount(Index count) {
}
Result BinaryReaderInterp::OnTagType(Index index, Index sig_index) {
- CHECK_RESULT(validator_.OnTag(GetLocation(), Var(sig_index)));
+ CHECK_RESULT(validator_.OnTag(GetLocation(), Var(sig_index, GetLocation())));
FuncType& func_type = module_.func_types[sig_index];
TagType tag_type{TagAttr::Exception, func_type.params};
module_.tags.push_back(TagDesc{tag_type});
@@ -666,7 +668,8 @@ Result BinaryReaderInterp::OnExport(Index index,
ExternalKind kind,
Index item_index,
std::string_view name) {
- CHECK_RESULT(validator_.OnExport(GetLocation(), kind, Var(item_index), name));
+ CHECK_RESULT(validator_.OnExport(GetLocation(), kind,
+ Var(item_index, GetLocation()), name));
std::unique_ptr<ExternType> type;
switch (kind) {
@@ -682,7 +685,8 @@ Result BinaryReaderInterp::OnExport(Index index,
}
Result BinaryReaderInterp::OnStartFunction(Index func_index) {
- CHECK_RESULT(validator_.OnStart(GetLocation(), Var(func_index)));
+ CHECK_RESULT(
+ validator_.OnStart(GetLocation(), Var(func_index, GetLocation())));
module_.starts.push_back(StartDesc{func_index});
return Result::Ok;
}
@@ -696,7 +700,8 @@ Result BinaryReaderInterp::BeginElemSegment(Index index,
Index table_index,
uint8_t flags) {
auto mode = ToSegmentMode(flags);
- CHECK_RESULT(validator_.OnElemSegment(GetLocation(), Var(table_index), mode));
+ CHECK_RESULT(validator_.OnElemSegment(GetLocation(),
+ Var(table_index, GetLocation()), mode));
FuncDesc init_func{
FuncType{{}, {ValueType::I32}}, {}, Istream::kInvalidOffset, {}};
@@ -738,8 +743,8 @@ Result BinaryReaderInterp::OnElemSegmentElemExpr_RefNull(Index segment_index,
Result BinaryReaderInterp::OnElemSegmentElemExpr_RefFunc(Index segment_index,
Index func_index) {
- CHECK_RESULT(
- validator_.OnElemSegmentElemExpr_RefFunc(GetLocation(), Var(func_index)));
+ CHECK_RESULT(validator_.OnElemSegmentElemExpr_RefFunc(
+ GetLocation(), Var(func_index, GetLocation())));
ElemDesc& elem = module_.elems.back();
elem.elements.push_back(ElemExpr{ElemKind::RefFunc, func_index});
return Result::Ok;
@@ -765,8 +770,8 @@ Result BinaryReaderInterp::BeginDataSegment(Index index,
Index memory_index,
uint8_t flags) {
auto mode = ToSegmentMode(flags);
- CHECK_RESULT(
- validator_.OnDataSegment(GetLocation(), Var(memory_index), mode));
+ CHECK_RESULT(validator_.OnDataSegment(
+ GetLocation(), Var(memory_index, GetLocation()), mode));
FuncDesc init_func{
FuncType{{}, {ValueType::I32}}, {}, Istream::kInvalidOffset, {}};
@@ -1038,14 +1043,14 @@ Result BinaryReaderInterp::OnBrExpr(Index depth) {
Index drop_count, keep_count, catch_drop_count;
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
CHECK_RESULT(validator_.GetCatchCount(depth, &catch_drop_count));
- CHECK_RESULT(validator_.OnBr(GetLocation(), Var(depth)));
+ CHECK_RESULT(validator_.OnBr(GetLocation(), Var(depth, GetLocation())));
EmitBr(depth, drop_count, keep_count, catch_drop_count);
return Result::Ok;
}
Result BinaryReaderInterp::OnBrIfExpr(Index depth) {
Index drop_count, keep_count, catch_drop_count;
- CHECK_RESULT(validator_.OnBrIf(GetLocation(), Var(depth)));
+ CHECK_RESULT(validator_.OnBrIf(GetLocation(), Var(depth, GetLocation())));
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
CHECK_RESULT(validator_.GetCatchCount(depth, &catch_drop_count));
// Flip the br_if so if <cond> is true it can drop values from the stack.
@@ -1065,7 +1070,8 @@ Result BinaryReaderInterp::OnBrTableExpr(Index num_targets,
for (Index i = 0; i < num_targets; ++i) {
Index depth = target_depths[i];
- CHECK_RESULT(validator_.OnBrTableTarget(GetLocation(), Var(depth)));
+ CHECK_RESULT(
+ validator_.OnBrTableTarget(GetLocation(), Var(depth, GetLocation())));
CHECK_RESULT(GetBrDropKeepCount(depth, &drop_count, &keep_count));
CHECK_RESULT(validator_.GetCatchCount(depth, &catch_drop_count));
// Emit DropKeep directly (instead of using EmitDropKeep) so the
@@ -1074,8 +1080,8 @@ Result BinaryReaderInterp::OnBrTableExpr(Index num_targets,
istream_.Emit(Opcode::InterpCatchDrop, catch_drop_count);
EmitBr(depth, 0, 0, 0);
}
- CHECK_RESULT(
- validator_.OnBrTableTarget(GetLocation(), Var(default_target_depth)));
+ CHECK_RESULT(validator_.OnBrTableTarget(
+ GetLocation(), Var(default_target_depth, GetLocation())));
CHECK_RESULT(
GetBrDropKeepCount(default_target_depth, &drop_count, &keep_count));
CHECK_RESULT(
@@ -1090,7 +1096,8 @@ Result BinaryReaderInterp::OnBrTableExpr(Index num_targets,
}
Result BinaryReaderInterp::OnCallExpr(Index func_index) {
- CHECK_RESULT(validator_.OnCall(GetLocation(), Var(func_index)));
+ CHECK_RESULT(
+ validator_.OnCall(GetLocation(), Var(func_index, GetLocation())));
if (func_index >= num_func_imports()) {
istream_.Emit(Opcode::Call, func_index);
@@ -1103,8 +1110,9 @@ Result BinaryReaderInterp::OnCallExpr(Index func_index) {
Result BinaryReaderInterp::OnCallIndirectExpr(Index sig_index,
Index table_index) {
- CHECK_RESULT(validator_.OnCallIndirect(GetLocation(), Var(sig_index),
- Var(table_index)));
+ CHECK_RESULT(validator_.OnCallIndirect(GetLocation(),
+ Var(sig_index, GetLocation()),
+ Var(table_index, GetLocation())));
istream_.Emit(Opcode::CallIndirect, table_index, sig_index);
return Result::Ok;
}
@@ -1119,7 +1127,8 @@ Result BinaryReaderInterp::OnReturnCallExpr(Index func_index) {
validator_.GetCatchCount(label_stack_.size() - 1, &catch_drop_count));
// The validator must be run after we get the drop/keep counts, since it
// will change the type stack.
- CHECK_RESULT(validator_.OnReturnCall(GetLocation(), Var(func_index)));
+ CHECK_RESULT(
+ validator_.OnReturnCall(GetLocation(), Var(func_index, GetLocation())));
istream_.EmitDropKeep(drop_count, keep_count);
istream_.EmitCatchDrop(catch_drop_count);
@@ -1149,8 +1158,9 @@ Result BinaryReaderInterp::OnReturnCallIndirectExpr(Index sig_index,
validator_.GetCatchCount(label_stack_.size() - 1, &catch_drop_count));
// The validator must be run after we get the drop/keep counts, since it
// changes the type stack.
- CHECK_RESULT(validator_.OnReturnCallIndirect(GetLocation(), Var(sig_index),
- Var(table_index)));
+ CHECK_RESULT(validator_.OnReturnCallIndirect(
+ GetLocation(), Var(sig_index, GetLocation()),
+ Var(table_index, GetLocation())));
istream_.EmitDropKeep(drop_count, keep_count);
istream_.EmitCatchDrop(catch_drop_count);
istream_.Emit(Opcode::ReturnCallIndirect, table_index, sig_index);
@@ -1206,13 +1216,15 @@ Result BinaryReaderInterp::OnV128ConstExpr(v128 value_bits) {
}
Result BinaryReaderInterp::OnGlobalGetExpr(Index global_index) {
- CHECK_RESULT(validator_.OnGlobalGet(GetLocation(), Var(global_index)));
+ CHECK_RESULT(
+ validator_.OnGlobalGet(GetLocation(), Var(global_index, GetLocation())));
istream_.Emit(Opcode::GlobalGet, global_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnGlobalSetExpr(Index global_index) {
- CHECK_RESULT(validator_.OnGlobalSet(GetLocation(), Var(global_index)));
+ CHECK_RESULT(
+ validator_.OnGlobalSet(GetLocation(), Var(global_index, GetLocation())));
istream_.Emit(Opcode::GlobalSet, global_index);
return Result::Ok;
}
@@ -1227,7 +1239,8 @@ Result BinaryReaderInterp::OnLocalGetExpr(Index local_index) {
// will update the type stack size. We need the index to be relative to the
// old stack size.
Index translated_local_index = TranslateLocalIndex(local_index);
- CHECK_RESULT(validator_.OnLocalGet(GetLocation(), Var(local_index)));
+ CHECK_RESULT(
+ validator_.OnLocalGet(GetLocation(), Var(local_index, GetLocation())));
istream_.Emit(Opcode::LocalGet, translated_local_index);
return Result::Ok;
}
@@ -1235,13 +1248,15 @@ Result BinaryReaderInterp::OnLocalGetExpr(Index local_index) {
Result BinaryReaderInterp::OnLocalSetExpr(Index local_index) {
// See comment in OnLocalGetExpr above.
Index translated_local_index = TranslateLocalIndex(local_index);
- CHECK_RESULT(validator_.OnLocalSet(GetLocation(), Var(local_index)));
+ CHECK_RESULT(
+ validator_.OnLocalSet(GetLocation(), Var(local_index, GetLocation())));
istream_.Emit(Opcode::LocalSet, translated_local_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnLocalTeeExpr(Index local_index) {
- CHECK_RESULT(validator_.OnLocalTee(GetLocation(), Var(local_index)));
+ CHECK_RESULT(
+ validator_.OnLocalTee(GetLocation(), Var(local_index, GetLocation())));
istream_.Emit(Opcode::LocalTee, TranslateLocalIndex(local_index));
return Result::Ok;
}
@@ -1250,7 +1265,8 @@ Result BinaryReaderInterp::OnLoadExpr(Opcode opcode,
Index memidx,
Address align_log2,
Address offset) {
- CHECK_RESULT(validator_.OnLoad(GetLocation(), opcode, Var(memidx),
+ CHECK_RESULT(validator_.OnLoad(GetLocation(), opcode,
+ Var(memidx, GetLocation()),
GetAlignment(align_log2)));
istream_.Emit(opcode, memidx, offset);
return Result::Ok;
@@ -1260,44 +1276,51 @@ Result BinaryReaderInterp::OnStoreExpr(Opcode opcode,
Index memidx,
Address align_log2,
Address offset) {
- CHECK_RESULT(validator_.OnStore(GetLocation(), opcode, Var(memidx),
+ CHECK_RESULT(validator_.OnStore(GetLocation(), opcode,
+ Var(memidx, GetLocation()),
GetAlignment(align_log2)));
istream_.Emit(opcode, memidx, offset);
return Result::Ok;
}
Result BinaryReaderInterp::OnMemoryGrowExpr(Index memidx) {
- CHECK_RESULT(validator_.OnMemoryGrow(GetLocation(), Var(memidx)));
+ CHECK_RESULT(
+ validator_.OnMemoryGrow(GetLocation(), Var(memidx, GetLocation())));
istream_.Emit(Opcode::MemoryGrow, memidx);
return Result::Ok;
}
Result BinaryReaderInterp::OnMemorySizeExpr(Index memidx) {
- CHECK_RESULT(validator_.OnMemorySize(GetLocation(), Var(memidx)));
+ CHECK_RESULT(
+ validator_.OnMemorySize(GetLocation(), Var(memidx, GetLocation())));
istream_.Emit(Opcode::MemorySize, memidx);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableGrowExpr(Index table_index) {
- CHECK_RESULT(validator_.OnTableGrow(GetLocation(), Var(table_index)));
+ CHECK_RESULT(
+ validator_.OnTableGrow(GetLocation(), Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableGrow, table_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableSizeExpr(Index table_index) {
- CHECK_RESULT(validator_.OnTableSize(GetLocation(), Var(table_index)));
+ CHECK_RESULT(
+ validator_.OnTableSize(GetLocation(), Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableSize, table_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableFillExpr(Index table_index) {
- CHECK_RESULT(validator_.OnTableFill(GetLocation(), Var(table_index)));
+ CHECK_RESULT(
+ validator_.OnTableFill(GetLocation(), Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableFill, table_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnRefFuncExpr(Index func_index) {
- CHECK_RESULT(validator_.OnRefFunc(GetLocation(), Var(func_index)));
+ CHECK_RESULT(
+ validator_.OnRefFunc(GetLocation(), Var(func_index, GetLocation())));
istream_.Emit(Opcode::RefFunc, func_index);
return Result::Ok;
}
@@ -1369,73 +1392,83 @@ Result BinaryReaderInterp::OnAtomicNotifyExpr(Opcode opcode,
}
Result BinaryReaderInterp::OnMemoryCopyExpr(Index srcmemidx, Index destmemidx) {
- CHECK_RESULT(
- validator_.OnMemoryCopy(GetLocation(), Var(srcmemidx), Var(destmemidx)));
+ CHECK_RESULT(validator_.OnMemoryCopy(GetLocation(),
+ Var(srcmemidx, GetLocation()),
+ Var(destmemidx, GetLocation())));
istream_.Emit(Opcode::MemoryCopy, srcmemidx, destmemidx);
return Result::Ok;
}
Result BinaryReaderInterp::OnDataDropExpr(Index segment_index) {
- CHECK_RESULT(validator_.OnDataDrop(GetLocation(), Var(segment_index)));
+ CHECK_RESULT(
+ validator_.OnDataDrop(GetLocation(), Var(segment_index, GetLocation())));
istream_.Emit(Opcode::DataDrop, segment_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnMemoryFillExpr(Index memidx) {
- CHECK_RESULT(validator_.OnMemoryFill(GetLocation(), Var(memidx)));
+ CHECK_RESULT(
+ validator_.OnMemoryFill(GetLocation(), Var(memidx, GetLocation())));
istream_.Emit(Opcode::MemoryFill, memidx);
return Result::Ok;
}
Result BinaryReaderInterp::OnMemoryInitExpr(Index segment_index, Index memidx) {
- CHECK_RESULT(
- validator_.OnMemoryInit(GetLocation(), Var(segment_index), Var(memidx)));
+ CHECK_RESULT(validator_.OnMemoryInit(GetLocation(),
+ Var(segment_index, GetLocation()),
+ Var(memidx, GetLocation())));
istream_.Emit(Opcode::MemoryInit, memidx, segment_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableGetExpr(Index table_index) {
- CHECK_RESULT(validator_.OnTableGet(GetLocation(), Var(table_index)));
+ CHECK_RESULT(
+ validator_.OnTableGet(GetLocation(), Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableGet, table_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableSetExpr(Index table_index) {
- CHECK_RESULT(validator_.OnTableSet(GetLocation(), Var(table_index)));
+ CHECK_RESULT(
+ validator_.OnTableSet(GetLocation(), Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableSet, table_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableCopyExpr(Index dst_index, Index src_index) {
- CHECK_RESULT(
- validator_.OnTableCopy(GetLocation(), Var(dst_index), Var(src_index)));
+ CHECK_RESULT(validator_.OnTableCopy(GetLocation(),
+ Var(dst_index, GetLocation()),
+ Var(src_index, GetLocation())));
istream_.Emit(Opcode::TableCopy, dst_index, src_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnElemDropExpr(Index segment_index) {
- CHECK_RESULT(validator_.OnElemDrop(GetLocation(), Var(segment_index)));
+ CHECK_RESULT(
+ validator_.OnElemDrop(GetLocation(), Var(segment_index, GetLocation())));
istream_.Emit(Opcode::ElemDrop, segment_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnTableInitExpr(Index segment_index,
Index table_index) {
- CHECK_RESULT(validator_.OnTableInit(GetLocation(), Var(segment_index),
- Var(table_index)));
+ CHECK_RESULT(validator_.OnTableInit(GetLocation(),
+ Var(segment_index, GetLocation()),
+ Var(table_index, GetLocation())));
istream_.Emit(Opcode::TableInit, table_index, segment_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnThrowExpr(Index tag_index) {
- CHECK_RESULT(validator_.OnThrow(GetLocation(), Var(tag_index)));
+ CHECK_RESULT(
+ validator_.OnThrow(GetLocation(), Var(tag_index, GetLocation())));
istream_.Emit(Opcode::Throw, tag_index);
return Result::Ok;
}
Result BinaryReaderInterp::OnRethrowExpr(Index depth) {
Index catch_depth;
- CHECK_RESULT(validator_.OnRethrow(GetLocation(), Var(depth)));
+ CHECK_RESULT(validator_.OnRethrow(GetLocation(), Var(depth, GetLocation())));
CHECK_RESULT(validator_.GetCatchCount(depth, &catch_depth));
// The rethrow opcode takes an index into the exception stack rather than
// the number of catch nestings, so we subtract one here.
@@ -1463,7 +1496,8 @@ Result BinaryReaderInterp::OnTryExpr(Type sig_type) {
}
Result BinaryReaderInterp::OnCatchExpr(Index tag_index) {
- CHECK_RESULT(validator_.OnCatch(GetLocation(), Var(tag_index), false));
+ CHECK_RESULT(
+ validator_.OnCatch(GetLocation(), Var(tag_index, GetLocation()), false));
Label* label = TopLabel();
HandlerDesc& desc = func_->handlers[label->handler_desc_index];
desc.kind = HandlerKind::Catch;
@@ -1513,7 +1547,7 @@ Result BinaryReaderInterp::OnCatchAllExpr() {
}
Result BinaryReaderInterp::OnDelegateExpr(Index depth) {
- CHECK_RESULT(validator_.OnDelegate(GetLocation(), Var(depth)));
+ CHECK_RESULT(validator_.OnDelegate(GetLocation(), Var(depth, GetLocation())));
Label* label = TopLabel();
assert(label->kind == LabelKind::Try);
HandlerDesc& desc = func_->handlers[label->handler_desc_index];
diff --git a/src/ir.cc b/src/ir.cc
index 65152b7d..2d9c8b3a 100644
--- a/src/ir.cc
+++ b/src/ir.cc
@@ -586,17 +586,19 @@ void MakeTypeBindingReverseMapping(
}
}
+Var::Var() : Var(kInvalidIndex, Location()) {}
+
Var::Var(Index index, const Location& loc)
: loc(loc), type_(VarType::Index), index_(index) {}
Var::Var(std::string_view name, const Location& loc)
: loc(loc), type_(VarType::Name), name_(name) {}
-Var::Var(Var&& rhs) : Var(kInvalidIndex) {
+Var::Var(Var&& rhs) : Var() {
*this = std::move(rhs);
}
-Var::Var(const Var& rhs) : Var(kInvalidIndex) {
+Var::Var(const Var& rhs) : Var() {
*this = rhs;
}
diff --git a/src/ir.h b/src/ir.h
index d085ff4c..fbc48c7c 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -41,8 +41,9 @@ enum class VarType {
};
struct Var {
- explicit Var(Index index = kInvalidIndex, const Location& loc = Location());
- explicit Var(std::string_view name, const Location& loc = Location());
+ explicit Var();
+ explicit Var(Index index, const Location& loc);
+ explicit Var(std::string_view name, const Location& loc);
Var(Var&&);
Var(const Var&);
Var& operator=(const Var&);
diff --git a/src/validator.cc b/src/validator.cc
index 0634ac43..06831a8d 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -280,7 +280,7 @@ Result Validator::OnCallRefExpr(CallRefExpr* expr) {
Index function_type_index;
result_ |= validator_.OnCallRef(expr->loc, &function_type_index);
if (Succeeded(result_)) {
- expr->function_type_index = Var{function_type_index};
+ expr->function_type_index = Var{function_type_index, expr->loc};
return Result::Ok;
}
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index ddcd95cd..d1564439 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -937,7 +937,7 @@ Result WastParser::ParseValueType(Var* out_type) {
return Result::Error;
}
- *out_type = Var(type);
+ *out_type = Var(type, GetLocation());
return Result::Ok;
}
@@ -1654,7 +1654,7 @@ Result WastParser::ParseMemoryModuleField(Module* module) {
if (MatchLpar(TokenType::Data)) {
auto data_segment_field = MakeUnique<DataSegmentModuleField>(loc);
DataSegment& data_segment = data_segment_field->data_segment;
- data_segment.memory_var = Var(module->memories.size());
+ data_segment.memory_var = Var(module->memories.size(), GetLocation());
data_segment.offset.push_back(MakeUnique<ConstExpr>(
field->memory.page_limits.is_64 ? Const::I64(0) : Const::I32(0)));
data_segment.offset.back().loc = loc;
@@ -1726,7 +1726,7 @@ Result WastParser::ParseTableModuleField(Module* module) {
auto elem_segment_field = MakeUnique<ElemSegmentModuleField>(loc);
ElemSegment& elem_segment = elem_segment_field->elem_segment;
- elem_segment.table_var = Var(module->tables.size());
+ elem_segment.table_var = Var(module->tables.size(), GetLocation());
elem_segment.offset.push_back(MakeUnique<ConstExpr>(Const::I32(0)));
elem_segment.offset.back().loc = loc;
elem_segment.elem_type = elem_type;
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 45350e08..b6f19652 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -1329,7 +1329,7 @@ void WatWriter::WriteBeginFunc(const Func& func) {
WriteCloseSpace();
}
- if (module.IsImport(ExternalKind::Func, Var(func_index_))) {
+ if (module.IsImport(ExternalKind::Func, Var(func_index_, Location()))) {
// Imported functions can be written a few ways:
//
// 1. (import "module" "field" (func (type 0)))