summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp6
-rw-r--r--src/wasm/wasm-stack.cpp18
-rw-r--r--src/wasm/wasm.cpp13
3 files changed, 28 insertions, 9 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 4a90dd698..b7ffcd8d7 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2879,6 +2879,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
case BinaryConsts::RefAsNonNull:
visitRefAs((curr = allocator.alloc<RefAs>())->cast<RefAs>(), code);
break;
+ case BinaryConsts::BrOnNull:
+ maybeVisitBrOn(curr, code);
+ break;
case BinaryConsts::Try:
visitTryOrTryInBlock(curr);
break;
@@ -5831,6 +5834,9 @@ bool WasmBinaryBuilder::maybeVisitRefCast(Expression*& out, uint32_t code) {
bool WasmBinaryBuilder::maybeVisitBrOn(Expression*& out, uint32_t code) {
BrOnOp op;
switch (code) {
+ case BinaryConsts::BrOnNull:
+ op = BrOnNull;
+ break;
case BinaryConsts::BrOnCast:
op = BrOnCast;
break;
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 003d2b7af..d42080bac 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -1982,19 +1982,21 @@ void BinaryInstWriter::visitRefCast(RefCast* curr) {
}
void BinaryInstWriter::visitBrOn(BrOn* curr) {
- o << int8_t(BinaryConsts::GCPrefix);
switch (curr->op) {
+ case BrOnNull:
+ o << int8_t(BinaryConsts::BrOnNull);
+ break;
case BrOnCast:
- o << U32LEB(BinaryConsts::BrOnCast);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnCast);
break;
case BrOnFunc:
- o << U32LEB(BinaryConsts::BrOnFunc);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnFunc);
break;
case BrOnData:
- o << U32LEB(BinaryConsts::BrOnData);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnData);
break;
case BrOnI31:
- o << U32LEB(BinaryConsts::BrOnI31);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::BrOnI31);
break;
default:
WASM_UNREACHABLE("invalid br_on_*");
@@ -2085,13 +2087,13 @@ void BinaryInstWriter::visitRefAs(RefAs* curr) {
o << int8_t(BinaryConsts::RefAsNonNull);
break;
case RefAsFunc:
- o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsFunc);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefAsFunc);
break;
case RefAsData:
- o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsData);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefAsData);
break;
case RefAsI31:
- o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsI31);
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RefAsI31);
break;
default:
WASM_UNREACHABLE("invalid ref.as_*");
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index a94bda066..f8d8890ec 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -936,13 +936,24 @@ void BrOn::finalize() {
(rtt && rtt->type == Type::unreachable)) {
type = Type::unreachable;
} else {
- type = ref->type;
+ if (op == BrOnNull) {
+ // If BrOnNull does not branch, it flows out the existing value as
+ // non-null.
+ // FIXME: When we support non-nullable types, this should be non-nullable.
+ type = Type(ref->type.getHeapType(), Nullable);
+ } else {
+ type = ref->type;
+ }
}
}
Type BrOn::getCastType() {
switch (op) {
+ case BrOnNull:
+ // BrOnNull does not send a value on the branch.
+ return Type::none;
case BrOnCast:
+ // FIXME: When we support non-nullable types, this should be non-nullable.
return Type(rtt->type.getHeapType(), Nullable);
case BrOnFunc:
return Type::funcref;