Skip to content

Commit 07d53b6

Browse files
committed
Update pop text syntax
Rather than `(pop valtype*)`, use `(pop valtype)`, where `valtype` is now allowed to be a tuple. This will make it possible to parse un-folded multivalue pops in the new text parser. The alternative would have been to put an arity in the syntax like we have for other tuple instructions, but that's much uglier.
1 parent f57ade3 commit 07d53b6

10 files changed

+27
-31
lines changed

src/passes/Print.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,11 +2023,8 @@ struct PrintExpressionContents
20232023
void visitNop(Nop* curr) { printMinor(o, "nop"); }
20242024
void visitUnreachable(Unreachable* curr) { printMinor(o, "unreachable"); }
20252025
void visitPop(Pop* curr) {
2026-
prepareColor(o) << "pop";
2027-
for (auto type : curr->type) {
2028-
o << ' ';
2029-
printType(type);
2030-
}
2026+
prepareColor(o) << "pop ";
2027+
printType(curr->type);
20312028
restoreNormalColor(o);
20322029
}
20332030
void visitTupleMake(TupleMake* curr) {

src/wasm/wasm-s-parser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,11 +2394,10 @@ Expression* SExpressionWasmBuilder::makeMemoryFill(Element& s) {
23942394

23952395
Expression* SExpressionWasmBuilder::makePop(Element& s) {
23962396
auto ret = allocator.alloc<Pop>();
2397-
std::vector<Type> types;
2398-
for (size_t i = 1; i < s.size(); ++i) {
2399-
types.push_back(elementToType(*s[i]));
2397+
if (s.size() != 2) {
2398+
throw SParseException("expected 'pop <valtype>'", s);
24002399
}
2401-
ret->type = Type(types);
2400+
ret->type = elementToType(*s[1]);
24022401
ret->finalize();
24032402
return ret;
24042403
}

test/example/c-api-kitchen-sink.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ BinaryenFeatureAll: 131071
22372237
(pop externref)
22382238
)
22392239
(tuple.drop 4
2240-
(pop i32 i64 f32 f64)
2240+
(pop (tuple i32 i64 f32 f64))
22412241
)
22422242
(drop
22432243
(memory.size)

test/lit/basic/exception-handling-old.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
;; CHECK-TEXT-NEXT: )
116116
;; CHECK-TEXT-NEXT: (catch $e-i32-i64
117117
;; CHECK-TEXT-NEXT: (local.set $x
118-
;; CHECK-TEXT-NEXT: (pop i32 i64)
118+
;; CHECK-TEXT-NEXT: (pop (tuple i32 i64))
119119
;; CHECK-TEXT-NEXT: )
120120
;; CHECK-TEXT-NEXT: (drop
121121
;; CHECK-TEXT-NEXT: (tuple.extract 2 0
@@ -139,7 +139,7 @@
139139
;; CHECK-BIN-NEXT: )
140140
;; CHECK-BIN-NEXT: (catch $e-i32-i64
141141
;; CHECK-BIN-NEXT: (local.set $2
142-
;; CHECK-BIN-NEXT: (pop i32 i64)
142+
;; CHECK-BIN-NEXT: (pop (tuple i32 i64))
143143
;; CHECK-BIN-NEXT: )
144144
;; CHECK-BIN-NEXT: (local.set $x
145145
;; CHECK-BIN-NEXT: (block (result i32)
@@ -168,7 +168,7 @@
168168
(throw $e-i32-i64 (i32.const 0) (i64.const 0))
169169
)
170170
(catch $e-i32-i64
171-
(local.set $x (pop i32 i64))
171+
(local.set $x (pop (tuple i32 i64)))
172172
(drop
173173
(tuple.extract 2 0
174174
(local.get $x)
@@ -1387,7 +1387,7 @@
13871387
;; CHECK-BIN-NODEBUG-NEXT: )
13881388
;; CHECK-BIN-NODEBUG-NEXT: (catch $tag$2
13891389
;; CHECK-BIN-NODEBUG-NEXT: (local.set $2
1390-
;; CHECK-BIN-NODEBUG-NEXT: (pop i32 i64)
1390+
;; CHECK-BIN-NODEBUG-NEXT: (pop (tuple i32 i64))
13911391
;; CHECK-BIN-NODEBUG-NEXT: )
13921392
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0
13931393
;; CHECK-BIN-NODEBUG-NEXT: (block (result i32)

test/lit/passes/catch-pop-fixup-eh-old.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
;; CHECK-NEXT: )
335335
;; CHECK-NEXT: (catch $e-i32-f32
336336
;; CHECK-NEXT: (local.set $1
337-
;; CHECK-NEXT: (pop i32 f32)
337+
;; CHECK-NEXT: (pop (tuple i32 f32))
338338
;; CHECK-NEXT: )
339339
;; CHECK-NEXT: (throw $e-i32
340340
;; CHECK-NEXT: (block (result i32)
@@ -354,7 +354,7 @@
354354
(throw $e-i32
355355
;; This tests a pop taking a tuple type.
356356
(block (result i32)
357-
(local.set $x (pop i32 f32))
357+
(local.set $x (pop (tuple i32 f32)))
358358
(i32.const 0)
359359
)
360360
)

test/lit/passes/gufa-refs.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@
21502150
;; CHECK-NEXT: )
21512151
;; CHECK-NEXT: (catch $tag
21522152
;; CHECK-NEXT: (local.set $0
2153-
;; CHECK-NEXT: (pop anyref anyref)
2153+
;; CHECK-NEXT: (pop (tuple anyref anyref))
21542154
;; CHECK-NEXT: )
21552155
;; CHECK-NEXT: (drop
21562156
;; CHECK-NEXT: (block (result nullref)
@@ -2169,7 +2169,7 @@
21692169
;; CHECK-NEXT: (catch $tag
21702170
;; CHECK-NEXT: (drop
21712171
;; CHECK-NEXT: (tuple.extract 2 1
2172-
;; CHECK-NEXT: (pop anyref anyref)
2172+
;; CHECK-NEXT: (pop (tuple anyref anyref))
21732173
;; CHECK-NEXT: )
21742174
;; CHECK-NEXT: )
21752175
;; CHECK-NEXT: )
@@ -2187,7 +2187,7 @@
21872187
(catch $tag
21882188
(drop
21892189
(tuple.extract 2 0
2190-
(pop (ref null any) (ref null any))
2190+
(pop (tuple (ref null any) (ref null any)))
21912191
)
21922192
)
21932193
)
@@ -2198,7 +2198,7 @@
21982198
(catch $tag
21992199
(drop
22002200
(tuple.extract 2 1
2201-
(pop (ref null any) (ref null any))
2201+
(pop (tuple (ref null any) (ref null any)))
22022202
)
22032203
)
22042204
)

test/lit/passes/poppify.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
;; CHECK-NEXT: (i32.const 0)
483483
;; CHECK-NEXT: (i64.const 1)
484484
;; CHECK-NEXT: (br $l
485-
;; CHECK-NEXT: (pop i32 i64)
485+
;; CHECK-NEXT: (pop (tuple i32 i64))
486486
;; CHECK-NEXT: )
487487
;; CHECK-NEXT: )
488488
;; CHECK-NEXT: )
@@ -501,7 +501,7 @@
501501
;; CHECK-NEXT: (i32.const 0)
502502
;; CHECK-NEXT: (i64.const 1)
503503
;; CHECK-NEXT: (return
504-
;; CHECK-NEXT: (pop i32 i64)
504+
;; CHECK-NEXT: (pop (tuple i32 i64))
505505
;; CHECK-NEXT: )
506506
;; CHECK-NEXT: )
507507
(func $return-tuple (result i32 i64)

test/lit/passes/translate-eh-old-to-new.wast

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
)
233233
(catch $e-i32-i64
234234
(tuple.drop 2
235-
(pop i32 i64)
235+
(pop (tuple i32 i64))
236236
)
237237
)
238238
(catch_all
@@ -294,7 +294,7 @@
294294
)
295295
(catch $e-i32-i64
296296
(tuple.drop 2
297-
(pop i32 i64)
297+
(pop (tuple i32 i64))
298298
)
299299
(rethrow $l0)
300300
)
@@ -515,7 +515,7 @@
515515
)
516516
(catch $e-i32-i64
517517
(tuple.drop 2
518-
(pop i32 i64)
518+
(pop (tuple i32 i64))
519519
)
520520
(i32.const 1)
521521
)
@@ -584,7 +584,7 @@
584584
)
585585
(catch $e-i32-i64
586586
(tuple.drop 2
587-
(pop i32 i64)
587+
(pop (tuple i32 i64))
588588
)
589589
(rethrow $l0)
590590
)
@@ -856,7 +856,7 @@
856856
)
857857
)
858858
(catch $e-i32-i64
859-
(pop i32 i64)
859+
(pop (tuple i32 i64))
860860
)
861861
(catch_all
862862
(tuple.make 2
@@ -932,7 +932,7 @@
932932
)
933933
(catch $e-i32-i64
934934
(tuple.drop 2
935-
(pop i32 i64)
935+
(pop (tuple i32 i64))
936936
)
937937
(rethrow $l0)
938938
)
@@ -1050,7 +1050,7 @@
10501050
)
10511051
(catch $e-i32-i64
10521052
(tuple.drop 2
1053-
(pop i32 i64)
1053+
(pop (tuple i32 i64))
10541054
)
10551055
(rethrow $l0)
10561056
)

test/lit/wat-kitchen-sink.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@
18241824
;; CHECK-NEXT: )
18251825
;; CHECK-NEXT: )
18261826
;; CHECK-NEXT: (catch $tag-pair
1827-
;; CHECK-NEXT: (pop i32 i64)
1827+
;; CHECK-NEXT: (pop (tuple i32 i64))
18281828
;; CHECK-NEXT: )
18291829
;; CHECK-NEXT: )
18301830
;; CHECK-NEXT: )

test/spec/exception-handling-old.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
)
8383
(catch $e-i32-f32
8484
(local.set $x
85-
(pop i32 f32)
85+
(pop (tuple i32 f32))
8686
)
8787
(tuple.extract 2 0
8888
(local.get $x)

0 commit comments

Comments
 (0)