diff options
-rw-r--r-- | src/parser/contexts.h | 5 | ||||
-rw-r--r-- | src/parser/parsers.h | 2 | ||||
-rw-r--r-- | src/wasm-ir-builder.h | 2 | ||||
-rw-r--r-- | src/wasm.h | 1 | ||||
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 7 | ||||
-rw-r--r-- | test/lit/wat-kitchen-sink.wast | 45 |
6 files changed, 57 insertions, 5 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 4147f7bda..aa207fcd5 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -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 @@ -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 diff --git a/src/parser/parsers.h b/src/parser/parsers.h index e2fb3732a..610e2953a 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -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> diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 64ee0d62e..24b430e25 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -170,7 +170,7 @@ public: [[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(); diff --git a/src/wasm.h b/src/wasm.h index dbedc05f4..47cc047bb 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1760,6 +1760,7 @@ public: class RefAs : public SpecificExpression<Expression::RefAsId> { public: + RefAs() = default; RefAs(MixedArena& allocator) {} RefAsOp op; diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index cc2bfb433..843e0ed78 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -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() {} diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index a99cd4c24..6b70a7822 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -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))) @@ -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)) @@ -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) @@ -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 |