Debian Codegraph @

js/src/jit-test/tests/wasm/tail-calls/return-call-validate.js

raw
1 wasmValidateText(
2 `(module
3 (func $arity-1-vs-0
4 (i32.const 1) (return_call 1))
5 (func))`);
6
7 wasmValidateText(
8 `(module
9 (func $arity-2-vs-0
10 (f64.const 2) (i32.const 1) (return_call 1))
11 (func))`);
12
13 const constants = [{'type': 'i32', 'value': '0x132'},
14 {'type': 'i64', 'value': '0x164'},
15 {'type': 'f32', 'value': '0xf32'},
16 {'type': 'f64', 'value': '0xf64'}];
17
18 function validateConst(type, value) {
19 wasmValidateText(
20 `(module
21 (func $const-${type} (result ${type})
22 (${type}.const ${value}))
23 (func $trampoline-${type} (result ${type})
24 (return_call $const-${type}))
25 (func $t (result ${type})
26 (return_call $trampoline-${type})))`);
27 }
28 for (let {type, value} of constants) {
29 validateConst(type, value);
30 }
31
32 function validateOneArg(type, value) {
33 wasmValidateText(
34 `(module
35 (func $id-${type} (param ${type}) (result ${type})
36 (local.get 0))
37 (func $t (result ${type})
38 (return_call $id-${type} (${type}.const ${value}))))`);
39 }
40 for (let {type, value} of constants) {
41 validateOneArg(type, value);
42 }
43
44 function validateTwoArgs(t0, v0, t1, v1) {
45 wasmValidateText(
46 `(module
47 (func $second-${t0}-${t1} (param ${t0} ${t1}) (result ${t1})
48 (local.get 1))
49 (func $t (result ${t1})
50 (return_call $second-${t0}-${t1}
51 (${t0}.const ${v0}) (${t1}.const ${v1}))))`);
52 }
53 for (let {type: t0, value: v0} of constants) {
54 for (let {type: t1, value: v1} of constants) {
55 validateTwoArgs(t0, v0, t1, v1);
56 }
57 }
58
59 wasmValidateText(
60 `(module
61 (func $fac-acc (param i64 i64) (result i64)
62 (if (result i64) (i64.eqz (local.get 0))
63 (then (local.get 1))
64 (else
65 (return_call $fac-acc
66 (i64.sub (local.get 0) (i64.const 1))
67 (i64.mul (local.get 0) (local.get 1))))))
68 (func $t (result i64)
69 (return_call $fac-acc (i64.const 0) (i64.const 1))))`);
70
71 wasmValidateText(
72 `(module
73 (func $count (param i64) (result i64)
74 (if (result i64) (i64.eqz (local.get 0))
75 (then (local.get 0))
76 (else (return_call $count (i64.sub (local.get 0) (i64.const 1))))))
77 (func $t (result i64)
78 (return_call $count (i64.const 0))))`);
79
80 wasmValidateText(
81 `(module
82 (func $even (param i64) (result i32)
83 (if (result i32) (i64.eqz (local.get 0))
84 (then (i32.const 44))
85 (else (return_call $odd (i64.sub (local.get 0) (i64.const 1))))))
86 (func $odd (param i64) (result i32)
87 (if (result i32) (i64.eqz (local.get 0))
88 (then (i32.const 99))
89 (else (return_call $even (i64.sub (local.get 0) (i64.const 1))))))
90 (func $t (result i32)
91 (return_call $even (i64.const 0))))`);
92
93 wasmFailValidateText(
94 `(module
95 (func $type-void-vs-num (result i32)
96 (return_call 1) (i32.const 0))
97 (func))`,
98 /type mismatch: expected 1 values, got 0 values/);
99
100 wasmFailValidateText(
101 `(module
102 (func $type-num-vs-num (result i32)
103 (return_call 1) (i32.const 0))
104 (func (result i64)
105 (i64.const 1)))`,
106 /expression has type i64 but expected i32/);
107
108 wasmFailValidateText(
109 `(module
110 (func $arity-0-vs-1
111 (return_call 1))
112 (func (param i32)))`,
113 /popping value from empty stack/);
114
115 wasmFailValidateText(
116 `(module
117 (func $arity-0-vs-2
118 (return_call 1))
119 (func (param f64 i32)))`,
120 /popping value from empty stack/);
121
122 wasmFailValidateText(
123 `(module
124 (func $type-first-void-vs-num
125 (return_call 1 (nop) (i32.const 1)))
126 (func (param i32 i32)))`,
127 /popping value from empty stack/);
128
129 wasmFailValidateText(
130 `(module
131 (func $type-second-void-vs-num
132 (return_call 1 (i32.const 1) (nop)))
133 (func (param i32 i32)))`,
134 /popping value from empty stack/);
135
136 wasmFailValidateText(
137 `(module
138 (func $type-first-num-vs-num
139 (return_call 1 (f64.const 1) (i32.const 1)))
140 (func (param i32 f64)))`,
141 /expression has type i32 but expected f64/);
142
143 wasmFailValidateText(
144 `(module
145 (func $type-second-num-vs-num
146 (return_call 1 (i32.const 1) (f64.const 1)))
147 (func (param f64 i32)))`,
148 /expression has type f64 but expected i32/);
149
150 wasmFailValidateText(
151 `(module
152 (func $unbound-func
153 (return_call 1)))`,
154 /callee index out of range/);
155
156 wasmFailValidateText(
157 `(module
158 (func $large-func
159 (return_call 1012321300)))`,
160 /callee index out of range/);