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
4 changes: 4 additions & 0 deletions include/wabt/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ 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;
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
4 changes: 4 additions & 0 deletions 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 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
4 changes: 4 additions & 0 deletions include/wabt/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ 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;
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
15 changes: 15 additions & 0 deletions include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ enum class ExprType {
Block,
Br,
BrIf,
BrOnNonNull,
BrOnNull,
BrTable,
Call,
CallIndirect,
Expand All @@ -418,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 @@ -588,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 @@ -667,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 Down Expand Up @@ -758,6 +765,14 @@ class CallRefExpr : public ExprMixin<ExprType::CallRef> {
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>
class BlockExprBase : public ExprMixin<TypeEnum> {
public:
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
4 changes: 4 additions & 0 deletions include/wabt/shared-validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class SharedValidator {
Result OnBlock(const Location&, Type sig_type);
Result OnBr(const Location&, Var depth);
Result OnBrIf(const Location&, Var depth);
Result OnBrOnNonNull(const Location&, Var depth);
Result OnBrOnNull(const Location&, Var depth);
Result BeginBrTable(const Location&);
Result OnBrTableTarget(const Location&, Var depth);
Result EndBrTable(const Location&);
Expand Down Expand Up @@ -176,12 +178,14 @@ class SharedValidator {
Result OnMemoryInit(const Location&, Var segment_var, Var memidx);
Result OnMemorySize(const Location&, Var memidx);
Result OnNop(const Location&);
Result OnRefAsNonNull(const Location&);
Result OnRefFunc(const Location&, Var func_var);
Result OnRefIsNull(const Location&);
Result OnRefNull(const Location&, Var func_type_var);
Result OnRethrow(const Location&, Var depth);
Result OnReturnCall(const Location&, Var func_var);
Result OnReturnCallIndirect(const Location&, Var sig_var, Var table_var);
Result OnReturnCallRef(const Location&, Var function_type_var);
Result OnReturn(const Location&);
Result OnSelect(const Location&, Index result_count, Type* result_types);
Result OnSimdLaneOp(const Location&, Opcode, uint64_t lane_idx);
Expand Down
4 changes: 4 additions & 0 deletions include/wabt/token.def
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ WABT_TOKEN(Binary, "BINARY")
WABT_TOKEN(Block, "block")
WABT_TOKEN(Br, "br")
WABT_TOKEN(BrIf, "br_if")
WABT_TOKEN(BrOnNonNull, "br_on_non_null")
WABT_TOKEN(BrOnNull, "br_on_null")
WABT_TOKEN(BrTable, "br_table")
WABT_TOKEN(Code, "code")
WABT_TOKEN(Call, "call")
WABT_TOKEN(CallIndirect, "call_indirect")
WABT_TOKEN(CallRef, "call_ref")
WABT_TOKEN(ReturnCallRef, "return_call_ref")
WABT_TOKEN(Catch, "catch")
WABT_TOKEN(CatchAll, "catch_all")
WABT_TOKEN(CatchRef, "catch_ref")
Expand All @@ -130,6 +133,7 @@ WABT_TOKEN(MemoryGrow, "memory.grow")
WABT_TOKEN(MemoryInit, "memory.init")
WABT_TOKEN(MemorySize, "memory.size")
WABT_TOKEN(Nop, "nop")
WABT_TOKEN(RefAsNonNull, "ref.as_non_null")
WABT_TOKEN(RefExtern, "ref.extern")
WABT_TOKEN(RefFunc, "ref.func")
WABT_TOKEN(RefIsNull, "ref.is_null")
Expand Down
5 changes: 5 additions & 0 deletions include/wabt/type-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class TypeChecker {
Result OnBlock(const TypeVector& param_types, const TypeVector& result_types);
Result OnBr(Index depth);
Result OnBrIf(Index depth);
Result OnBrOnNonNull(Index depth);
Result OnBrOnNull(Index depth);
Result BeginBrTable();
Result OnBrTableTarget(Index depth);
Result EndBrTable();
Expand All @@ -100,6 +102,7 @@ class TypeChecker {
const TypeVector& result_types);
Result OnReturnCallIndirect(const TypeVector& param_types,
const TypeVector& result_types);
Result OnReturnCallRef(Type);
Result OnCatch(const TypeVector& sig);
Result OnCompare(Opcode);
Result OnConst(Type);
Expand Down Expand Up @@ -131,6 +134,7 @@ class TypeChecker {
Result OnTableSize(const Limits& limits);
Result OnTableFill(Type elem_type, const Limits& limits);
Result OnRefFuncExpr(Index func_type);
Result OnRefAsNonNullExpr();
Result OnRefNullExpr(Type type);
Result OnRefIsNullExpr();
Result OnRethrow(Index depth);
Expand Down Expand Up @@ -193,6 +197,7 @@ class TypeChecker {
Type expected2,
Type expected3,
const char* desc);
Result PopAndCheckReference(Type* actual, const char* desc);
Result CheckOpcode1(Opcode opcode, const Limits* limits = nullptr);
Result CheckOpcode2(Opcode opcode, const Limits* limits = nullptr);
Result CheckOpcode3(Opcode opcode,
Expand Down
14 changes: 14 additions & 0 deletions src/apply-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class NameApplier : public ExprVisitor::DelegateNop {
Result EndBlockExpr(BlockExpr*) override;
Result OnBrExpr(BrExpr*) override;
Result OnBrIfExpr(BrIfExpr*) override;
Result OnBrOnNonNullExpr(BrOnNonNullExpr*) override;
Result OnBrOnNullExpr(BrOnNullExpr*) override;
Result OnBrTableExpr(BrTableExpr*) override;
Result OnCallExpr(CallExpr*) override;
Result OnRefFuncExpr(RefFuncExpr*) override;
Expand Down Expand Up @@ -350,6 +352,18 @@ Result NameApplier::OnBrIfExpr(BrIfExpr* expr) {
return Result::Ok;
}

Result NameApplier::OnBrOnNonNullExpr(BrOnNonNullExpr* expr) {
std::string_view label = FindLabelByVar(&expr->var);
UseNameForVar(label, &expr->var);
return Result::Ok;
}

Result NameApplier::OnBrOnNullExpr(BrOnNullExpr* expr) {
std::string_view label = FindLabelByVar(&expr->var);
UseNameForVar(label, &expr->var);
return Result::Ok;
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR but this seems to be a repeated pattern here.. i wonder if we could refactor/tempetize/macro somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I will do it.

}

Result NameApplier::OnBrTableExpr(BrTableExpr* expr) {
for (Var& target : expr->targets) {
std::string_view label = FindLabelByVar(&target);
Expand Down
24 changes: 24 additions & 0 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class BinaryReaderIR : public BinaryReaderNop {
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;
Expand All @@ -210,6 +212,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnCallRefExpr(Type sig_type) override;
Result OnReturnCallExpr(Index func_index) override;
Result OnReturnCallIndirectExpr(Index sig_index, Index table_index) override;
Result OnReturnCallRefExpr(Type sig_type) override;
Result OnCompareExpr(Opcode opcode) override;
Result OnConvertExpr(Opcode opcode) override;
Result OnDelegateExpr(Index depth) override;
Expand Down Expand Up @@ -246,6 +249,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnTableGrowExpr(Index table_index) override;
Result OnTableSizeExpr(Index table_index) override;
Result OnTableFillExpr(Index table_index) override;
Result OnRefAsNonNullExpr() override;
Result OnRefFuncExpr(Index func_index) override;
Result OnRefNullExpr(Type type) override;
Result OnRefIsNullExpr() override;
Expand Down Expand Up @@ -897,6 +901,15 @@ Result BinaryReaderIR::OnBrIfExpr(Index depth) {
return AppendExpr(std::make_unique<BrIfExpr>(Var(depth, GetLocation())));
}

Result BinaryReaderIR::OnBrOnNonNullExpr(Index depth) {
return AppendExpr(
std::make_unique<BrOnNonNullExpr>(Var(depth, GetLocation())));
}

Result BinaryReaderIR::OnBrOnNullExpr(Index depth) {
return AppendExpr(std::make_unique<BrOnNullExpr>(Var(depth, GetLocation())));
}

Result BinaryReaderIR::OnBrTableExpr(Index num_targets,
Index* target_depths,
Index default_target_depth) {
Expand Down Expand Up @@ -953,6 +966,12 @@ Result BinaryReaderIR::OnReturnCallIndirectExpr(Index sig_index,
return AppendExpr(std::move(expr));
}

Result BinaryReaderIR::OnReturnCallRefExpr(Type sig_type) {
auto expr = std::make_unique<ReturnCallRefExpr>();
expr->sig_type = Var(sig_type, GetLocation());
return AppendExpr(std::move(expr));
}

Result BinaryReaderIR::OnCompareExpr(Opcode opcode) {
return AppendExpr(std::make_unique<CompareExpr>(opcode));
}
Expand Down Expand Up @@ -1147,6 +1166,11 @@ Result BinaryReaderIR::OnTableFillExpr(Index table_index) {
std::make_unique<TableFillExpr>(Var(table_index, GetLocation())));
}

Result BinaryReaderIR::OnRefAsNonNullExpr() {
return AppendExpr(
std::make_unique<RefAsNonNullExpr>(Opcode::RefAsNonNull, GetLocation()));
}

Result BinaryReaderIR::OnRefFuncExpr(Index func_index) {
module_->used_func_refs.insert(func_index);
return AppendExpr(
Expand Down
Loading
Loading