summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-11-15 01:49:37 +0100
committerGitHub <noreply@github.com>2023-11-15 01:49:37 +0100
commit001be441be8ec04df0b03035aefc411923485780 (patch)
tree899c4b2591fcd563d1d5bb3c877442731a4542b2 /src
parent1496f97d7919960ef4e3f74a961d959bfc236218 (diff)
downloadbinaryen-001be441be8ec04df0b03035aefc411923485780.tar.gz
binaryen-001be441be8ec04df0b03035aefc411923485780.tar.bz2
binaryen-001be441be8ec04df0b03035aefc411923485780.zip
[Parser] Parse call_ref (#6103)
Also mark array.new_elem as unimplemented as a drive-by; it previously had an incorrect implementation.
Diffstat (limited to 'src')
-rw-r--r--src/parser/contexts.h7
-rw-r--r--src/parser/parsers.h10
-rw-r--r--src/wasm-ir-builder.h3
-rw-r--r--src/wasm/wasm-ir-builder.cpp25
4 files changed, 37 insertions, 8 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index f6dd92063..192442c84 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -393,6 +393,9 @@ struct NullInstrParserCtx {
Result<> makeRefIsNull(Index) { return Ok{}; }
Result<> makeRefFunc(Index, FuncIdxT) { return Ok{}; }
Result<> makeRefEq(Index) { return Ok{}; }
+ template<typename HeapTypeT> Result<> makeCallRef(Index, HeapTypeT, bool) {
+ return Ok{};
+ }
Result<> makeRefI31(Index) { return Ok{}; }
Result<> makeI31Get(Index, bool) { return Ok{}; }
template<typename TypeT> Result<> makeRefTest(Index, TypeT) { return Ok{}; }
@@ -1285,6 +1288,10 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
Result<> makeRefEq(Index pos) { return withLoc(pos, irBuilder.makeRefEq()); }
+ Result<> makeCallRef(Index pos, HeapType type, bool isReturn) {
+ return withLoc(pos, irBuilder.makeCallRef(type, isReturn));
+ }
+
Result<> makeRefI31(Index pos) {
return withLoc(pos, irBuilder.makeRefI31());
}
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index 2d90a7d27..41e625657 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -1291,7 +1291,9 @@ template<typename Ctx> Result<> makeTupleExtract(Ctx& ctx, Index pos) {
template<typename Ctx>
Result<> makeCallRef(Ctx& ctx, Index pos, bool isReturn) {
- return ctx.in.err("unimplemented instruction");
+ auto type = typeidx(ctx);
+ CHECK_ERR(type);
+ return ctx.makeCallRef(pos, *type, isReturn);
}
template<typename Ctx> Result<> makeRefI31(Ctx& ctx, Index pos) {
@@ -1374,11 +1376,7 @@ template<typename Ctx> Result<> makeArrayNewData(Ctx& ctx, Index pos) {
}
template<typename Ctx> Result<> makeArrayNewElem(Ctx& ctx, Index pos) {
- auto type = typeidx(ctx);
- CHECK_ERR(type);
- auto data = dataidx(ctx);
- CHECK_ERR(data);
- return ctx.makeArrayNewElem(pos, *type, *data);
+ return ctx.in.err("unimplemented instruction");
}
template<typename Ctx> Result<> makeArrayNewFixed(Ctx& ctx, Index pos) {
diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h
index 4b6cacae9..e02d623f8 100644
--- a/src/wasm-ir-builder.h
+++ b/src/wasm-ir-builder.h
@@ -148,7 +148,7 @@ public:
// [[nodiscard]] Result<> makeTupleExtract();
[[nodiscard]] Result<> makeRefI31();
[[nodiscard]] Result<> makeI31Get(bool signed_);
- // [[nodiscard]] Result<> makeCallRef();
+ [[nodiscard]] Result<> makeCallRef(HeapType type, bool isReturn);
[[nodiscard]] Result<> makeRefTest(Type type);
[[nodiscard]] Result<> makeRefCast(Type type);
[[nodiscard]] Result<>
@@ -197,6 +197,7 @@ public:
[[nodiscard]] Result<>
visitSwitch(Switch*, std::optional<Index> defaultLabel = std::nullopt);
[[nodiscard]] Result<> visitCall(Call*);
+ [[nodiscard]] Result<> visitCallRef(CallRef*);
private:
Module& wasm;
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index 9b2a944dd..433145d13 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -349,6 +349,18 @@ Result<> IRBuilder::visitCall(Call* curr) {
return Ok{};
}
+Result<> IRBuilder::visitCallRef(CallRef* curr) {
+ auto target = pop();
+ CHECK_ERR(target);
+ curr->target = *target;
+ for (size_t i = 0, numArgs = curr->operands.size(); i < numArgs; ++i) {
+ auto arg = pop();
+ CHECK_ERR(arg);
+ curr->operands[numArgs - 1 - i] = *arg;
+ }
+ return Ok{};
+}
+
Result<> IRBuilder::visitFunctionStart(Function* func) {
if (!scopeStack.empty()) {
return Err{"unexpected start of function"};
@@ -923,7 +935,18 @@ Result<> IRBuilder::makeI31Get(bool signed_) {
return Ok{};
}
-// Result<> IRBuilder::makeCallRef() {}
+Result<> IRBuilder::makeCallRef(HeapType type, bool isReturn) {
+ CallRef curr(wasm.allocator);
+ if (!type.isSignature()) {
+ return Err{"expected function type"};
+ }
+ auto sig = type.getSignature();
+ curr.operands.resize(type.getSignature().params.size());
+ CHECK_ERR(visitCallRef(&curr));
+ CHECK_ERR(validateTypeAnnotation(type, curr.target));
+ push(builder.makeCallRef(curr.target, curr.operands, sig.results, isReturn));
+ return Ok{};
+}
Result<> IRBuilder::makeRefTest(Type type) {
RefTest curr;