Skip to content

Commit e2a0cdf

Browse files
committed
Update testsuite and implement table64
See WebAssembly/memory64#51 Includes workaround for #2422
1 parent 39f85a7 commit e2a0cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4191
-241
lines changed

include/wabt/interp/interp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ class Thread {
11231123
T WABT_VECTORCALL Pop();
11241124
Value Pop();
11251125
u64 PopPtr(const Memory::Ptr& memory);
1126+
u64 PopPtr(const Table::Ptr& table);
1127+
void PushPtr(const Memory::Ptr& memory, u64 value);
1128+
void PushPtr(const Table::Ptr& table, u64 value);
11261129

11271130
template <typename T>
11281131
void WABT_VECTORCALL Push(T);

include/wabt/type-checker.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class TypeChecker {
7777
Result EndBrTable();
7878
Result OnCall(const TypeVector& param_types, const TypeVector& result_types);
7979
Result OnCallIndirect(const TypeVector& param_types,
80-
const TypeVector& result_types);
80+
const TypeVector& result_types,
81+
const Limits& table_limits);
8182
Result OnIndexedFuncRef(Index* out_index);
8283
Result OnReturnCall(const TypeVector& param_types,
8384
const TypeVector& result_types);
@@ -99,20 +100,20 @@ class TypeChecker {
99100
Result OnLocalSet(Type);
100101
Result OnLocalTee(Type);
101102
Result OnLoop(const TypeVector& param_types, const TypeVector& result_types);
102-
Result OnMemoryCopy(const Limits& dstlimits, const Limits& srclimits);
103+
Result OnMemoryCopy(const Limits& dst_limits, const Limits& src_limits);
103104
Result OnDataDrop(Index);
104105
Result OnMemoryFill(const Limits& limits);
105106
Result OnMemoryGrow(const Limits& limits);
106107
Result OnMemoryInit(Index, const Limits& limits);
107108
Result OnMemorySize(const Limits& limits);
108-
Result OnTableCopy();
109+
Result OnTableCopy(const Limits& dst_limits, const Limits& src_limits);
109110
Result OnElemDrop(Index);
110-
Result OnTableInit(Index, Index);
111-
Result OnTableGet(Type elem_type);
112-
Result OnTableSet(Type elem_type);
113-
Result OnTableGrow(Type elem_type);
114-
Result OnTableSize();
115-
Result OnTableFill(Type elem_type);
111+
Result OnTableInit(Index, const Limits& limits);
112+
Result OnTableGet(Type elem_type, const Limits& limits);
113+
Result OnTableSet(Type elem_type, const Limits& limits);
114+
Result OnTableGrow(Type elem_type, const Limits& limits);
115+
Result OnTableSize(const Limits& limits);
116+
Result OnTableFill(Type elem_type, const Limits& limits);
116117
Result OnRefFuncExpr(Index func_type, bool force_generic_funcref);
117118
Result OnRefNullExpr(Type type);
118119
Result OnRefIsNullExpr();

src/binary-reader-objdump.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,9 @@ Result BinaryReaderObjdump::OnTable(Index index,
16441644
if (!name.empty()) {
16451645
PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name));
16461646
}
1647+
if (elem_limits->is_64) {
1648+
PrintDetails(" i64");
1649+
}
16471650
PrintDetails("\n");
16481651
return Result::Ok;
16491652
}

