diff options
author | Thomas Lively <tlively@google.com> | 2023-12-12 17:20:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 17:20:32 -0800 |
commit | 28bea549061d88a8a7f7d05f3acf3bca175f0102 (patch) | |
tree | 2329f4374061006771672c7d37001783eaaf06a5 /src | |
parent | b59b2fc639a134260458bc076c407e7fbfb946d6 (diff) | |
download | binaryen-28bea549061d88a8a7f7d05f3acf3bca175f0102.tar.gz binaryen-28bea549061d88a8a7f7d05f3acf3bca175f0102.tar.bz2 binaryen-28bea549061d88a8a7f7d05f3acf3bca175f0102.zip |
Add an arity immediate to tuple.extract (#6172)
Once support for tuple.extract lands in the new WAT parser, this arity immediate
will let the parser determine how many values it should pop off the stack to
serve as the tuple operand to `tuple.extract`. This will usually coincide with
the arity of a tuple-producing instruction on top of the stack, but in the
spirit of treating the input as a proper stack machine, it will not have to and
the parser will still work correctly.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 1 | ||||
-rw-r--r-- | src/passes/TupleOptimization.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 15 |
3 files changed, 12 insertions, 6 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 51909c6ff..3feebd121 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -1998,6 +1998,7 @@ struct PrintExpressionContents } void visitTupleExtract(TupleExtract* curr) { printMedium(o, "tuple.extract "); + o << curr->tuple->type.size() << " "; o << curr->index; } void visitRefI31(RefI31* curr) { printMedium(o, "ref.i31"); } diff --git a/src/passes/TupleOptimization.cpp b/src/passes/TupleOptimization.cpp index 16a2bad58..25da1c5ec 100644 --- a/src/passes/TupleOptimization.cpp +++ b/src/passes/TupleOptimization.cpp @@ -22,7 +22,7 @@ // (local.set $tuple // (tuple.make 3 (A) (B) (C))) // (use -// (tuple.extract 0 +// (tuple.extract 3 0 // (local.get $tuple))) // // If there are no other uses, then we just need one of the three lanes. By diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 521060749..94b434dfb 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2872,11 +2872,16 @@ Expression* SExpressionWasmBuilder::makeTupleMake(Element& s) { Expression* SExpressionWasmBuilder::makeTupleExtract(Element& s) { auto ret = allocator.alloc<TupleExtract>(); - ret->index = parseIndex(*s[1]); - ret->tuple = parseExpression(s[2]); - if (ret->tuple->type != Type::unreachable && - ret->index >= ret->tuple->type.size()) { - throw SParseException("Bad index on tuple.extract", s, *s[1]); + size_t arity = std::stoll(s[1]->toString()); + ret->index = parseIndex(*s[2]); + ret->tuple = parseExpression(s[3]); + if (ret->tuple->type != Type::unreachable) { + if (arity != ret->tuple->type.size()) { + throw SParseException("Unexpected tuple.extract arity", s, *s[1]); + } + if (ret->index >= ret->tuple->type.size()) { + throw SParseException("Bad index on tuple.extract", s, *s[2]); + } } ret->finalize(); return ret; |