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