1;; Test `nop` operator.
2
3(module
4  ;; Auxiliary definitions
5  (func $dummy)
6  (func $3-ary (param i32 i32 i32) (result i32)
7    get_local 0 get_local 1 get_local 2 i32.sub i32.add
8  )
9  (memory 1)
10
11  (func (export "as-func-first") (result i32)
12    (nop) (i32.const 1)
13  )
14  (func (export "as-func-mid") (result i32)
15    (call $dummy) (nop) (i32.const 2)
16  )
17  (func (export "as-func-last") (result i32)
18    (call $dummy) (i32.const 3) (nop)
19  )
20  (func (export "as-func-everywhere") (result i32)
21    (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop)
22  )
23
24  (func (export "as-drop-last") (param i32)
25    (get_local 0) (nop) (drop)
26  )
27  (func (export "as-drop-everywhere") (param i32)
28    (nop) (nop) (get_local 0) (nop) (nop) (drop)
29  )
30
31  (func (export "as-select-mid1") (param i32) (result i32)
32    (get_local 0) (nop) (get_local 0) (get_local 0) (select)
33  )
34  (func (export "as-select-mid2") (param i32) (result i32)
35    (get_local 0) (get_local 0) (nop) (get_local 0) (select)
36  )
37  (func (export "as-select-last") (param i32) (result i32)
38    (get_local 0) (get_local 0) (get_local 0) (nop) (select)
39  )
40  (func (export "as-select-everywhere") (param i32) (result i32)
41    (nop) (get_local 0) (nop) (nop) (get_local 0)
42    (nop) (nop) (get_local 0) (nop) (nop) (select)
43  )
44
45  (func (export "as-block-first") (result i32)
46    (block i32 (nop) (i32.const 2))
47  )
48  (func (export "as-block-mid") (result i32)
49    (block i32 (call $dummy) (nop) (i32.const 2))
50  )
51  (func (export "as-block-last") (result i32)
52    (block i32 (nop) (call $dummy) (i32.const 3) (nop))
53  )
54  (func (export "as-block-everywhere") (result i32)
55    (block i32 (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop))
56  )
57
58  (func (export "as-loop-first") (result i32)
59    (loop i32 (nop) (i32.const 2))
60  )
61  (func (export "as-loop-mid") (result i32)
62    (loop i32 (call $dummy) (nop) (i32.const 2))
63  )
64  (func (export "as-loop-last") (result i32)
65    (loop i32 (call $dummy) (i32.const 3) (nop))
66  )
67  (func (export "as-loop-everywhere") (result i32)
68    (loop i32 (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop))
69  )
70
71  (func (export "as-if-condition") (param i32)
72    (get_local 0) (nop) (if (then (call $dummy)))
73  )
74  (func (export "as-if-then") (param i32)
75    (if (get_local 0) (nop) (call $dummy))
76  )
77  (func (export "as-if-else") (param i32)
78    (if (get_local 0) (call $dummy) (nop))
79  )
80
81  (func (export "as-br-last") (param i32) (result i32)
82    (block i32 (get_local 0) (nop) (br 0))
83  )
84  (func (export "as-br-everywhere") (param i32) (result i32)
85    (block i32 (nop) (nop) (get_local 0) (nop) (nop) (br 0))
86  )
87
88  (func (export "as-br_if-mid") (param i32) (result i32)
89    (block i32 (get_local 0) (nop) (get_local 0) (br_if 0))
90  )
91  (func (export "as-br_if-last") (param i32) (result i32)
92    (block i32 (get_local 0) (get_local 0) (nop) (br_if 0))
93  )
94  (func (export "as-br_if-everywhere") (param i32) (result i32)
95    (block i32
96      (nop) (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop)
97      (br_if 0)
98    )
99  )
100
101  (func (export "as-br_table-mid") (param i32) (result i32)
102    (block i32 (get_local 0) (nop) (get_local 0) (br_table 0 0))
103  )
104  (func (export "as-br_table-last") (param i32) (result i32)
105    (block i32 (get_local 0) (get_local 0) (nop) (br_table 0 0))
106  )
107  (func (export "as-br_table-everywhere") (param i32) (result i32)
108    (block i32
109      (nop) (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop)
110      (br_table 0 0)
111    )
112  )
113
114  (func (export "as-return-last") (param i32) (result i32)
115    (get_local 0) (nop) (return)
116  )
117  (func (export "as-return-everywhere") (param i32) (result i32)
118    (nop) (nop) (get_local 0) (nop) (nop) (return)
119  )
120
121  (func (export "as-call-mid1") (param i32 i32 i32) (result i32)
122    (get_local 0) (nop) (get_local 1) (get_local 2) (call $3-ary)
123  )
124  (func (export "as-call-mid2") (param i32 i32 i32) (result i32)
125    (get_local 0) (get_local 1) (nop) (get_local 2) (call $3-ary)
126  )
127  (func (export "as-call-last") (param i32 i32 i32) (result i32)
128    (get_local 0) (get_local 1) (get_local 2) (nop) (call $3-ary)
129  )
130  (func (export "as-call-everywhere") (param i32 i32 i32) (result i32)
131    (nop) (nop) (get_local 0) (nop) (nop) (get_local 1)
132    (nop) (nop) (get_local 2) (nop) (nop) (call $3-ary)
133  )
134
135  ;; TODO(stack): call_indirect, *_local, load*, store*
136
137  (func (export "as-unary-last") (param i32) (result i32)
138    (get_local 0) (nop) (i32.ctz)
139  )
140  (func (export "as-unary-everywhere") (param i32) (result i32)
141    (nop) (nop) (get_local 0) (nop) (nop) (i32.ctz)
142  )
143
144  (func (export "as-binary-mid") (param i32) (result i32)
145    (get_local 0) (nop) (get_local 0) (i32.add)
146  )
147  (func (export "as-binary-last") (param i32) (result i32)
148    (get_local 0) (get_local 0) (nop) (i32.add)
149  )
150  (func (export "as-binary-everywhere") (param i32) (result i32)
151    (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop) (i32.add)
152  )
153
154  (func (export "as-test-last") (param i32) (result i32)
155    (get_local 0) (nop) (i32.eqz)
156  )
157  (func (export "as-test-everywhere") (param i32) (result i32)
158    (nop) (nop) (get_local 0) (nop) (nop) i32.eqz
159  )
160
161  (func (export "as-compare-mid") (param i32) (result i32)
162    (get_local 0) (nop) (get_local 0) (i32.ne)
163  )
164  (func (export "as-compare-last") (param i32) (result i32)
165    (get_local 0) (get_local 0) (nop) (i32.lt_u)
166  )
167  (func (export "as-compare-everywhere") (param i32) (result i32)
168    (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop) (i32.le_s)
169  )
170
171  (func (export "as-grow_memory-last") (param i32) (result i32)
172    (get_local 0) (nop) (grow_memory)
173  )
174  (func (export "as-grow_memory-everywhere") (param i32) (result i32)
175    (nop) (nop) (get_local 0) (nop) (nop) (grow_memory)
176  )
177)
178
179(assert_return (invoke "as-func-first") (i32.const 1))
180(assert_return (invoke "as-func-mid") (i32.const 2))
181(assert_return (invoke "as-func-last") (i32.const 3))
182(assert_return (invoke "as-func-everywhere") (i32.const 4))
183
184(assert_return (invoke "as-drop-last" (i32.const 0)))
185(assert_return (invoke "as-drop-everywhere" (i32.const 0)))
186
187(assert_return (invoke "as-select-mid1" (i32.const 3)) (i32.const 3))
188(assert_return (invoke "as-select-mid2" (i32.const 3)) (i32.const 3))
189(assert_return (invoke "as-select-last" (i32.const 3)) (i32.const 3))
190(assert_return (invoke "as-select-everywhere" (i32.const 3)) (i32.const 3))
191
192(assert_return (invoke "as-block-first") (i32.const 2))
193(assert_return (invoke "as-block-mid") (i32.const 2))
194(assert_return (invoke "as-block-last") (i32.const 3))
195(assert_return (invoke "as-block-everywhere") (i32.const 4))
196
197(assert_return (invoke "as-loop-first") (i32.const 2))
198(assert_return (invoke "as-loop-mid") (i32.const 2))
199(assert_return (invoke "as-loop-last") (i32.const 3))
200(assert_return (invoke "as-loop-everywhere") (i32.const 4))
201
202(assert_return (invoke "as-if-condition" (i32.const 0)))
203(assert_return (invoke "as-if-condition" (i32.const -1)))
204(assert_return (invoke "as-if-then" (i32.const 0)))
205(assert_return (invoke "as-if-then" (i32.const 4)))
206(assert_return (invoke "as-if-else" (i32.const 0)))
207(assert_return (invoke "as-if-else" (i32.const 3)))
208
209(assert_return (invoke "as-br-last" (i32.const 6)) (i32.const 6))
210(assert_return (invoke "as-br-everywhere" (i32.const 7)) (i32.const 7))
211
212(assert_return (invoke "as-br_if-mid" (i32.const 5)) (i32.const 5))
213(assert_return (invoke "as-br_if-last" (i32.const 6)) (i32.const 6))
214(assert_return (invoke "as-br_if-everywhere" (i32.const 7)) (i32.const 7))
215
216(assert_return (invoke "as-br_table-mid" (i32.const 5)) (i32.const 5))
217(assert_return (invoke "as-br_table-last" (i32.const 6)) (i32.const 6))
218(assert_return (invoke "as-br_table-everywhere" (i32.const 7)) (i32.const 7))
219
220(assert_return (invoke "as-return-last" (i32.const 6)) (i32.const 6))
221(assert_return (invoke "as-return-everywhere" (i32.const 7)) (i32.const 7))
222
223(assert_return (invoke "as-call-mid1" (i32.const 3) (i32.const 1) (i32.const 2)) (i32.const 2))
224(assert_return (invoke "as-call-mid2" (i32.const 0) (i32.const 3) (i32.const 1)) (i32.const 2))
225(assert_return (invoke "as-call-last" (i32.const 10) (i32.const 9) (i32.const -1)) (i32.const 20))
226(assert_return (invoke "as-call-everywhere" (i32.const 2) (i32.const 1) (i32.const 5)) (i32.const -2))
227
228(assert_return (invoke "as-unary-last" (i32.const 30)) (i32.const 1))
229(assert_return (invoke "as-unary-everywhere" (i32.const 12)) (i32.const 2))
230
231(assert_return (invoke "as-binary-mid" (i32.const 3)) (i32.const 6))
232(assert_return (invoke "as-binary-last" (i32.const 3)) (i32.const 6))
233(assert_return (invoke "as-binary-everywhere" (i32.const 3)) (i32.const 6))
234
235(assert_return (invoke "as-test-last" (i32.const 0)) (i32.const 1))
236(assert_return (invoke "as-test-everywhere" (i32.const 0)) (i32.const 1))
237
238(assert_return (invoke "as-compare-mid" (i32.const 3)) (i32.const 0))
239(assert_return (invoke "as-compare-last" (i32.const 3)) (i32.const 0))
240(assert_return (invoke "as-compare-everywhere" (i32.const 3)) (i32.const 1))
241
242(assert_return (invoke "as-grow_memory-last" (i32.const 2)) (i32.const 1))
243(assert_return (invoke "as-grow_memory-everywhere" (i32.const 12)) (i32.const 3))
244
245(assert_invalid
246  (module (func $type-i32 (result i32) (nop)))
247  "type mismatch"
248)
249(assert_invalid
250  (module (func $type-i64 (result i64) (nop)))
251  "type mismatch"
252)
253(assert_invalid
254  (module (func $type-f32 (result f32) (nop)))
255  "type mismatch"
256)
257(assert_invalid
258  (module (func $type-f64 (result f64) (nop)))
259  "type mismatch"
260)
261