summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-11-15 01:43:27 +0100
committerGitHub <noreply@github.com>2023-11-15 01:43:27 +0100
commit325d588b0bf1497322d75c35ef8e017f9a8a5d7c (patch)
treec7bca1234294a5c92304c1191efa4ca1448f3919 /src
parent8eb4899d8dafe02c0440c5e33aaf37529e8fc941 (diff)
downloadbinaryen-325d588b0bf1497322d75c35ef8e017f9a8a5d7c.tar.gz
binaryen-325d588b0bf1497322d75c35ef8e017f9a8a5d7c.tar.bz2
binaryen-325d588b0bf1497322d75c35ef8e017f9a8a5d7c.zip
[Parser] Parse ref.test and ref.cast (#6099)
Diffstat (limited to 'src')
-rw-r--r--src/parser/contexts.h10
-rw-r--r--src/parser/parsers.h8
-rw-r--r--src/wasm-ir-builder.h4
-rw-r--r--src/wasm.h2
-rw-r--r--src/wasm/wasm-ir-builder.cpp14
5 files changed, 32 insertions, 6 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index 485c596e7..bf6c291e7 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -395,6 +395,8 @@ struct NullInstrParserCtx {
Result<> makeRefEq(Index) { return Ok{}; }
Result<> makeRefI31(Index) { return Ok{}; }
Result<> makeI31Get(Index, bool) { return Ok{}; }
+ template<typename TypeT> Result<> makeRefTest(Index, TypeT) { return Ok{}; }
+ template<typename TypeT> Result<> makeRefCast(Index, TypeT) { return Ok{}; }
template<typename HeapTypeT> Result<> makeStructNew(Index, HeapTypeT) {
return Ok{};
@@ -1280,6 +1282,14 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
return withLoc(pos, irBuilder.makeI31Get(signed_));
}
+ Result<> makeRefTest(Index pos, Type type) {
+ return withLoc(pos, irBuilder.makeRefTest(type));
+ }
+
+ Result<> makeRefCast(Index pos, Type type) {
+ return withLoc(pos, irBuilder.makeRefCast(type));
+ }
+
Result<> makeStructNew(Index pos, HeapType type) {
return withLoc(pos, irBuilder.makeStructNew(type));
}
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index 0641e941c..6b6bb0aa5 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -1303,11 +1303,15 @@ template<typename Ctx> Result<> makeI31Get(Ctx& ctx, Index pos, bool signed_) {
}
template<typename Ctx> Result<> makeRefTest(Ctx& ctx, Index pos) {
- return ctx.in.err("unimplemented instruction");
+ auto type = reftype(ctx);
+ CHECK_ERR(type);
+ return ctx.makeRefTest(pos, *type);
}
template<typename Ctx> Result<> makeRefCast(Ctx& ctx, Index pos) {
- return ctx.in.err("unimplemented instruction");
+ auto type = reftype(ctx);
+ CHECK_ERR(type);
+ return ctx.makeRefCast(pos, *type);
}
template<typename Ctx> Result<> makeBrOnNull(Ctx& ctx, Index pos, bool onFail) {
diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h
index 6d4fca3c3..c0cd7b4a1 100644
--- a/src/wasm-ir-builder.h
+++ b/src/wasm-ir-builder.h
@@ -149,8 +149,8 @@ public:
[[nodiscard]] Result<> makeRefI31();
[[nodiscard]] Result<> makeI31Get(bool signed_);
// [[nodiscard]] Result<> makeCallRef();
- // [[nodiscard]] Result<> makeRefTest();
- // [[nodiscard]] Result<> makeRefCast();
+ [[nodiscard]] Result<> makeRefTest(Type type);
+ [[nodiscard]] Result<> makeRefCast(Type type);
// [[nodiscard]] Result<> makeBrOn();
[[nodiscard]] Result<> makeStructNew(HeapType type);
[[nodiscard]] Result<> makeStructNewDefault(HeapType type);
diff --git a/src/wasm.h b/src/wasm.h
index ba797d773..96c9271fe 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1540,6 +1540,7 @@ public:
class RefTest : public SpecificExpression<Expression::RefTestId> {
public:
+ RefTest() = default;
RefTest(MixedArena& allocator) {}
Expression* ref;
@@ -1553,6 +1554,7 @@ public:
class RefCast : public SpecificExpression<Expression::RefCastId> {
public:
+ RefCast() = default;
RefCast(MixedArena& allocator) {}
Expression* ref;
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index cbb16ff68..c973238e9 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -919,9 +919,19 @@ Result<> IRBuilder::makeI31Get(bool signed_) {
// Result<> IRBuilder::makeCallRef() {}
-// Result<> IRBuilder::makeRefTest() {}
+Result<> IRBuilder::makeRefTest(Type type) {
+ RefTest curr;
+ CHECK_ERR(visitRefTest(&curr));
+ push(builder.makeRefTest(curr.ref, type));
+ return Ok{};
+}
-// Result<> IRBuilder::makeRefCast() {}
+Result<> IRBuilder::makeRefCast(Type type) {
+ RefCast curr;
+ CHECK_ERR(visitRefCast(&curr));
+ push(builder.makeRefCast(curr.ref, type));
+ return Ok{};
+}
// Result<> IRBuilder::makeBrOn() {}