Skip to content

Commit 962c2a2

Browse files
committed
extend preserve-locals.wast
Signed-off-by: Robin Freyler <[email protected]>
1 parent 6355dfe commit 962c2a2

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

tests/preserve-locals.wast

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,134 @@
117117
(assert_return (invoke "if.preserve-locals" (i32.const 1) (i32.const -1)) (i32.const -1))
118118
(assert_return (invoke "if.preserve-locals" (i32.const 1) (i32.const 42)) (i32.const 042))
119119
(assert_return (invoke "if.preserve-locals" (i32.const 1) (i32.const 999)) (i32.const 999))
120+
121+
(module
122+
(func (export "block.nested") (param i32 i32) (param $c0 i32) (param $c1 i32) (result i32 i32)
123+
(local.get 0) ;; 1st return value
124+
(local.get 1) ;; 2nd return value
125+
(block
126+
(br_if 0 (local.get $c0))
127+
(local.set 0 (i32.const 10)) ;; conditionally overwrites (local 0) on stack
128+
(block
129+
(br_if 1 (local.get $c1))
130+
(local.set 1 (i32.const 20)) ;; conditionally overwrites (local 1) on stack
131+
)
132+
)
133+
)
134+
)
135+
(assert_return
136+
(invoke "block.nested" (i32.const 10) (i32.const 20) (i32.const 0) (i32.const 0))
137+
(i32.const 10) (i32.const 20)
138+
)
139+
(assert_return
140+
(invoke "block.nested" (i32.const 10) (i32.const 20) (i32.const 0) (i32.const 1))
141+
(i32.const 10) (i32.const 20)
142+
)
143+
(assert_return
144+
(invoke "block.nested" (i32.const 10) (i32.const 20) (i32.const 1) (i32.const 0))
145+
(i32.const 10) (i32.const 20)
146+
)
147+
(assert_return
148+
(invoke "block.nested" (i32.const 10) (i32.const 20) (i32.const 1) (i32.const 1))
149+
(i32.const 10) (i32.const 20)
150+
)
151+
152+
(module
153+
(func (export "if.nested") (param i32 i32) (param $c0 i32) (param $c1 i32) (result i32 i32)
154+
local.get 0 ;; 1st return value
155+
local.get 1 ;; 2nd return value
156+
(if (local.get $c0)
157+
(then
158+
(local.set 0 (i32.const 10)) ;; overwrites (local 0) conditionally
159+
(if (local.get $c1)
160+
(then
161+
(local.set 1 (i32.const 20)) ;; overwrites (local 1) conditionally
162+
)
163+
)
164+
)
165+
)
166+
)
167+
)
168+
(assert_return
169+
(invoke "if.nested" (i32.const 10) (i32.const 20) (i32.const 0) (i32.const 0))
170+
(i32.const 10) (i32.const 20)
171+
)
172+
(assert_return
173+
(invoke "if.nested" (i32.const 10) (i32.const 20) (i32.const 0) (i32.const 1))
174+
(i32.const 10) (i32.const 20)
175+
)
176+
(assert_return
177+
(invoke "if.nested" (i32.const 10) (i32.const 20) (i32.const 1) (i32.const 0))
178+
(i32.const 10) (i32.const 20)
179+
)
180+
(assert_return
181+
(invoke "if.nested" (i32.const 10) (i32.const 20) (i32.const 1) (i32.const 1))
182+
(i32.const 10) (i32.const 20)
183+
)
184+
185+
(module
186+
(func (export "expr.block.rhs") (param $cond i32) (param $x i32) (param $y0 i32) (param $y1 i32) (result i32)
187+
(i32.add
188+
(local.get $x)
189+
(block $exit (result i32)
190+
(drop
191+
(br_if $exit
192+
(local.get $y0) ;; br_if return value
193+
(i32.eqz (local.get $cond)) ;; br_if condition
194+
)
195+
)
196+
(local.set $x (i32.const 0x7FFF_FFFF)) ;; x = i32::MAX
197+
(local.get $y1)
198+
)
199+
)
200+
)
201+
)
202+
(assert_return
203+
(invoke "expr.block.rhs" (i32.const 0) (i32.const 3) (i32.const 5) (i32.const 7))
204+
(i32.const 8)
205+
)
206+
(assert_return
207+
(invoke "expr.block.rhs" (i32.const 0) (i32.const 5) (i32.const 7) (i32.const 11))
208+
(i32.const 12)
209+
)
210+
(assert_return
211+
(invoke "expr.block.rhs" (i32.const 1) (i32.const 3) (i32.const 5) (i32.const 7))
212+
(i32.const 10)
213+
)
214+
(assert_return
215+
(invoke "expr.block.rhs" (i32.const 1) (i32.const 5) (i32.const 7) (i32.const 11))
216+
(i32.const 16)
217+
)
218+
219+
(module
220+
(func (export "expr.if.rhs") (param $cond i32) (param $x i32) (param $y0 i32) (param $y1 i32) (result i32)
221+
(i32.add
222+
(local.get $x)
223+
(if (result i32) (i32.eqz (local.get $cond))
224+
(then
225+
(local.set $x (i32.const 0x7FFF_FFFF)) ;; x = i32::MAX
226+
(local.get $y0)
227+
)
228+
(else
229+
(local.get $y1)
230+
)
231+
)
232+
)
233+
)
234+
)
235+
(assert_return
236+
(invoke "expr.if.rhs" (i32.const 0) (i32.const 3) (i32.const 5) (i32.const 7))
237+
(i32.const 8)
238+
)
239+
(assert_return
240+
(invoke "expr.if.rhs" (i32.const 0) (i32.const 5) (i32.const 7) (i32.const 11))
241+
(i32.const 12)
242+
)
243+
(assert_return
244+
(invoke "expr.if.rhs" (i32.const 1) (i32.const 3) (i32.const 5) (i32.const 7))
245+
(i32.const 10)
246+
)
247+
(assert_return
248+
(invoke "expr.if.rhs" (i32.const 1) (i32.const 5) (i32.const 7) (i32.const 11))
249+
(i32.const 16)
250+
)

0 commit comments

Comments
 (0)