Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Wabt has been compiled to JavaScript via emscripten. Some of the functionality i
| [extended-const][] | `--enable-extended-const` | | ✓ | ✓ | ✓ | ✓ | ✓ |
| [relaxed-simd][] | `--enable-relaxed-simd` | | ✓ | ✓ | ✓ | ✓ | |
| [custom-page-sizes][] | `--enable-custom-page-sizes`| | ✓ | ✓ | ✓ | ✓ | ✓ |
| [function-references][] | `--enable-function-references` | | ✓ | ✓ | ✓ | ✓ | |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used update-spec-tests.py and updated README before, so these are just speculative changes.


[exception handling]: https://github.com/WebAssembly/exception-handling
[mutable globals]: https://github.com/WebAssembly/mutable-global
Expand All @@ -80,6 +81,7 @@ Wabt has been compiled to JavaScript via emscripten. Some of the functionality i
[extended-const]: https://github.com/WebAssembly/extended-const
[relaxed-simd]: https://github.com/WebAssembly/relaxed-simd
[custom-page-sizes]: https://github.com/WebAssembly/custom-page-sizes
[function-references]: https://github.com/WebAssembly/function-references

## Cloning

Expand Down
10 changes: 7 additions & 3 deletions include/wabt/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ class BinaryReaderLogging : public BinaryReaderDelegate {

Result BeginTableSection(Offset size) override;
Result OnTableCount(Index count) override;
Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) override;
Result BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) override;
Result BeginTableInitExpr(Index index) override;
Result EndTableInitExpr(Index index) override;
Result EndTable(Index index) override;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since tables can have an initializer expressions now, this is a breaking change. I don't know how these are handled in this project.

Result EndTableSection() override;

Result BeginMemorySection(Offset size) override;
Expand Down
10 changes: 7 additions & 3 deletions include/wabt/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* Table section */
Result BeginTableSection(Offset size) override { return Result::Ok; }
Result OnTableCount(Index count) override { return Result::Ok; }
Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) override {
Result BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) override {
return Result::Ok;
}
Result BeginTableInitExpr(Index index) override { return Result::Ok; }
Result EndTableInitExpr(Index index) override { return Result::Ok; }
Result EndTable(Index index) override { return Result::Ok; }
Result EndTableSection() override { return Result::Ok; }

/* Memory section */
Expand Down
15 changes: 12 additions & 3 deletions include/wabt/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ struct CatchClause {
};
using CatchClauseVector = std::vector<CatchClause>;

enum class TableInitExprStatus {
TableWithInitExpression,
TableWithoutInitExpression,
};

