summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-12-12 11:25:53 -0800
committerGitHub <noreply@github.com>2023-12-12 11:25:53 -0800
commita2a59e96f8f18e00e8aea9627d3b15d894d5a825 (patch)
tree6692c7556659ddb2a72178ed931445eb112c60f2 /src
parent71dad8795112b5c9ed1442450fa7e7bbe33622d1 (diff)
downloadbinaryen-a2a59e96f8f18e00e8aea9627d3b15d894d5a825.tar.gz
binaryen-a2a59e96f8f18e00e8aea9627d3b15d894d5a825.tar.bz2
binaryen-a2a59e96f8f18e00e8aea9627d3b15d894d5a825.zip
Update `tuple.make` text format to include arity (#6169)
Previously, the number of tuple elements was inferred from the number of s-expression children of the `tuple.make` expression, but that scheme would not work in the new wat parser, where s-expressions are optional and cannot be semantically meaningful. Update the text format to take the number of tuple elements (i.e. the tuple arity) as an immediate. This new format will be able to be implemented in the new parser as follow-on work.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Flatten.cpp2
-rw-r--r--src/passes/Print.cpp5
-rw-r--r--src/passes/TupleOptimization.cpp2
-rw-r--r--src/wasm/wasm-s-parser.cpp6
4 files changed, 11 insertions, 4 deletions
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp
index 3c0aa78a0..8ddd8632a 100644
--- a/src/passes/Flatten.cpp
+++ b/src/passes/Flatten.cpp
@@ -24,7 +24,7 @@
// (func $foo
// (drop
// (block (result funcref (ref $none))
-// (tuple.make
+// (tuple.make 2
// (ref.null func)
// (ref.func $foo)
// )
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 889eb87fd..9a0a600f9 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1985,7 +1985,10 @@ struct PrintExpressionContents
}
restoreNormalColor(o);
}
- void visitTupleMake(TupleMake* curr) { printMedium(o, "tuple.make"); }
+ void visitTupleMake(TupleMake* curr) {
+ printMedium(o, "tuple.make ");
+ o << curr->operands.size();
+ }
void visitTupleExtract(TupleExtract* curr) {
printMedium(o, "tuple.extract ");
o << curr->index;
diff --git a/src/passes/TupleOptimization.cpp b/src/passes/TupleOptimization.cpp
index e4fb1cf00..16a2bad58 100644
--- a/src/passes/TupleOptimization.cpp
+++ b/src/passes/TupleOptimization.cpp
@@ -20,7 +20,7 @@
// like this:
//
// (local.set $tuple
-// (tuple.make (A) (B) (C)))
+// (tuple.make 3 (A) (B) (C)))
// (use
// (tuple.extract 0
// (local.get $tuple)))
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 9e16d34e6..8e74820a9 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2858,7 +2858,11 @@ Expression* SExpressionWasmBuilder::makeRethrow(Element& s) {
Expression* SExpressionWasmBuilder::makeTupleMake(Element& s) {
auto ret = allocator.alloc<TupleMake>();
- parseCallOperands(s, 1, s.size(), ret);
+ size_t arity = std::stoll(s[1]->toString());
+ if (arity != s.size() - 2) {
+ throw SParseException("unexpected number of elements", s, *s[1]);
+ }
+ parseCallOperands(s, 2, s.size(), ret);
ret->finalize();
return ret;
}