Skip to content
Open
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
6 changes: 5 additions & 1 deletion include/wabt/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnBlockExpr(Type sig_type) override;
Result OnBrExpr(Index depth) override;
Result OnBrIfExpr(Index depth) override;
Result OnBrOnNonNullExpr(Index depth) override;
Result OnBrOnNullExpr(Index depth) override;
Result OnBrTableExpr(Index num_targets,
Index* target_depths,
Index default_target_depth) override;
Result OnCallExpr(Index func_index) override;
Result OnCatchExpr(Index tag_index) override;
Result OnCatchAllExpr() override;
Result OnCallIndirectExpr(Index sig_index, Index table_index) override;
Result OnCallRefExpr() override;
Result OnCallRefExpr(Type sig_type) override;
Result OnCompareExpr(Opcode opcode) override;
Result OnConvertExpr(Opcode opcode) override;
Result OnDelegateExpr(Index depth) override;
Expand Down Expand Up @@ -218,12 +220,14 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnTableGrowExpr(Index table) override;
Result OnTableSizeExpr(Index table) override;
Result OnTableFillExpr(Index table) override;
Result OnRefAsNonNullExpr() override;
Result OnRefFuncExpr(Index index) override;
Result OnRefNullExpr(Type type) override;
Result OnRefIsNullExpr() override;
Result OnNopExpr() override;
Result OnRethrowExpr(Index depth) override;
Result OnReturnCallExpr(Index func_index) override;
Result OnReturnCallRefExpr(Type sig_type) override;
Result OnReturnCallIndirectExpr(Index sig_index, Index table_index) override;
Result OnReturnExpr() override;
Result OnSelectExpr(Index result_count, Type* result_types) override;
Expand Down
6 changes: 5 additions & 1 deletion include/wabt/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnBlockExpr(Type sig_type) override { return Result::Ok; }
Result OnBrExpr(Index depth) override { return Result::Ok; }
Result OnBrIfExpr(Index depth) override { return Result::Ok; }
Result OnBrOnNonNullExpr(Index depth) override { return Result::Ok; }
Result OnBrOnNullExpr(Index depth) override { return Result::Ok; }
Result OnBrTableExpr(Index num_targets,
Index* target_depths,
Index default_target_depth) override {
Expand All @@ -250,7 +252,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnCallIndirectExpr(Index sig_index, Index table_index) override {
return Result::Ok;
}
Result OnCallRefExpr() override { return Result::Ok; }
Result OnCallRefExpr(Type sig_type) override { return Result::Ok; }
Result OnCatchExpr(Index tag_index) override { return Result::Ok; }
Result OnCatchAllExpr() override { return Result::Ok; }
Result OnCompareExpr(Opcode opcode) override { return Result::Ok; }
Expand Down Expand Up @@ -299,6 +301,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnTableGrowExpr(Index table_index) override { return Result::Ok; }
Result OnTableSizeExpr(Index table_index) override { return Result::Ok; }
Result OnTableFillExpr(Index table_index) override { return Result::Ok; }
Result OnRefAsNonNullExpr() override { return Result::Ok; }
Result OnRefFuncExpr(Index func_index) override { return Result::Ok; }
Result OnRefNullExpr(Type type) override { return Result::Ok; }
Result OnRefIsNullExpr() override { return Result::Ok; }
Expand All @@ -308,6 +311,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnReturnCallIndirectExpr(Index sig_index, Index table_index) override {
return Result::Ok;
}
Result OnReturnCallRefExpr(Type sig_type) override { return Result::Ok; }
Result OnReturnExpr() override { return Result::Ok; }
Result OnSelectExpr(Index result_count, Type* result_types) override {
return Result::Ok;
Expand Down
6 changes: 5 additions & 1 deletion include/wabt/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ class BinaryReaderDelegate {
virtual Result OnBlockExpr(Type sig_type) = 0;
virtual Result OnBrExpr(Index depth) = 0;
virtual Result OnBrIfExpr(Index depth) = 0;
virtual Result OnBrOnNonNullExpr(Index depth) = 0;
virtual Result OnBrOnNullExpr(Index depth) = 0;
virtual Result OnBrTableExpr(Index num_targets,
Index* target_depths,
Index default_target_depth) = 0;
virtual Result OnCallExpr(Index func_index) = 0;
virtual Result OnCallIndirectExpr(Index sig_index, Index table_index) = 0;
virtual Result OnCallRefExpr() = 0;
virtual Result OnCallRefExpr(Type sig_type) = 0;
virtual Result OnCatchExpr(Index tag_index) = 0;
virtual Result OnCatchAllExpr() = 0;
virtual Result OnCompareExpr(Opcode opcode) = 0;
Expand Down Expand Up @@ -294,6 +296,7 @@ class BinaryReaderDelegate {
virtual Result OnTableGrowExpr(Index table_index) = 0;
virtual Result OnTableSizeExpr(Index table_index) = 0;
virtual Result OnTableFillExpr(Index table_index) = 0;
virtual Result OnRefAsNonNullExpr() = 0;
virtual Result OnRefFuncExpr(Index func_index) = 0;
virtual Result OnRefNullExpr(Type type) = 0;
virtual Result OnRefIsNullExpr() = 0;
Expand All @@ -303,6 +306,7 @@ class BinaryReaderDelegate {
virtual Result OnReturnCallExpr(Index func_index) = 0;
virtual Result OnReturnCallIndirectExpr(Index sig_index,
Index table_index) = 0;
virtual Result OnReturnCallRefExpr(Type sig_type) = 0;
virtual Result OnSelectExpr(Index result_count, Type* result_types) = 0;
virtual Result OnStoreExpr(Opcode opcode,
Index memidx,
Expand Down
8 changes: 8 additions & 0 deletions include/wabt/expr-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class ExprVisitor::Delegate {
virtual Result EndBlockExpr(BlockExpr*) = 0;
virtual Result OnBrExpr(BrExpr*) = 0;
virtual Result OnBrIfExpr(BrIfExpr*) = 0;
virtual Result OnBrOnNonNullExpr(BrOnNonNullExpr*) = 0;
virtual Result OnBrOnNullExpr(BrOnNullExpr*) = 0;
virtual Result OnBrTableExpr(BrTableExpr*) = 0;
virtual Result BeginTryTableExpr(TryTableExpr*) = 0;
virtual Result EndTryTableExpr(TryTableExpr*) = 0;
Expand Down Expand Up @@ -109,13 +111,15 @@ class ExprVisitor::Delegate {
virtual Result OnTableGrowExpr(TableGrowExpr*) = 0;
virtual Result OnTableSizeExpr(TableSizeExpr*) = 0;
virtual Result OnTableFillExpr(TableFillExpr*) = 0;
virtual Result OnRefAsNonNullExpr(RefAsNonNullExpr*) = 0;
virtual Result OnRefFuncExpr(RefFuncExpr*) = 0;
virtual Result OnRefNullExpr(RefNullExpr*) = 0;
virtual Result OnRefIsNullExpr(RefIsNullExpr*) = 0;
virtual Result OnNopExpr(NopExpr*) = 0;
virtual Result OnReturnExpr(ReturnExpr*) = 0;
virtual Result OnReturnCallExpr(ReturnCallExpr*) = 0;
virtual Result OnReturnCallIndirectExpr(ReturnCallIndirectExpr*) = 0;
virtual Result OnReturnCallRefExpr(ReturnCallRefExpr*) = 0;
virtual Result OnSelectExpr(SelectExpr*) = 0;
virtual Result OnStoreExpr(StoreExpr*) = 0;
virtual Result OnUnaryExpr(UnaryExpr*) = 0;
Expand Down Expand Up @@ -150,6 +154,8 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result EndBlockExpr(BlockExpr*) override { return Result::Ok; }
Result OnBrExpr(BrExpr*) override { return Result::Ok; }
Result OnBrIfExpr(BrIfExpr*) override { return Result::Ok; }
Result OnBrOnNonNullExpr(BrOnNonNullExpr*) override { return Result::Ok; };
Result OnBrOnNullExpr(BrOnNullExpr*) override { return Result::Ok; };
Result OnBrTableExpr(BrTableExpr*) override { return Result::Ok; }
Result BeginTryTableExpr(TryTableExpr*) override { return Result::Ok; }
Result EndTryTableExpr(TryTableExpr*) override { return Result::Ok; }
Expand Down Expand Up @@ -186,6 +192,7 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result OnTableGrowExpr(TableGrowExpr*) override { return Result::Ok; }
Result OnTableSizeExpr(TableSizeExpr*) override { return Result::Ok; }
Result OnTableFillExpr(TableFillExpr*) override { return Result::Ok; }
Result OnRefAsNonNullExpr(RefAsNonNullExpr*) override { return Result::Ok; }
Result OnRefFuncExpr(RefFuncExpr*) override { return Result::Ok; }
Result OnRefNullExpr(RefNullExpr*) override { return Result::Ok; }
Result OnRefIsNullExpr(RefIsNullExpr*) override { return Result::Ok; }
Expand All @@ -195,6 +202,7 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result OnReturnCallIndirectExpr(ReturnCallIndirectExpr*) override {
return Result::Ok;
}
Result OnReturnCallRefExpr(ReturnCallRefExpr*) override { return Result::Ok; }
Result OnSelectExpr(SelectExpr*) override { return Result::Ok; }
Result OnStoreExpr(StoreExpr*) override { return Result::Ok; }
Result OnUnaryExpr(UnaryExpr*) override { return Result::Ok; }
Expand Down
2 changes: 1 addition & 1 deletion include/wabt/interp/interp-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline bool FuncType::classof(const ExternType* type) {
}

inline FuncType::FuncType(ValueTypes params, ValueTypes results)
: ExternType(ExternKind::Func), params(params), results(results) {}
: ExternType(ExternKind::Func), params(params), results(results), func_types(nullptr) {}

//// TableType ////
// static
Expand Down
4 changes: 4 additions & 0 deletions include/wabt/interp/interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ struct FuncType : ExternType {

ValueTypes params;
ValueTypes results;
// When params or results contain references, the referenced
// types are also needed for type equality comparisons.
// An example for these comparisons is import validation.
std::vector<FuncType>* func_types;
};

struct TableType : ExternType {
Expand Down
59 changes: 50 additions & 9 deletions include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,43 @@ namespace wabt {

struct Module;

enum class VarType {
// VarType (16 bit) and the opt_type_ (16 bit)
// fields of Var forms a 32 bit field.
enum class VarType : uint16_t {
Index,
Name,
};

struct Var {
// Var can represent variables or types.

// Represent a variable:
// has_opt_type() is false
// Only used by wast-parser

// Represent a type:
// has_opt_type() is true, is_index() is true
// type can be get by to_type()
// Binary reader only constructs this variant

// Represent both a variable and a type:
// has_opt_type() is true, is_name() is true
// A reference, which index is unknown
// Only used by wast-parser

explicit Var();
explicit Var(Index index, const Location& loc);
explicit Var(std::string_view name, const Location& loc);
explicit Var(Type type, const Location& loc);
Var(Var&&);
Var(const Var&);
Var& operator=(const Var&);
Var& operator=(Var&&);
~Var();

VarType type() const { return type_; }
bool is_index() const { return type_ == VarType::Index; }
bool is_name() const { return type_ == VarType::Name; }
bool has_opt_type() const { return opt_type_ < 0; }

Index index() const {
assert(is_index());
Expand All @@ -63,17 +82,25 @@ struct Var {
assert(is_name());
return name_;
}
Type::Enum opt_type() const {
assert(has_opt_type());
return static_cast<Type::Enum>(opt_type_);
}

void set_index(Index);
void set_name(std::string&&);
void set_name(std::string_view);
void set_opt_type(Type::Enum);
Type to_type() const;

Location loc;

private:
void Destroy();

VarType type_;
// Can be set to Type::Enum types, Type::Any represent no optional type.
int16_t opt_type_;
union {
Index index_;
std::string name_;
Expand Down Expand Up @@ -155,6 +182,7 @@ struct Const {
}
void set_funcref() { From<uintptr_t>(Type::FuncRef, 0); }
void set_externref(uintptr_t x) { From(Type::ExternRef, x); }
void set_extern(uintptr_t x) { From(Type(Type::ExternRef, Type::ReferenceNonNull), x); }
void set_null(Type type) { From<uintptr_t>(type, kRefNullBits); }

bool is_expected_nan(int lane = 0) const {
Expand Down Expand Up @@ -366,6 +394,8 @@ enum class ExprType {
Block,
Br,
BrIf,
BrOnNonNull,
BrOnNull,
BrTable,
Call,
CallIndirect,
Expand All @@ -390,13 +420,15 @@ enum class ExprType {
MemoryInit,
MemorySize,
Nop,
RefAsNonNull,
RefIsNull,
RefFunc,
RefNull,
Rethrow,
Return,
ReturnCall,
ReturnCallIndirect,
ReturnCallRef,
Select,
SimdLaneOp,
SimdLoadLane,
Expand Down Expand Up @@ -537,10 +569,10 @@ using MemoryCopyExpr = MemoryBinaryExpr<ExprType::MemoryCopy>;
template <ExprType TypeEnum>
class RefTypeExpr : public ExprMixin<TypeEnum> {
public:
RefTypeExpr(Type type, const Location& loc = Location())
RefTypeExpr(Var type, const Location& loc = Location())
: ExprMixin<TypeEnum>(loc), type(type) {}

Type type;
Var type;
};

using RefNullExpr = RefTypeExpr<ExprType::RefNull>;
Expand All @@ -560,6 +592,7 @@ using CompareExpr = OpcodeExpr<ExprType::Compare>;
using ConvertExpr = OpcodeExpr<ExprType::Convert>;
using UnaryExpr = OpcodeExpr<ExprType::Unary>;
using TernaryExpr = OpcodeExpr<ExprType::Ternary>;
using RefAsNonNullExpr = OpcodeExpr<ExprType::RefAsNonNull>;

class SimdLaneOpExpr : public ExprMixin<ExprType::SimdLaneOp> {
public:
Expand Down Expand Up @@ -639,6 +672,8 @@ class MemoryVarExpr : public MemoryExpr<TypeEnum> {

using BrExpr = VarExpr<ExprType::Br>;
using BrIfExpr = VarExpr<ExprType::BrIf>;
using BrOnNonNullExpr = VarExpr<ExprType::BrOnNonNull>;
using BrOnNullExpr = VarExpr<ExprType::BrOnNull>;
using CallExpr = VarExpr<ExprType::Call>;
using RefFuncExpr = VarExpr<ExprType::RefFunc>;
using GlobalGetExpr = VarExpr<ExprType::GlobalGet>;
Expand All @@ -662,8 +697,8 @@ using MemoryInitExpr = MemoryVarExpr<ExprType::MemoryInit>;

class SelectExpr : public ExprMixin<ExprType::Select> {
public:
SelectExpr(TypeVector type, const Location& loc = Location())
: ExprMixin<ExprType::Select>(loc), result_type(type) {}
SelectExpr(const Location& loc = Location())
: ExprMixin<ExprType::Select>(loc) {}
TypeVector result_type;
};

Expand Down Expand Up @@ -727,9 +762,15 @@ class CallRefExpr : public ExprMixin<ExprType::CallRef> {
explicit CallRefExpr(const Location& loc = Location())
: ExprMixin<ExprType::CallRef>(loc) {}

// This field is setup only during Validate phase,
// so keep that in mind when you use it.
Var function_type_index;
Var sig_type;
};

class ReturnCallRefExpr : public ExprMixin<ExprType::ReturnCallRef> {
public:
explicit ReturnCallRefExpr(const Location& loc = Location())
: ExprMixin<ExprType::ReturnCallRef>(loc) {}

Var sig_type;
};

template <ExprType TypeEnum>
Expand Down
4 changes: 4 additions & 0 deletions include/wabt/opcode.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x11, CallIndirect, "call_indirect
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x12, ReturnCall, "return_call", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x13, ReturnCallIndirect, "return_call_indirect", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x14, CallRef, "call_ref", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x15, ReturnCallRef, "return_call_ref", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x18, Delegate, "delegate", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x19, CatchAll, "catch_all", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x1a, Drop, "drop", "")
Expand Down Expand Up @@ -267,6 +268,9 @@ WABT_OPCODE(___, I32, ___, I32, 0, 0xfc, 0x11, TableFill, "table.fill", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd0, RefNull, "ref.null", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd1, RefIsNull, "ref.is_null", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd2, RefFunc, "ref.func", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd4, RefAsNonNull, "ref.as_non_null", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd5, BrOnNull, "br_on_null", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0xd6, BrOnNonNull, "br_on_non_null", "")

/* Simd opcodes */
WABT_OPCODE(V128, I32, ___, ___, 16, 0xfd, 0x00, V128Load, "v128.load", "")
Expand Down
Loading
Loading