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