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
10 changes: 10 additions & 0 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ struct NullInstrParserCtx {
Result<> makeRefEq(Index) { return Ok{}; }
Result<> makeRefI31(Index) { return Ok{}; }
Result<> makeI31Get(Index, bool) { return Ok{}; }
template<typename TypeT> Result<> makeRefTest(Index, TypeT) { return Ok{}; }
template<typename TypeT> Result<> makeRefCast(Index, TypeT) { return Ok{}; }

template<typename HeapTypeT> Result<> makeStructNew(Index, HeapTypeT) {
return Ok{};
Expand Down Expand Up @@ -1280,6 +1282,14 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
return withLoc(pos, irBuilder.makeI31Get(signed_));
}

Result<> makeRefTest(Index pos, Type type) {
return withLoc(pos, irBuilder.makeRefTest(type));
}

Result<> makeRefCast(Index pos, Type type) {
return withLoc(pos, irBuilder.makeRefCast(type));
}

Result<> makeStructNew(Index pos, HeapType type) {
return withLoc(pos, irBuilder.makeStructNew(type));
}
Expand Down
8 changes: 6 additions & 2 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,15 @@ template<typename Ctx> Result<> makeI31Get(Ctx& ctx, Index pos, bool signed_) {
}

template<typename Ctx> Result<> makeRefTest(Ctx& ctx, Index pos) {
return ctx.in.err("unimplemented instruction");
auto type = reftype(ctx);
CHECK_ERR(type);
return ctx.makeRefTest(pos, *type);
}

template<typename Ctx> Result<> makeRefCast(Ctx& ctx, Index pos) {
return ctx.in.err("unimplemented instruction");
auto type = reftype(ctx);
CHECK_ERR(type);
return ctx.makeRefCast(pos, *type);
}

template<typename Ctx> Result<> makeBrOnNull(Ctx& ctx, Index pos, bool onFail) {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
[[nodiscard]] Result<> makeRefI31();
[[nodiscard]] Result<> makeI31Get(bool signed_);
// [[nodiscard]] Result<> makeCallRef();
// [[nodiscard]] Result<> makeRefTest();
// [[nodiscard]] Result<> makeRefCast();
[[nodiscard]] Result<> makeRefTest(Type type);
[[nodiscard]] Result<> makeRefCast(Type type);
// [[nodiscard]] Result<> makeBrOn();
[[nodiscard]] Result<> makeStructNew(HeapType type);
[[nodiscard]] Result<> makeStructNewDefault(HeapType type);
Expand Down
2 changes: 2 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ class CallRef : public SpecificExpression<Expression::CallRefId> {

class RefTest : public SpecificExpression<Expression::RefTestId> {
public:
RefTest() = default;
RefTest(MixedArena& allocator) {}

Expression* ref;
Expand All @@ -1553,6 +1554,7 @@ class RefTest : public SpecificExpression<Expression::RefTestId> {

class RefCast : public SpecificExpression<Expression::RefCastId> {
public:
RefCast() = default;
RefCast(MixedArena& allocator) {}

Expression* ref;
Expand Down
14 changes: 12 additions & 2 deletions src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,19 @@ Result<> IRBuilder::makeI31Get(bool signed_) {

// Result<> IRBuilder::makeCallRef() {}

// Result<> IRBuilder::makeRefTest() {}
Result<> IRBuilder::makeRefTest(Type type) {
RefTest curr;
CHECK_ERR(visitRefTest(&curr));
push(builder.makeRefTest(curr.ref, type));
return Ok{};
}

// Result<> IRBuilder::makeRefCast() {}
Result<> IRBuilder::makeRefCast(Type type) {
RefCast curr;
CHECK_ERR(visitRefCast(&curr));
push(builder.makeRefCast(curr.ref, type));
return Ok{};
}

// Result<> IRBuilder::makeBrOn() {}

Expand Down
Loading