From 2bdc4841b680ee44e132bbb07f5167eaa7226f99 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 27 Jan 2021 17:46:31 +0000 Subject: [GC] ref.as_* (#3520) These are similar to is, but instead of returning an i32 answer, they trap on an invalid value, and return it otherwise. These could in theory be in a single RefDoThing, with opcodes for both As and Is, but as the return values are different, that would be a little odd, and the name would be less clear. --- src/wasm/wasm-stack.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/wasm/wasm-stack.cpp') diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 5609dbb0e..197581e33 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2072,6 +2072,22 @@ void BinaryInstWriter::visitArrayLen(ArrayLen* curr) { parent.writeHeapType(curr->ref->type.getHeapType()); } +void BinaryInstWriter::visitRefAs(RefAs* curr) { + switch (curr->op) { + case RefAsFunc: + o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsFunc); + break; + case RefAsData: + o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsData); + break; + case RefAsI31: + o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::RefAsI31); + break; + default: + WASM_UNREACHABLE("invalid ref.as_*"); + } +} + void BinaryInstWriter::emitScopeEnd(Expression* curr) { assert(!breakStack.empty()); breakStack.pop_back(); -- cgit v1.2.3