summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-09-24 12:02:09 +0200
committerGitHub <noreply@github.com>2020-09-24 12:02:09 +0200
commite9e1b2ff00aeb05aaeb57af3811add267dc25323 (patch)
tree4e19032813858b2e650f0cda46fe9fa227aa0a7f /src/wasm/wasm-binary.cpp
parenta42423fafa8cf731c69303ddc0acbe80c890e0ab (diff)
downloadbinaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.tar.gz
binaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.tar.bz2
binaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.zip
GC: Add i31 instructions (#3154)
Adds the `i31.new` and `i31.get_s/u` instructions for creating and working with `i31ref` typed values. Does not include fuzzer integration just yet because the fuzzer expects that trivial values it creates are suitable in global initializers, which is not the case for trivial `i31ref` expressions.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index c1f698bb0..85880a988 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2589,6 +2589,17 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
throwError("invalid code after SIMD prefix: " + std::to_string(opcode));
break;
}
+ case BinaryConsts::GCPrefix: {
+ auto opcode = getU32LEB();
+ if (maybeVisitI31New(curr, opcode)) {
+ break;
+ }
+ if (maybeVisitI31Get(curr, opcode)) {
+ break;
+ }
+ throwError("invalid code after GC prefix: " + std::to_string(opcode));
+ break;
+ }
default: {
// otherwise, the code is a subcode TODO: optimize
if (maybeVisitBinary(curr, code)) {
@@ -5008,6 +5019,37 @@ void WasmBinaryBuilder::visitBrOnExn(BrOnExn* curr) {
curr->finalize();
}
+bool WasmBinaryBuilder::maybeVisitI31New(Expression*& out, uint32_t code) {
+ if (code != BinaryConsts::I31New) {
+ return false;
+ }
+ auto* curr = allocator.alloc<I31New>();
+ curr->value = popNonVoidExpression();
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
+bool WasmBinaryBuilder::maybeVisitI31Get(Expression*& out, uint32_t code) {
+ I31Get* curr;
+ switch (code) {
+ case BinaryConsts::I31GetS:
+ curr = allocator.alloc<I31Get>();
+ curr->signed_ = true;
+ break;
+ case BinaryConsts::I31GetU:
+ curr = allocator.alloc<I31Get>();
+ curr->signed_ = false;
+ break;
+ default:
+ return false;
+ }
+ curr->i31 = popNonVoidExpression();
+ curr->finalize();
+ out = curr;
+ return true;
+}
+
void WasmBinaryBuilder::throwError(std::string text) {
throw ParseException(text, 0, pos);
}