summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gen-s-parser.inc3
-rw-r--r--src/passes/Print.cpp3
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm-interpreter.h3
-rw-r--r--src/wasm.h1
-rw-r--r--src/wasm/wasm-binary.cpp6
-rw-r--r--src/wasm/wasm-stack.cpp3
-rw-r--r--src/wasm/wasm.cpp4
8 files changed, 24 insertions, 0 deletions
diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc
index a22a01c02..3930a0318 100644
--- a/src/gen-s-parser.inc
+++ b/src/gen-s-parser.inc
@@ -2849,6 +2849,9 @@ switch (op[0]) {
case 'i':
if (strcmp(op, "ref.as_i31") == 0) { return makeRefAs(s, RefAsI31); }
goto parse_error;
+ case 'n':
+ if (strcmp(op, "ref.as_non_null") == 0) { return makeRefAs(s, RefAsNonNull); }
+ goto parse_error;
default: goto parse_error;
}
}
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index c380eb0f9..9e1afffd4 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1871,6 +1871,9 @@ struct PrintExpressionContents
}
void visitRefAs(RefAs* curr) {
switch (curr->op) {
+ case RefAsNonNull:
+ printMedium(o, "ref.as_non_null");
+ break;
case RefAsFunc:
printMedium(o, "ref.as_func");
break;
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index e976a57bf..3536afaf8 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -996,6 +996,7 @@ enum ASTNodes {
RefNull = 0xd0,
RefIsNull = 0xd1,
RefFunc = 0xd2,
+ RefAsNonNull = 0xd3,
// exception handling opcodes
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index fb7a3fcea..26c86efe6 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1681,6 +1681,9 @@ public:
trap("null ref");
}
switch (curr->op) {
+ case RefAsNonNull:
+ // We've already checked for a null.
+ break;
case RefAsFunc:
if (value.type.isFunction()) {
trap("not a func");
diff --git a/src/wasm.h b/src/wasm.h
index 2102972b3..d681f3f4b 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -550,6 +550,7 @@ enum RefIsOp {
};
enum RefAsOp {
+ RefAsNonNull,
RefAsFunc,
RefAsData,
RefAsI31,
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 64a40f2ca..4a90dd698 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2876,6 +2876,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
case BinaryConsts::RefEq:
visitRefEq((curr = allocator.alloc<RefEq>())->cast<RefEq>());
break;
+ case BinaryConsts::RefAsNonNull:
+ visitRefAs((curr = allocator.alloc<RefAs>())->cast<RefAs>(), code);
+ break;
case BinaryConsts::Try:
visitTryOrTryInBlock(curr);
break;
@@ -5997,6 +6000,9 @@ bool WasmBinaryBuilder::maybeVisitArrayLen(Expression*& out, uint32_t code) {
void WasmBinaryBuilder::visitRefAs(RefAs* curr, uint8_t code) {
BYN_TRACE("zz node: RefAs\n");
switch (code) {
+ case BinaryConsts::RefAsNonNull:
+ curr->op = RefAsNonNull;
+ break;
case BinaryConsts::RefAsFunc:
curr->op = RefAsFunc;
break;
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 0ccca0e23..9ac3013b5 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2090,6 +2090,9 @@ void BinaryInstWriter::visitArrayLen(ArrayLen* curr) {
void BinaryInstWriter::visitRefAs(RefAs* curr) {
switch (curr->op) {
+ case RefAsNonNull:
+ o << int8_t(BinaryConsts::RefAsNonNull);
+ break;
case RefAsFunc:
o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsFunc);
break;
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index a62435412..a94bda066 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -1036,6 +1036,10 @@ void RefAs::finalize() {
return;
}
switch (op) {
+ case RefAsNonNull:
+ // FIXME: when we support non-nullable types, switch to NonNullable
+ type = Type(value->type.getHeapType(), Nullable);
+ break;
case RefAsFunc:
type = Type::funcref;
break;