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
5 changes: 5 additions & 0 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ struct NullInstrParserCtx {
template<typename HeapTypeT> Result<> makeArrayFill(Index, HeapTypeT) {
return Ok{};
}
Result<> makeRefAs(Index, RefAsOp) { return Ok{}; }
};

// Phase 1: Parse definition spans for top-level module elements and determine
Expand Down Expand Up @@ -1352,6 +1353,10 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
Result<> makeArrayFill(Index pos, HeapType type) {
return withLoc(pos, irBuilder.makeArrayFill(type));
}

Result<> makeRefAs(Index pos, RefAsOp op) {
return withLoc(pos, irBuilder.makeRefAs(op));
}
};

} // namespace wasm::WATParser
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ template<typename Ctx> Result<> makeArrayInitElem(Ctx& ctx, Index pos) {
}

template<typename Ctx> Result<> makeRefAs(Ctx& ctx, Index pos, RefAsOp op) {
return ctx.in.err("unimplemented instruction");
return ctx.makeRefAs(pos, op);
}

template<typename Ctx>
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
[[nodiscard]] Result<> makeArrayFill(HeapType type);
// [[nodiscard]] Result<> makeArrayInitData();
// [[nodiscard]] Result<> makeArrayInitElem();
// [[nodiscard]] Result<> makeRefAs();
[[nodiscard]] Result<> makeRefAs(RefAsOp op);
// [[nodiscard]] Result<> makeStringNew();
// [[nodiscard]] Result<> makeStringConst();
// [[nodiscard]] Result<> makeStringMeasure();
Expand Down
1 change: 1 addition & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ class ArrayInitElem : public SpecificExpression<Expression::ArrayInitElemId> {

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

RefAsOp op;
Expand Down
7 changes: 6 additions & 1 deletion src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,12 @@ Result<> IRBuilder::makeArrayFill(HeapType type) {

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

// Result<> IRBuilder::makeRefAs() {}
Result<> IRBuilder::makeRefAs(RefAsOp op) {
RefAs curr;
CHECK_ERR(visitRefAs(&curr));
push(builder.makeRefAs(op, curr.value));
return Ok{};
}

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

Expand Down
45 changes: 43 additions & 2 deletions test/lit/wat-kitchen-sink.wast
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

;; CHECK: (type $49 (func (param (ref $a2) i32 f32 i32)))

;; CHECK: (type $50 (func (param externref)))

;; CHECK: (type $s2 (struct (field i32)))
(type $s2 (struct i32))
;; CHECK: (type $s3 (struct (field i64)))
Expand Down Expand Up @@ -160,7 +162,7 @@
(global (import "mod" "") (ref null $many))

(global (mut i32) i32.const 0)
;; CHECK: (type $61 (func (param (ref $s0) (ref $s1) (ref $s2) (ref $s3) (ref $s4) (ref $s5) (ref $s6) (ref $s7) (ref $s8) (ref $a0) (ref $a1) (ref $a2) (ref $a3) (ref $subvoid) (ref $submany))))
;; CHECK: (type $62 (func (param (ref $s0) (ref $s1) (ref $s2) (ref $s3) (ref $s4) (ref $s5) (ref $s6) (ref $s7) (ref $s8) (ref $a0) (ref $a1) (ref $a2) (ref $a3) (ref $subvoid) (ref $submany))))

;; CHECK: (import "" "mem" (memory $mimport$1 0))

Expand Down Expand Up @@ -2693,6 +2695,45 @@
array.fill $a2
)

;; CHECK: (func $ref-as-non-null (type $8) (param $0 anyref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $ref-as-non-null (param anyref)
local.get 0
ref.as_non_null
drop
)

;; CHECK: (func $any-convert-extern (type $50) (param $0 externref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (extern.internalize
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $any-convert-extern (param externref)
local.get 0
extern.internalize
drop
)

;; CHECK: (func $extern-convert-any (type $8) (param $0 anyref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (extern.externalize
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $extern-convert-any (param anyref)
local.get 0
extern.externalize
drop
)

;; CHECK: (func $call (type $16) (param $0 i32) (param $1 i64) (result f32)
;; CHECK-NEXT: (call $call
;; CHECK-NEXT: (local.get $0)
Expand All @@ -2717,7 +2758,7 @@
return_call $return_call
)

;; CHECK: (func $use-types (type $61) (param $0 (ref $s0)) (param $1 (ref $s1)) (param $2 (ref $s2)) (param $3 (ref $s3)) (param $4 (ref $s4)) (param $5 (ref $s5)) (param $6 (ref $s6)) (param $7 (ref $s7)) (param $8 (ref $s8)) (param $9 (ref $a0)) (param $10 (ref $a1)) (param $11 (ref $a2)) (param $12 (ref $a3)) (param $13 (ref $subvoid)) (param $14 (ref $submany))
;; CHECK: (func $use-types (type $62) (param $0 (ref $s0)) (param $1 (ref $s1)) (param $2 (ref $s2)) (param $3 (ref $s3)) (param $4 (ref $s4)) (param $5 (ref $s5)) (param $6 (ref $s6)) (param $7 (ref $s7)) (param $8 (ref $s8)) (param $9 (ref $a0)) (param $10 (ref $a1)) (param $11 (ref $a2)) (param $12 (ref $a3)) (param $13 (ref $subvoid)) (param $14 (ref $submany))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $use-types
Expand Down