diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 13 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 11 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 10 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 8 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 11 |
5 files changed, 38 insertions, 15 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index bf71d3a4d..b3f085b36 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2865,7 +2865,7 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { visitRefNull((curr = allocator.alloc<RefNull>())->cast<RefNull>()); break; case BinaryConsts::RefIsNull: - visitRefIsNull((curr = allocator.alloc<RefIsNull>())->cast<RefIsNull>()); + visitRefIs((curr = allocator.alloc<RefIs>())->cast<RefIs>(), code); break; case BinaryConsts::RefFunc: visitRefFunc((curr = allocator.alloc<RefFunc>())->cast<RefFunc>()); @@ -5528,8 +5528,15 @@ void WasmBinaryBuilder::visitRefNull(RefNull* curr) { curr->finalize(getHeapType()); } -void WasmBinaryBuilder::visitRefIsNull(RefIsNull* curr) { - BYN_TRACE("zz node: RefIsNull\n"); +void WasmBinaryBuilder::visitRefIs(RefIs* curr, uint8_t code) { + BYN_TRACE("zz node: RefIs\n"); + switch (code) { + case BinaryConsts::RefIsNull: + curr->op = RefIsNull; + break; + default: + WASM_UNREACHABLE("invalid code for ref.is_*"); + } curr->value = popNonVoidExpression(); curr->finalize(); } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 857c0143b..b2212db18 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -51,7 +51,7 @@ int unhex(char c) { namespace wasm { static Name STRUCT("struct"), FIELD("field"), ARRAY("array"), I8("i8"), - I16("i16"), RTT("rtt"); + I16("i16"), RTT("rtt"), REF_IS_NULL("ref.is_null"); static Address getAddress(const Element* s) { return atoll(s->c_str()); } @@ -1922,8 +1922,13 @@ Expression* SExpressionWasmBuilder::makeRefNull(Element& s) { return ret; } -Expression* SExpressionWasmBuilder::makeRefIsNull(Element& s) { - auto ret = allocator.alloc<RefIsNull>(); +Expression* SExpressionWasmBuilder::makeRefIs(Element& s) { + auto ret = allocator.alloc<RefIs>(); + if (*s[0] == REF_IS_NULL) { + ret->op = RefIsNull; + } else { + WASM_UNREACHABLE("unimplemented ref.is_*"); + } ret->value = parseExpression(s[1]); ret->finalize(); return ret; diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index fae9da140..7b902ad67 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -1864,8 +1864,14 @@ void BinaryInstWriter::visitRefNull(RefNull* curr) { parent.writeHeapType(curr->type.getHeapType()); } -void BinaryInstWriter::visitRefIsNull(RefIsNull* curr) { - o << int8_t(BinaryConsts::RefIsNull); +void BinaryInstWriter::visitRefIs(RefIs* curr) { + switch (curr->op) { + case RefIsNull: + o << int8_t(BinaryConsts::RefIsNull); + break; + default: + WASM_UNREACHABLE("unimplemented ref.is_*"); + } } void BinaryInstWriter::visitRefFunc(RefFunc* curr) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 7cddf5a86..8def0e529 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -331,7 +331,7 @@ public: void visitMemorySize(MemorySize* curr); void visitMemoryGrow(MemoryGrow* curr); void visitRefNull(RefNull* curr); - void visitRefIsNull(RefIsNull* curr); + void visitRefIs(RefIs* curr); void visitRefFunc(RefFunc* curr); void visitRefEq(RefEq* curr); void visitTry(Try* curr); @@ -1981,14 +1981,14 @@ void FunctionValidator::visitRefNull(RefNull* curr) { curr->type.isNullable(), curr, "ref.null types must be nullable"); } -void FunctionValidator::visitRefIsNull(RefIsNull* curr) { +void FunctionValidator::visitRefIs(RefIs* curr) { shouldBeTrue(getModule()->features.hasReferenceTypes(), curr, - "ref.is_null requires reference-types to be enabled"); + "ref.is_* requires reference-types to be enabled"); shouldBeTrue(curr->value->type == Type::unreachable || curr->value->type.isRef(), curr->value, - "ref.is_null's argument should be a reference type"); + "ref.is_*'s argument should be a reference type"); } void FunctionValidator::visitRefFunc(RefFunc* curr) { diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 13085ca17..f2f08033e 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -188,8 +188,13 @@ const char* getExpressionName(Expression* curr) { return "pop"; case Expression::Id::RefNullId: return "ref.null"; - case Expression::Id::RefIsNullId: - return "ref.is_null"; + case Expression::Id::RefIsId: + switch (curr->cast<RefIs>()->op) { + case RefIsNull: + return "ref.is_null"; + default: + WASM_UNREACHABLE("unimplemented ref.is_*"); + } case Expression::Id::RefFuncId: return "ref.func"; case Expression::Id::RefEqId: @@ -929,7 +934,7 @@ void RefNull::finalize(Type type_) { void RefNull::finalize() { } -void RefIsNull::finalize() { +void RefIs::finalize() { if (value->type == Type::unreachable) { type = Type::unreachable; return; |