class BinaryReaderDelegate {
public:
struct State {
Expand Down Expand Up @@ -156,9 +161,13 @@ class BinaryReaderDelegate {
/* Table section */
virtual Result BeginTableSection(Offset size) = 0;
virtual Result OnTableCount(Index count) = 0;
virtual Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) = 0;
virtual Result BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) = 0;
virtual Result BeginTableInitExpr(Index index) = 0;
virtual Result EndTableInitExpr(Index index) = 0;
virtual Result EndTable(Index index) = 0;
virtual Result EndTableSection() = 0;

/* Memory section */
Expand Down
10 changes: 2 additions & 8 deletions include/wabt/interp/interp-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,6 @@ void RequireType(ValueType type) {
assert(HasType<T>(type));
}

inline bool TypesMatch(ValueType expected, ValueType actual) {
// Currently there is no subtyping, so expected and actual must match
// exactly. In the future this may be expanded.
return expected == actual;
}

//// Value ////
inline Value WABT_VECTORCALL Value::Make(s32 val) { Value res; res.i32_ = val; res.SetType(ValueType::I32); return res; }
inline Value WABT_VECTORCALL Value::Make(u32 val) { Value res; res.i32_ = val; res.SetType(ValueType::I32); return res; }
Expand Down Expand Up @@ -682,8 +676,8 @@ inline bool Table::classof(const Object* obj) {
}

// static
inline Table::Ptr Table::New(Store& store, TableType type) {
return store.Alloc<Table>(store, type);
inline Table::Ptr Table::New(Store& store, TableType type, Ref init_ref) {
return store.Alloc<Table>(store, type, init_ref);
}

inline const ExternType& Table::extern_type() {
Expand Down
9 changes: 7 additions & 2 deletions include/wabt/interp/interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ using u32x2 = Simd<u32, 2>;

//// Types ////

bool TypesMatch(ValueType expected, ValueType actual);

//// Limits ////

bool CanGrow(const Limits&, u32 old_size, u32 delta, u32* new_size);
Result Match(const Limits& expected,
const Limits& actual,
Expand Down Expand Up @@ -334,6 +338,7 @@ struct FuncDesc {

struct TableDesc {
TableType type;
FuncDesc init_func;
};

struct MemoryDesc {
Expand Down Expand Up @@ -818,7 +823,7 @@ class Table : public Extern {
static const char* GetTypeName() { return "Table"; }
using Ptr = RefPtr<Table>;

static Table::Ptr New(Store&, TableType);
static Table::Ptr New(Store&, TableType, Ref);

Result Match(Store&, const ImportType&, Trap::Ptr* out_trap) override;

Expand Down Expand Up @@ -850,7 +855,7 @@ class Table : public Extern {

private:
friend Store;
explicit Table(Store&, TableType);
explicit Table(Store&, TableType, Ref);
void Mark(Store&) override;

TableType type_;
Expand Down
3 changes: 2 additions & 1 deletion include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,14 @@ struct Table {
std::string name;
Limits elem_limits;
Type elem_type;
ExprList init_expr;
};

using ExprListVector = std::vector<ExprList>;

struct ElemSegment {
explicit ElemSegment(std::string_view name) : name(name) {}
uint8_t GetFlags(const Module*) const;
uint8_t GetFlags(const Module*, bool function_references_enabled) const;

SegmentKind kind = SegmentKind::Active;
std::string name;
Expand Down
7 changes: 6 additions & 1 deletion include/wabt/shared-validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ struct ValidateOptions {
Features features;
};

enum class TableImportStatus {
TableIsImported,
TableIsNotImported,
};

class SharedValidator {
public:
WABT_DISALLOW_COPY_AND_ASSIGN(SharedValidator);
Expand Down Expand Up @@ -75,7 +80,7 @@ class SharedValidator {
Result OnArrayType(const Location&, TypeMut field);

Result OnFunction(const Location&, Var sig_var);
Result OnTable(const Location&, Type elem_type, const Limits&);
Result OnTable(const Location&, Type elem_type, const Limits&, TableImportStatus import_status, TableInitExprStatus init_provided);
Result OnMemory(const Location&, const Limits&, uint32_t page_size);
Result OnGlobalImport(const Location&, Type type, bool mutable_);
Result OnGlobal(const Location&, Type type, bool mutable_);
Expand Down
8 changes: 8 additions & 0 deletions src/apply-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class NameApplier : public ExprVisitor::DelegateNop {
Result VisitGlobal(Global* global);
Result VisitTag(Tag* tag);
Result VisitExport(Index export_index, Export* export_);
Result VisitTable(Table* table);
Result VisitElemSegment(Index elem_segment_index, ElemSegment* segment);
Result VisitDataSegment(Index data_segment_index, DataSegment* segment);
Result VisitStart(Var* start_var);
Expand Down Expand Up @@ -559,6 +560,11 @@ Result NameApplier::VisitExport(Index export_index, Export* export_) {
return Result::Ok;
}

Result NameApplier::VisitTable(Table* table) {
CHECK_RESULT(visitor_.VisitExprList(table->init_expr));
return Result::Ok;
}

Result NameApplier::VisitElemSegment(Index elem_segment_index,
ElemSegment* segment) {
CHECK_RESULT(UseNameForTableVar(&segment->table_var));
Expand Down Expand Up @@ -594,6 +600,8 @@ Result NameApplier::VisitModule(Module* module) {
CHECK_RESULT(VisitTag(module->tags[i]));
for (size_t i = 0; i < module->exports.size(); ++i)
CHECK_RESULT(VisitExport(i, module->exports[i]));
for (size_t i = 0; i < module->tables.size(); ++i)
CHECK_RESULT(VisitTable(module->tables[i]));
for (size_t i = 0; i < module->elem_segments.size(); ++i)
CHECK_RESULT(VisitElemSegment(i, module->elem_segments[i]));
for (size_t i = 0; i < module->data_segments.size(); ++i)
Expand Down
26 changes: 20 additions & 6 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnFunction(Index index, Index sig_index) override;

Result OnTableCount(Index count) override;
Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) override;
Result BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) override;
Result BeginTableInitExpr(Index index) override;
Result EndTableInitExpr(Index index) override;

Result OnMemoryCount(Index count) override;
Result OnMemory(Index index,
Expand Down Expand Up @@ -700,9 +703,10 @@ Result BinaryReaderIR::OnTableCount(Index count) {
return Result::Ok;
}

Result BinaryReaderIR::OnTable(Index index,
Type elem_type,
const Limits* elem_limits) {
Result BinaryReaderIR::BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus) {
auto field = std::make_unique<TableModuleField>(GetLocation());
Table& table = field->table;
table.elem_limits = *elem_limits;
Expand All @@ -712,6 +716,16 @@ Result BinaryReaderIR::OnTable(Index index,
return Result::Ok;
}

Result BinaryReaderIR::BeginTableInitExpr(Index index) {
assert(index == module_->tables.size() - 1);
Table* table = module_->tables[index];
return BeginInitExpr(&table->init_expr);
}

Result BinaryReaderIR::EndTableInitExpr(Index index) {
return EndInitExpr();
}

Result BinaryReaderIR::OnMemoryCount(Index count) {
WABT_TRY
module_->memories.reserve(module_->num_memory_imports + count);
Expand Down
12 changes: 8 additions & 4 deletions src/binary-reader-logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,15 @@ Result BinaryReaderLogging::OnImportTag(Index import_index,
sig_index);
}

Result BinaryReaderLogging::OnTable(Index index,
Type elem_type,
const Limits* elem_limits) {
Result BinaryReaderLogging::BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) {
char buf[100];
SPrintLimits(buf, sizeof(buf), elem_limits);
LOGF("OnTable(index: %" PRIindex ", elem_type: %s, %s)\n", index,
elem_type.GetName().c_str(), buf);
return reader_->OnTable(index, elem_type, elem_limits);
return reader_->BeginTable(index, elem_type, elem_limits, init_provided);
}

Result BinaryReaderLogging::OnMemory(Index index,
Expand Down Expand Up @@ -816,6 +817,9 @@ DEFINE_END(EndFunctionSection)

DEFINE_BEGIN(BeginTableSection)
DEFINE_INDEX(OnTableCount)
DEFINE_INDEX(BeginTableInitExpr)
DEFINE_INDEX(EndTableInitExpr)
DEFINE_INDEX(EndTable)
DEFINE_END(EndTableSection)

DEFINE_BEGIN(BeginMemorySection)
Expand Down
31 changes: 23 additions & 8 deletions src/binary-reader-objdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,10 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnFunction(Index index, Index sig_index) override;

Result OnTableCount(Index count) override;
Result OnTable(Index index,
Type elem_type,
const Limits* elem_limits) override;
Result BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus init_provided) override;

Result OnMemoryCount(Index count) override;
Result OnMemory(Index index,
Expand Down Expand Up @@ -1176,6 +1177,14 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {

Result EndDataSegmentInitExpr(Index index) override { return EndInitExpr(); }

Result BeginTableInitExpr(Index index) override {
reading_table_init_expr_ = true;
BeginInitExpr();
return Result::Ok;
}

Result EndTableInitExpr(Index index) override { return EndInitExpr(); }

Result BeginGlobalInitExpr(Index index) override {
reading_global_init_expr_ = true;
BeginInitExpr();
Expand Down Expand Up @@ -1305,6 +1314,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Index elem_index_ = 0;
Index table_index_ = 0;
Index next_data_reloc_ = 0;
bool reading_table_init_expr_ = false;
bool reading_elem_init_expr_ = false;
bool reading_data_init_expr_ = false;
bool reading_global_init_expr_ = false;
Expand All @@ -1317,8 +1327,9 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
uint64_t elem_offset_ = 0;

bool ReadingInitExpr() {
return reading_elem_init_expr_ || reading_data_init_expr_ ||
reading_global_init_expr_ || reading_elem_expr_;
return reading_table_init_expr_ || reading_elem_init_expr_ ||
reading_data_init_expr_ || reading_global_init_expr_ ||
reading_elem_expr_;
}
};

Expand Down Expand Up @@ -1697,9 +1708,10 @@ Result BinaryReaderObjdump::OnTableCount(Index count) {
return OnCount(count);
}

Result BinaryReaderObjdump::OnTable(Index index,
Type elem_type,
const Limits* elem_limits) {
Result BinaryReaderObjdump::BeginTable(Index index,
Type elem_type,
const Limits* elem_limits,
TableInitExprStatus) {
PrintDetails(" - table[%" PRIindex "] type=%s initial=%" PRId64, index,
elem_type.GetName().c_str(), elem_limits->initial);
if (elem_limits->has_max) {
Expand Down Expand Up @@ -1922,6 +1934,9 @@ Result BinaryReaderObjdump::EndInitExpr() {
if (reading_data_init_expr_) {
reading_data_init_expr_ = false;
InitExprToConstOffset(current_init_expr_, &data_offset_);
} else if (reading_table_init_expr_) {
reading_table_init_expr_ = false;
InitExprToConstOffset(current_init_expr_, &elem_offset_);
} else if (reading_elem_init_expr_) {
reading_elem_init_expr_ = false;
InitExprToConstOffset(current_init_expr_, &elem_offset_);
Expand Down
Loading
Loading