src/binary-reader.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,16 @@ Result BinaryReader::ReadTable(Type* out_elem_type, Limits* out_elem_limits) {
582582
bool is_64 = flags & WABT_BINARY_LIMITS_IS_64_FLAG;
583583
const uint8_t unknown_flags = flags & ~WABT_BINARY_LIMITS_ALL_FLAGS;
584584
ERROR_IF(is_shared, "tables may not be shared");
585-
ERROR_IF(is_64, "tables may not be 64-bit");
585+
ERROR_IF(is_64 && !options_.features.memory64_enabled(),
586+
"memory64 not allowed");
586587
ERROR_UNLESS(unknown_flags == 0, "malformed table limits flag: %d", flags);
587588
CHECK_RESULT(ReadU32Leb128(&initial, "table initial elem count"));
588589
if (has_max) {
589590
CHECK_RESULT(ReadU32Leb128(&max, "table max elem count"));
590591
}
591592

592593
out_elem_limits->has_max = has_max;
594+
out_elem_limits->is_64 = is_64;
593595
out_elem_limits->initial = initial;
594596
out_elem_limits->max = max;
595597
return Result::Ok;

src/c-writer.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,15 @@ void CWriter::Write(const Const& const_) {
12921292
// Negative zero. Special-cased so it isn't written as -0 below.
12931293
Writef("-0.0");
12941294
} else {
1295-
Writef("%.17g", Bitcast<double>(f64_bits));
1295+
char buf[128];
1296+
snprintf(buf, sizeof(buf), "%.17g", Bitcast<double>(f64_bits));
1297+
// Append .0 if sprint didn't include a decimal point or use the
1298+
// exponent ('e') form. This is a workaround for an MSVC parsing
1299+
// issue: https://github.com/WebAssembly/wabt/issues/2422
1300+
if (!strchr(buf, '.') && !strchr(buf, 'e')) {
1301+
strcat(buf, ".0");
1302+
}
1303+
Writef("%s", buf);
12961304
}
12971305
break;
12981306
}
@@ -3636,18 +3644,18 @@ void CWriter::Write(const ExprList& exprs) {
36363644

36373645
case ExprType::TableGrow: {
36383646
const Table* table = module_->GetTable(cast<TableGrowExpr>(&expr)->var);
3639-
Write(StackVar(1, Type::I32), " = wasm_rt_grow_",
3647+
Write(StackVar(1, table->elem_limits.IndexType()), " = wasm_rt_grow_",
36403648
GetReferenceTypeName(table->elem_type), "_table(",
36413649
ExternalInstancePtr(ModuleFieldType::Table, table->name), ", ",
36423650
StackVar(0), ", ", StackVar(1), ");", Newline());
36433651
DropTypes(2);
3644-
PushType(Type::I32);
3652+
PushType(table->elem_limits.IndexType());
36453653
} break;
36463654

36473655
case ExprType::TableSize: {
36483656
const Table* table = module_->GetTable(cast<TableSizeExpr>(&expr)->var);
36493657

3650-
PushType(Type::I32);
3658+
PushType(table->elem_limits.IndexType());
36513659
Write(StackVar(0), " = ",
36523660
ExternalInstanceRef(ModuleFieldType::Table, table->name),
36533661
".size;", Newline());

src/interp/binary-reader-interp.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
306306
Index keep_extra,
307307
Index* out_drop_count,
308308
Index* out_keep_count);
309-
Result BeginInitExpr(Type type, FuncDesc* init_func);
309+
Result BeginInitExpr(FuncDesc* init_func);
310310
Result EndInitExpr();
311311

312312
void EmitBr(Index depth,
@@ -631,7 +631,7 @@ Result BinaryReaderInterp::BeginGlobal(Index index, Type type, bool mutable_) {
631631

632632
Result BinaryReaderInterp::BeginGlobalInitExpr(Index index) {
633633
GlobalDesc& global = module_.globals.back();
634-
return BeginInitExpr(global.type.type, &global.init_func);
634+
return BeginInitExpr(&global.init_func);
635635
}
636636

637637
Result BinaryReaderInterp::EndInitExpr() {
@@ -642,10 +642,11 @@ Result BinaryReaderInterp::EndInitExpr() {
642642
return Result::Ok;
643643
}
644644

645-
Result BinaryReaderInterp::BeginInitExpr(Type type, FuncDesc* func) {
645+
Result BinaryReaderInterp::BeginInitExpr(FuncDesc* func) {
646646
label_stack_.clear();
647647
func_ = func;
648648
func_->code_offset = istream_.end();
649+
Type type = func->type.results[0];
649650
CHECK_RESULT(validator_.BeginInitExpr(GetLocation(), type));
650651
// Push implicit init func label (equivalent to return).
651652
PushLabel(LabelKind::Try, Istream::kInvalidOffset, Istream::kInvalidOffset);
@@ -709,16 +710,21 @@ Result BinaryReaderInterp::BeginElemSegment(Index index,
709710
CHECK_RESULT(validator_.OnElemSegment(GetLocation(),
710711
Var(table_index, GetLocation()), mode));
711712

713+
ValueType offset_type = ValueType::I32;
714+
if (table_index < table_types_.size() &&
715+
table_types_[table_index].limits.is_64) {
716+
offset_type = ValueType::I64;
717+
}
712718
FuncDesc init_func{
713-
FuncType{{}, {ValueType::I32}}, {}, Istream::kInvalidOffset, {}};
719+
FuncType{{}, {offset_type}}, {}, Istream::kInvalidOffset, {}};
714720
ElemDesc desc{{}, ValueType::Void, mode, table_index, init_func};
715721
module_.elems.push_back(desc);
716722
return Result::Ok;
717723
}
718724

719725
Result BinaryReaderInterp::BeginElemSegmentInitExpr(Index index) {
720726
ElemDesc& elem = module_.elems.back();
721-
return BeginInitExpr(Type::I32, &elem.init_func);
727+
return BeginInitExpr(&elem.init_func);
722728
}
723729

724730
Result BinaryReaderInterp::EndElemSegmentInitExpr(Index index) {
@@ -744,7 +750,7 @@ Result BinaryReaderInterp::BeginElemExpr(Index elem_index, Index expr_index) {
744750
elem.elements.push_back(
745751
{FuncType{{}, {elem.type}}, {}, Istream::kInvalidOffset, {}});
746752
assert(expr_index == elem.elements.size() - 1);
747-
return BeginInitExpr(elem.type, &elem.elements.back());
753+
return BeginInitExpr(&elem.elements.back());
748754
}
749755

750756
Result BinaryReaderInterp::EndElemExpr(Index elem_index, Index expr_index) {
@@ -758,9 +764,8 @@ Result BinaryReaderInterp::OnDataCount(Index count) {
758764
}
759765

760766
Result BinaryReaderInterp::BeginDataSegmentInitExpr(Index index) {
761-
MemoryType t = memory_types_[0];
762767
DataDesc& data = module_.datas.back();
763-
return BeginInitExpr(t.limits.is_64 ? Type::I64 : Type::I32, &data.init_func);
768+
return BeginInitExpr(&data.init_func);
764769
}
765770

766771
Result BinaryReaderInterp::EndDataSegmentInitExpr(Index index) {
@@ -774,8 +779,13 @@ Result BinaryReaderInterp::BeginDataSegment(Index index,
774779
CHECK_RESULT(validator_.OnDataSegment(
775780
GetLocation(), Var(memory_index, GetLocation()), mode));
776781

782+
ValueType offset_type = ValueType::I32;
783+
if (memory_index < memory_types_.size() &&
784+
memory_types_[memory_index].limits.is_64) {
785+
offset_type = ValueType::I64;
786+
}
777787
FuncDesc init_func{
778-
FuncType{{}, {ValueType::I32}}, {}, Istream::kInvalidOffset, {}};
788+
FuncType{{}, {offset_type}}, {}, Istream::kInvalidOffset, {}};
779789
DataDesc desc{{}, mode, memory_index, init_func};
780790
module_.datas.push_back(desc);
781791
return Result::Ok;

0 commit comments

Comments
 (0)