Debian Codegraph @

internal/integration_test/spectest/v2/testdata/imports.wast

raw
1 ;; Auxiliary module to import from
2
3 (module
4 (func (export "func"))
5 (func (export "func-i32") (param i32))
6 (func (export "func-f32") (param f32))
7 (func (export "func->i32") (result i32) (i32.const 22))
8 (func (export "func->f32") (result f32) (f32.const 11))
9 (func (export "func-i32->i32") (param i32) (result i32) (local.get 0))
10 (func (export "func-i64->i64") (param i64) (result i64) (local.get 0))
11 (global (export "global-i32") i32 (i32.const 55))
12 (global (export "global-f32") f32 (f32.const 44))
13 (global (export "global-mut-i64") (mut i64) (i64.const 66))
14 (table (export "table-10-inf") 10 funcref)
15 (table (export "table-10-20") 10 20 funcref)
16 (memory (export "memory-2-inf") 2)
17 ;; Multiple memories are not yet supported
18 ;; (memory (export "memory-2-4") 2 4)
19 )
20
21 (register "test")
22
23
24 ;; Functions
25
26 (module
27 (type $func_i32 (func (param i32)))
28 (type $func_i64 (func (param i64)))
29 (type $func_f32 (func (param f32)))
30 (type $func_f64 (func (param f64)))
31
32 (import "spectest" "print_i32" (func (param i32)))
33 (func (import "spectest" "print_i64") (param i64))
34 (import "spectest" "print_i32" (func $print_i32 (param i32)))
35 (import "spectest" "print_i64" (func $print_i64 (param i64)))
36 (import "spectest" "print_f32" (func $print_f32 (param f32)))
37 (import "spectest" "print_f64" (func $print_f64 (param f64)))
38 (import "spectest" "print_i32_f32" (func $print_i32_f32 (param i32 f32)))
39 (import "spectest" "print_f64_f64" (func $print_f64_f64 (param f64 f64)))
40 (func $print_i32-2 (import "spectest" "print_i32") (param i32))
41 (func $print_f64-2 (import "spectest" "print_f64") (param f64))
42 (import "test" "func-i64->i64" (func $i64->i64 (param i64) (result i64)))
43
44 (func (export "p1") (import "spectest" "print_i32") (param i32))
45 (func $p (export "p2") (import "spectest" "print_i32") (param i32))
46 (func (export "p3") (export "p4") (import "spectest" "print_i32") (param i32))
47 (func (export "p5") (import "spectest" "print_i32") (type 0))
48 (func (export "p6") (import "spectest" "print_i32") (type 0) (param i32) (result))
49
50 (import "spectest" "print_i32" (func (type $forward)))
51 (func (import "spectest" "print_i32") (type $forward))
52 (type $forward (func (param i32)))
53
54 (table funcref (elem $print_i32 $print_f64))
55
56 (func (export "print32") (param $i i32)
57 (local $x f32)
58 (local.set $x (f32.convert_i32_s (local.get $i)))
59 (call 0 (local.get $i))
60 (call $print_i32_f32
61 (i32.add (local.get $i) (i32.const 1))
62 (f32.const 42)
63 )
64 (call $print_i32 (local.get $i))
65 (call $print_i32-2 (local.get $i))
66 (call $print_f32 (local.get $x))
67 (call_indirect (type $func_i32) (local.get $i) (i32.const 0))
68 )
69
70 (func (export "print64") (param $i i64)
71 (local $x f64)
72 (local.set $x (f64.convert_i64_s (call $i64->i64 (local.get $i))))
73 (call 1 (local.get $i))
74 (call $print_f64_f64
75 (f64.add (local.get $x) (f64.const 1))
76 (f64.const 53)
77 )
78 (call $print_i64 (local.get $i))
79 (call $print_f64 (local.get $x))
80 (call $print_f64-2 (local.get $x))
81 (call_indirect (type $func_f64) (local.get $x) (i32.const 1))
82 )
83 )
84
85 (assert_return (invoke "print32" (i32.const 13)))
86 (assert_return (invoke "print64" (i64.const 24)))
87
88 (assert_invalid
89 (module
90 (type (func (result i32)))
91 (import "test" "func" (func (type 1)))
92 )
93 "unknown type"
94 )
95
96 ;; Export sharing name with import
97 (module
98 (import "spectest" "print_i32" (func $imported_print (param i32)))
99 (func (export "print_i32") (param $i i32)
100 (call $imported_print (local.get $i))
101 )
102 )
103
104 (assert_return (invoke "print_i32" (i32.const 13)))
105
106 ;; Export sharing name with import
107 (module
108 (import "spectest" "print_i32" (func $imported_print (param i32)))
109 (func (export "print_i32") (param $i i32) (param $j i32) (result i32)
110 (i32.add (local.get $i) (local.get $j))
111 )
112 )
113
114 (assert_return (invoke "print_i32" (i32.const 5) (i32.const 11)) (i32.const 16))
115
116 (module (import "test" "func" (func)))
117 (module (import "test" "func-i32" (func (param i32))))
118 (module (import "test" "func-f32" (func (param f32))))
119 (module (import "test" "func->i32" (func (result i32))))
120 (module (import "test" "func->f32" (func (result f32))))
121 (module (import "test" "func-i32->i32" (func (param i32) (result i32))))
122 (module (import "test" "func-i64->i64" (func (param i64) (result i64))))
123
124 (assert_unlinkable
125 (module (import "test" "unknown" (func)))
126 "unknown import"
127 )
128 (assert_unlinkable
129 (module (import "spectest" "unknown" (func)))
130 "unknown import"
131 )
132
133 (assert_unlinkable
134 (module (import "test" "func" (func (param i32))))
135 "incompatible import type"
136 )
137 (assert_unlinkable
138 (module (import "test" "func" (func (result i32))))
139 "incompatible import type"
140 )
141 (assert_unlinkable
142 (module (import "test" "func" (func (param i32) (result i32))))
143 "incompatible import type"
144 )
145 (assert_unlinkable
146 (module (import "test" "func-i32" (func)))
147 "incompatible import type"
148 )
149 (assert_unlinkable
150 (module (import "test" "func-i32" (func (result i32))))
151 "incompatible import type"
152 )
153 (assert_unlinkable
154 (module (import "test" "func-i32" (func (param f32))))
155 "incompatible import type"
156 )
157 (assert_unlinkable
158 (module (import "test" "func-i32" (func (param i64))))
159 "incompatible import type"
160 )
161 (assert_unlinkable
162 (module (import "test" "func-i32" (func (param i32) (result i32))))
163 "incompatible import type"
164 )
165 (assert_unlinkable
166 (module (import "test" "func->i32" (func)))
167 "incompatible import type"
168 )
169 (assert_unlinkable
170 (module (import "test" "func->i32" (func (param i32))))
171 "incompatible import type"
172 )
173 (assert_unlinkable
174 (module (import "test" "func->i32" (func (result f32))))
175 "incompatible import type"
176 )
177 (assert_unlinkable
178 (module (import "test" "func->i32" (func (result i64))))
179 "incompatible import type"
180 )
181 (assert_unlinkable
182 (module (import "test" "func->i32" (func (param i32) (result i32))))
183 "incompatible import type"
184 )
185 (assert_unlinkable
186 (module (import "test" "func-i32->i32" (func)))
187 "incompatible import type"
188 )
189 (assert_unlinkable
190 (module (import "test" "func-i32->i32" (func (param i32))))
191 "incompatible import type"
192 )
193 (assert_unlinkable
194 (module (import "test" "func-i32->i32" (func (result i32))))
195 "incompatible import type"
196 )
197
198 (assert_unlinkable
199 (module (import "test" "global-i32" (func (result i32))))
200 "incompatible import type"
201 )
202 (assert_unlinkable
203 (module (import "test" "table-10-inf" (func)))
204 "incompatible import type"
205 )
206 (assert_unlinkable
207 (module (import "test" "memory-2-inf" (func)))
208 "incompatible import type"
209 )
210 (assert_unlinkable
211 (module (import "spectest" "global_i32" (func)))
212 "incompatible import type"
213 )
214 (assert_unlinkable
215 (module (import "spectest" "table" (func)))
216 "incompatible import type"
217 )
218 (assert_unlinkable
219 (module (import "spectest" "memory" (func)))
220 "incompatible import type"
221 )
222
223
224 ;; Globals
225
226 (module
227 (import "spectest" "global_i32" (global i32))
228 (global (import "spectest" "global_i32") i32)
229
230 (import "spectest" "global_i32" (global $x i32))
231 (global $y (import "spectest" "global_i32") i32)
232
233 (import "spectest" "global_i64" (global i64))
234 (import "spectest" "global_f32" (global f32))
235 (import "spectest" "global_f64" (global f64))
236
237 (func (export "get-0") (result i32) (global.get 0))
238 (func (export "get-1") (result i32) (global.get 1))
239 (func (export "get-x") (result i32) (global.get $x))
240 (func (export "get-y") (result i32) (global.get $y))
241 (func (export "get-4") (result i64) (global.get 4))
242 (func (export "get-5") (result f32) (global.get 5))
243 (func (export "get-6") (result f64) (global.get 6))
244 )
245
246 (assert_return (invoke "get-0") (i32.const 666))
247 (assert_return (invoke "get-1") (i32.const 666))
248 (assert_return (invoke "get-x") (i32.const 666))
249 (assert_return (invoke "get-y") (i32.const 666))
250 (assert_return (invoke "get-4") (i64.const 666))
251 (assert_return (invoke "get-5") (f32.const 666.6))
252 (assert_return (invoke "get-6") (f64.const 666.6))
253
254 (module (import "test" "global-i32" (global i32)))
255 (module (import "test" "global-f32" (global f32)))
256 (module (import "test" "global-mut-i64" (global (mut i64))))
257
258 (assert_unlinkable
259 (module (import "test" "unknown" (global i32)))
260 "unknown import"
261 )
262 (assert_unlinkable
263 (module (import "spectest" "unknown" (global i32)))
264 "unknown import"
265 )
266
267 (assert_unlinkable
268 (module (import "test" "global-i32" (global i64)))
269 "incompatible import type"
270 )
271 (assert_unlinkable
272 (module (import "test" "global-i32" (global f32)))
273 "incompatible import type"
274 )
275 (assert_unlinkable
276 (module (import "test" "global-i32" (global f64)))
277 "incompatible import type"
278 )
279 (assert_unlinkable
280 (module (import "test" "global-i32" (global (mut i32))))
281 "incompatible import type"
282 )
283 (assert_unlinkable
284 (module (import "test" "global-f32" (global i32)))
285 "incompatible import type"
286 )
287 (assert_unlinkable
288 (module (import "test" "global-f32" (global i64)))
289 "incompatible import type"
290 )
291 (assert_unlinkable
292 (module (import "test" "global-f32" (global f64)))
293 "incompatible import type"
294 )
295 (assert_unlinkable
296 (module (import "test" "global-f32" (global (mut f32))))
297 "incompatible import type"
298 )
299 (assert_unlinkable
300 (module (import "test" "global-mut-i64" (global (mut i32))))
301 "incompatible import type"
302 )
303 (assert_unlinkable
304 (module (import "test" "global-mut-i64" (global (mut f32))))
305 "incompatible import type"
306 )
307 (assert_unlinkable
308 (module (import "test" "global-mut-i64" (global (mut f64))))
309 "incompatible import type"
310 )
311 (assert_unlinkable
312 (module (import "test" "global-mut-i64" (global i64)))
313 "incompatible import type"
314 )
315
316 (assert_unlinkable
317 (module (import "test" "func" (global i32)))
318 "incompatible import type"
319 )
320 (assert_unlinkable
321 (module (import "test" "table-10-inf" (global i32)))
322 "incompatible import type"
323 )
324 (assert_unlinkable
325 (module (import "test" "memory-2-inf" (global i32)))
326 "incompatible import type"
327 )
328 (assert_unlinkable
329 (module (import "spectest" "print_i32" (global i32)))
330 "incompatible import type"
331 )
332 (assert_unlinkable
333 (module (import "spectest" "table" (global i32)))
334 "incompatible import type"
335 )
336 (assert_unlinkable
337 (module (import "spectest" "memory" (global i32)))
338 "incompatible import type"
339 )
340
341
342 ;; Tables
343
344 (module
345 (type (func (result i32)))
346 (import "spectest" "table" (table $tab 10 20 funcref))
347 (elem (table $tab) (i32.const 1) func $f $g)
348
349 (func (export "call") (param i32) (result i32)
350 (call_indirect $tab (type 0) (local.get 0))
351 )
352 (func $f (result i32) (i32.const 11))
353 (func $g (result i32) (i32.const 22))
354 )
355
356 (assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
357 (assert_return (invoke "call" (i32.const 1)) (i32.const 11))
358 (assert_return (invoke "call" (i32.const 2)) (i32.const 22))
359 (assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
360 (assert_trap (invoke "call" (i32.const 100)) "undefined element")
361
362
363 (module
364 (type (func (result i32)))
365 (table $tab (import "spectest" "table") 10 20 funcref)
366 (elem (table $tab) (i32.const 1) func $f $g)
367
368 (func (export "call") (param i32) (result i32)
369 (call_indirect $tab (type 0) (local.get 0))
370 )
371 (func $f (result i32) (i32.const 11))
372 (func $g (result i32) (i32.const 22))
373 )
374
375 (assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
376 (assert_return (invoke "call" (i32.const 1)) (i32.const 11))
377 (assert_return (invoke "call" (i32.const 2)) (i32.const 22))
378 (assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
379 (assert_trap (invoke "call" (i32.const 100)) "undefined element")
380
381 (module
382 (import "spectest" "table" (table 0 funcref))
383 (import "spectest" "table" (table 0 funcref))
384 (table 10 funcref)
385 (table 10 funcref)
386 )
387
388 (module (import "test" "table-10-inf" (table 10 funcref)))
389 (module (import "test" "table-10-inf" (table 5 funcref)))
390 (module (import "test" "table-10-inf" (table 0 funcref)))
391 (module (import "test" "table-10-20" (table 10 funcref)))
392 (module (import "test" "table-10-20" (table 5 funcref)))
393 (module (import "test" "table-10-20" (table 0 funcref)))
394 (module (import "test" "table-10-20" (table 10 20 funcref)))
395 (module (import "test" "table-10-20" (table 5 20 funcref)))
396 (module (import "test" "table-10-20" (table 0 20 funcref)))
397 (module (import "test" "table-10-20" (table 10 25 funcref)))
398 (module (import "test" "table-10-20" (table 5 25 funcref)))
399 (module (import "test" "table-10-20" (table 0 25 funcref)))
400 (module (import "spectest" "table" (table 10 funcref)))
401 (module (import "spectest" "table" (table 5 funcref)))
402 (module (import "spectest" "table" (table 0 funcref)))
403 (module (import "spectest" "table" (table 10 20 funcref)))
404 (module (import "spectest" "table" (table 5 20 funcref)))
405 (module (import "spectest" "table" (table 0 20 funcref)))
406 (module (import "spectest" "table" (table 10 25 funcref)))
407 (module (import "spectest" "table" (table 5 25 funcref)))
408
409 (assert_unlinkable
410 (module (import "test" "unknown" (table 10 funcref)))
411 "unknown import"
412 )
413 (assert_unlinkable
414 (module (import "spectest" "unknown" (table 10 funcref)))
415 "unknown import"
416 )
417
418 (assert_unlinkable
419 (module (import "test" "table-10-inf" (table 12 funcref)))
420 "incompatible import type"
421 )
422 (assert_unlinkable
423 (module (import "test" "table-10-inf" (table 10 20 funcref)))
424 "incompatible import type"
425 )
426 (assert_unlinkable
427 (module (import "test" "table-10-20" (table 12 20 funcref)))
428 "incompatible import type"
429 )
430 (assert_unlinkable
431 (module (import "test" "table-10-20" (table 10 18 funcref)))
432 "incompatible import type"
433 )
434 (assert_unlinkable
435 (module (import "spectest" "table" (table 12 funcref)))
436 "incompatible import type"
437 )
438 (assert_unlinkable
439 (module (import "spectest" "table" (table 10 15 funcref)))
440 "incompatible import type"
441 )
442
443 (assert_unlinkable
444 (module (import "test" "func" (table 10 funcref)))
445 "incompatible import type"
446 )
447 (assert_unlinkable
448 (module (import "test" "global-i32" (table 10 funcref)))
449 "incompatible import type"
450 )
451 (assert_unlinkable
452 (module (import "test" "memory-2-inf" (table 10 funcref)))
453 "incompatible import type"
454 )
455 (assert_unlinkable
456 (module (import "spectest" "print_i32" (table 10 funcref)))
457 "incompatible import type"
458 )
459
460
461
462 ;; Memories
463
464 (module
465 (import "spectest" "memory" (memory 1 2))
466 (data (memory 0) (i32.const 10) "\10")
467
468 (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
469 )
470
471 (assert_return (invoke "load" (i32.const 0)) (i32.const 0))
472 (assert_return (invoke "load" (i32.const 10)) (i32.const 16))
473 (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
474 (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
475
476 (module
477 (memory (import "spectest" "memory") 1 2)
478 (data (memory 0) (i32.const 10) "\10")
479
480 (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
481 )
482 (assert_return (invoke "load" (i32.const 0)) (i32.const 0))
483 (assert_return (invoke "load" (i32.const 10)) (i32.const 16))
484 (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
485 (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
486
487 (assert_invalid
488 (module (import "" "" (memory 1)) (import "" "" (memory 1)))
489 "multiple memories"
490 )
491 (assert_invalid
492 (module (import "" "" (memory 1)) (memory 0))
493 "multiple memories"
494 )
495 (assert_invalid
496 (module (memory 0) (memory 0))
497 "multiple memories"
498 )
499
500 (module (import "test" "memory-2-inf" (memory 2)))
501 (module (import "test" "memory-2-inf" (memory 1)))
502 (module (import "test" "memory-2-inf" (memory 0)))
503 (module (import "spectest" "memory" (memory 1)))
504 (module (import "spectest" "memory" (memory 0)))
505 (module (import "spectest" "memory" (memory 1 2)))
506 (module (import "spectest" "memory" (memory 0 2)))
507 (module (import "spectest" "memory" (memory 1 3)))
508 (module (import "spectest" "memory" (memory 0 3)))
509
510 (assert_unlinkable
511 (module (import "test" "unknown" (memory 1)))
512 "unknown import"
513 )
514 (assert_unlinkable
515 (module (import "spectest" "unknown" (memory 1)))
516 "unknown import"
517 )
518
519 (assert_unlinkable
520 (module (import "test" "memory-2-inf" (memory 3)))
521 "incompatible import type"
522 )
523 (assert_unlinkable
524 (module (import "test" "memory-2-inf" (memory 2 3)))
525 "incompatible import type"
526 )
527 (assert_unlinkable
528 (module (import "spectest" "memory" (memory 2)))
529 "incompatible import type"
530 )
531 (assert_unlinkable
532 (module (import "spectest" "memory" (memory 1 1)))
533 "incompatible import type"
534 )
535
536 (assert_unlinkable
537 (module (import "test" "func-i32" (memory 1)))
538 "incompatible import type"
539 )
540 (assert_unlinkable
541 (module (import "test" "global-i32" (memory 1)))
542 "incompatible import type"
543 )
544 (assert_unlinkable
545 (module (import "test" "table-10-inf" (memory 1)))
546 "incompatible import type"
547 )
548 (assert_unlinkable
549 (module (import "spectest" "print_i32" (memory 1)))
550 "incompatible import type"
551 )
552 (assert_unlinkable
553 (module (import "spectest" "global_i32" (memory 1)))
554 "incompatible import type"
555 )
556 (assert_unlinkable
557 (module (import "spectest" "table" (memory 1)))
558 "incompatible import type"
559 )
560
561 (assert_unlinkable
562 (module (import "spectest" "memory" (memory 2)))
563 "incompatible import type"
564 )
565 (assert_unlinkable
566 (module (import "spectest" "memory" (memory 1 1)))
567 "incompatible import type"
568 )
569
570 (module
571 (import "spectest" "memory" (memory 0 3)) ;; actual has max size 2
572 (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0)))
573 )
574 (assert_return (invoke "grow" (i32.const 0)) (i32.const 1))
575 (assert_return (invoke "grow" (i32.const 1)) (i32.const 1))
576 (assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
577 (assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
578 (assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
579
580
581 ;; Syntax errors
582
583 (assert_malformed
584 (module quote "(func) (import \"\" \"\" (func))")
585 "import after function"
586 )
587 (assert_malformed
588 (module quote "(func) (import \"\" \"\" (global i64))")
589 "import after function"
590 )
591 (assert_malformed
592 (module quote "(func) (import \"\" \"\" (table 0 funcref))")
593 "import after function"
594 )
595 (assert_malformed
596 (module quote "(func) (import \"\" \"\" (memory 0))")
597 "import after function"
598 )
599
600 (assert_malformed
601 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (func))")
602 "import after global"
603 )
604 (assert_malformed
605 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (global f32))")
606 "import after global"
607 )
608 (assert_malformed
609 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (table 0 funcref))")
610 "import after global"
611 )
612 (assert_malformed
613 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (memory 0))")
614 "import after global"
615 )
616
617 (assert_malformed
618 (module quote "(table 0 funcref) (import \"\" \"\" (func))")
619 "import after table"
620 )
621 (assert_malformed
622 (module quote "(table 0 funcref) (import \"\" \"\" (global i32))")
623 "import after table"
624 )
625 (assert_malformed
626 (module quote "(table 0 funcref) (import \"\" \"\" (table 0 funcref))")
627 "import after table"
628 )
629 (assert_malformed
630 (module quote "(table 0 funcref) (import \"\" \"\" (memory 0))")
631 "import after table"
632 )
633
634 (assert_malformed
635 (module quote "(memory 0) (import \"\" \"\" (func))")
636 "import after memory"
637 )
638 (assert_malformed
639 (module quote "(memory 0) (import \"\" \"\" (global i32))")
640 "import after memory"
641 )
642 (assert_malformed
643 (module quote "(memory 0) (import \"\" \"\" (table 1 3 funcref))")
644 "import after memory"
645 )
646 (assert_malformed
647 (module quote "(memory 0) (import \"\" \"\" (memory 1 2))")
648 "import after memory"
649 )
650
651 ;; This module is required to validate, regardless of whether it can be
652 ;; linked. Overloading is not possible in wasm itself, but it is possible
653 ;; in modules from which wasm can import.
654 (module)
655 (register "not wasm")
656 (assert_unlinkable
657 (module
658 (import "not wasm" "overloaded" (func))
659 (import "not wasm" "overloaded" (func (param i32)))
660 (import "not wasm" "overloaded" (func (param i32 i32)))
661 (import "not wasm" "overloaded" (func (param i64)))
662 (import "not wasm" "overloaded" (func (param f32)))
663 (import "not wasm" "overloaded" (func (param f64)))
664 (import "not wasm" "overloaded" (func (result i32)))
665 (import "not wasm" "overloaded" (func (result i64)))
666 (import "not wasm" "overloaded" (func (result f32)))
667 (import "not wasm" "overloaded" (func (result f64)))
668 (import "not wasm" "overloaded" (global i32))
669 (import "not wasm" "overloaded" (global i64))
670 (import "not wasm" "overloaded" (global f32))
671 (import "not wasm" "overloaded" (global f64))
672 (import "not wasm" "overloaded" (table 0 funcref))
673 (import "not wasm" "overloaded" (memory 0))
674 )
675 "unknown import"
676 )