summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/full-cycle.js
blob: 1ea8a653e3fedb7724e1a402b74af2253b684a7f (plain)
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
load(libdir + "wasm.js");

wasmFullPass(`(module
    (func $test (result i32) (param i32) (param i32) (i32.add (get_local 0) (get_local 1)))
    (func $run (result i32) (call $test (i32.const 1) (i32.const ${Math.pow(2, 31) - 1})))
    (export "run" $run)
)`, -Math.pow(2, 31));

wasmFullPass(`(module
    (func (result i32)
        i32.const 1
        i32.const 42
        i32.add
        return
        unreachable
        i32.const 0
        call 3
        i32.const 42
        f32.add
    )
    (func) (func) (func)
(export "run" 0))`, 43);

// Global section.
wasmFullPass(`(module
 (import $imported "globals" "x" (global i32))
 (global $mut_local (mut i32) (i32.const 0))
 (global $imm_local i32 (i32.const 37))
 (global $imm_local_2 i32 (get_global 0))
 (func $get (result i32)
  i32.const 13
  set_global $mut_local
  get_global $imported
  get_global $mut_local
  i32.add
  get_global $imm_local
  i32.add
  get_global $imm_local_2
  i32.add
 )
 (export "run" $get)
)`, 13 + 42 + 37 + 42, { globals: {x: 42} });

// Memory.
wasmFullPass(`(module
    (memory (export "memory") 1 2)
    (data (i32.const 0) "\\00\\01\\02" "\\03\\04\\05")
    (data (i32.const 6) "\\06")
    (func (export "run") (result i32)
        i32.const 1
        i32.load offset=2
    )
)`, 0x06050403);

let memory = new WebAssembly.Memory({ initial: 1, maximum: 2 });

wasmFullPass(`(module
    (memory (import "" "memory") 1 2)
    (data (i32.const 0) "\\00\\01\\02\\03\\04\\05")
    (func (export "run") (result i32)
        i32.const 1
        i32.load offset=2
    )
    (export "mem" memory)
)`, 0x050403, {"": {memory}});

// Tables.
wasmFullPass(`(module
    (table (export "table") 3 anyfunc)
    (type $t (func (result i32)))
    (func $foo (result i32) (i32.const 1))
    (func $bar (result i32) (i32.const 2))
    (func $baz (result i32) (i32.const 3))
    (elem (i32.const 0) $baz $bar)
    (elem (i32.const 2) $foo)
    (func (export "run") (param i32) (result i32)
        get_local 0
        call_indirect $t
    )
)`, 3, {}, 0);

let table = new WebAssembly.Table({ element: 'anyfunc', initial: 3, maximum: 3 });

wasmFullPass(`(module
    (table (import "" "table") 3 4 anyfunc)
    (type $t (func (result i32)))
    (func $foo (result i32) (i32.const 1))
    (func $bar (result i32) (i32.const 2))
    (func $baz (result i32) (i32.const 3))
    (elem (i32.const 0) $baz $bar)
    (elem (i32.const 2) $foo)
    (func (export "run") (param i32) (result i32)
        get_local 0
        call_indirect $t
    )
)`, 3, {"":{table}}, 0);

// Start function.
wasmFullPass(`(module
    (global $g (mut i32) (i32.const 0))
    (func $start
        get_global $g
        i32.const 1
        i32.add
        set_global $g
    )
    (start $start)
    (func (export "run") (result i32)
        get_global $g
    )
)`, 1);