OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
10 | 10 |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 | 12 |
13 #include "src/wasm/ast-decoder.h" | 13 #include "src/wasm/ast-decoder.h" |
14 #include "src/wasm/wasm-macro-gen.h" | 14 #include "src/wasm/wasm-macro-gen.h" |
15 #include "src/wasm/wasm-module.h" | 15 #include "src/wasm/wasm-module.h" |
16 #include "src/wasm/wasm-opcodes.h" | 16 #include "src/wasm/wasm-opcodes.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 namespace wasm { | 20 namespace wasm { |
21 | 21 |
22 #define B1(a) kExprBlock, a, kExprEnd | 22 #define B1(a) WASM_BLOCK(a) |
23 #define B2(a, b) kExprBlock, a, b, kExprEnd | 23 #define B2(a, b) WASM_BLOCK(a, b) |
24 #define B3(a, b, c) kExprBlock, a, b, c, kExprEnd | 24 #define B3(a, b, c) WASM_BLOCK(a, b, c) |
| 25 |
| 26 #define WASM_IF_OP kExprIf, kLocalVoid |
| 27 #define WASM_LOOP_OP kExprLoop, kLocalVoid |
25 | 28 |
26 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; | 29 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; |
27 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; | 30 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; |
28 static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; | 31 static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; |
| 32 static const byte kCodeTeeLocal0[] = {WASM_TEE_LOCAL(0, WASM_ZERO)}; |
29 | 33 |
30 static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; | 34 static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; |
31 static const MachineType machineTypes[] = { | 35 static const MachineType machineTypes[] = { |
32 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 36 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
33 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 37 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
34 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 38 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
35 MachineType::Float64()}; | 39 MachineType::Float64()}; |
36 | 40 |
37 static const WasmOpcode kInt32BinopOpcodes[] = { | 41 static const WasmOpcode kInt32BinopOpcodes[] = { |
38 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, | 42 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, |
39 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, | 43 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, |
40 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, | 44 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, |
41 kExprI32LeS, kExprI32LtU, kExprI32LeU}; | 45 kExprI32LeS, kExprI32LtU, kExprI32LeU}; |
42 | 46 |
43 #define WASM_BRV_IF_ZERO(depth, val) \ | 47 #define WASM_BRV_IF_ZERO(depth, val) \ |
44 val, WASM_ZERO, kExprBrIf, ARITY_1, static_cast<byte>(depth) | 48 val, WASM_ZERO, kExprBrIf, static_cast<byte>(depth) |
45 | 49 |
46 #define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x)) | 50 #define EXPECT_VERIFIES_C(sig, x) \ |
| 51 Verify(kSuccess, sigs.sig(), x, x + arraysize(x)) |
47 | 52 |
48 #define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x)) | 53 #define EXPECT_FAILURE_C(sig, x) Verify(kError, sigs.sig(), x, x + arraysize(x)) |
49 | 54 |
50 #define EXPECT_VERIFIES_INLINE(env, ...) \ | 55 #define EXPECT_VERIFIES_SC(sig, x) Verify(kSuccess, sig, x, x + arraysize(x)) |
| 56 |
| 57 #define EXPECT_FAILURE_SC(sig, x) Verify(kError, sig, x, x + arraysize(x)) |
| 58 |
| 59 #define EXPECT_VERIFIES_S(env, ...) \ |
51 do { \ | 60 do { \ |
52 static byte code[] = {__VA_ARGS__}; \ | 61 static byte code[] = {__VA_ARGS__}; \ |
53 Verify(kSuccess, env, code, code + arraysize(code)); \ | 62 Verify(kSuccess, env, code, code + arraysize(code)); \ |
54 } while (false) | 63 } while (false) |
55 | 64 |
56 #define EXPECT_FAILURE_INLINE(env, ...) \ | 65 #define EXPECT_FAILURE_S(env, ...) \ |
57 do { \ | 66 do { \ |
58 static byte code[] = {__VA_ARGS__}; \ | 67 static byte code[] = {__VA_ARGS__}; \ |
59 Verify(kError, env, code, code + arraysize(code)); \ | 68 Verify(kError, env, code, code + arraysize(code)); \ |
60 } while (false) | 69 } while (false) |
61 | 70 |
62 #define VERIFY(...) \ | 71 #define EXPECT_VERIFIES(sig, ...) \ |
63 do { \ | 72 do { \ |
64 static const byte code[] = {__VA_ARGS__}; \ | 73 static const byte code[] = {__VA_ARGS__}; \ |
65 Verify(kSuccess, sigs.v_i(), code, code + sizeof(code)); \ | 74 Verify(kSuccess, sigs.sig(), code, code + sizeof(code)); \ |
| 75 } while (false) |
| 76 |
| 77 #define EXPECT_FAILURE(sig, ...) \ |
| 78 do { \ |
| 79 static const byte code[] = {__VA_ARGS__}; \ |
| 80 Verify(kError, sigs.sig(), code, code + sizeof(code)); \ |
66 } while (false) | 81 } while (false) |
67 | 82 |
68 static bool old_eh_flag; | 83 static bool old_eh_flag; |
69 | 84 |
70 class AstDecoderTest : public TestWithZone { | 85 class AstDecoderTest : public TestWithZone { |
71 public: | 86 public: |
72 typedef std::pair<uint32_t, LocalType> LocalsDecl; | 87 typedef std::pair<uint32_t, LocalType> LocalsDecl; |
73 | 88 |
74 AstDecoderTest() : module(nullptr), local_decls(zone()) {} | 89 AstDecoderTest() : module(nullptr), local_decls(zone()) {} |
75 | 90 |
(...skipping 30 matching lines...) Expand all Loading... |
106 if (result.error_pt) str << ", pt = +" << pt; | 121 if (result.error_pt) str << ", pt = +" << pt; |
107 str << ", msg = " << result.error_msg.get(); | 122 str << ", msg = " << result.error_msg.get(); |
108 } else { | 123 } else { |
109 str << "Verification expected: " << expected << ", but got " | 124 str << "Verification expected: " << expected << ", but got " |
110 << result.error_code; | 125 << result.error_code; |
111 if (result.error_code != kSuccess) { | 126 if (result.error_code != kSuccess) { |
112 str << " pc = +" << pc; | 127 str << " pc = +" << pc; |
113 if (result.error_pt) str << ", pt = +" << pt; | 128 if (result.error_pt) str << ", pt = +" << pt; |
114 } | 129 } |
115 } | 130 } |
116 FATAL(str.str().c_str()); | 131 EXPECT_TRUE(false) << str.str().c_str(); |
117 } | 132 } |
118 } | 133 } |
119 | 134 |
120 void TestBinop(WasmOpcode opcode, FunctionSig* success) { | 135 void TestBinop(WasmOpcode opcode, FunctionSig* success) { |
121 // op(local[0], local[1]) | 136 // op(local[0], local[1]) |
122 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 137 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
123 EXPECT_VERIFIES(success, code); | 138 EXPECT_VERIFIES_SC(success, code); |
124 | 139 |
125 // Try all combinations of return and parameter types. | 140 // Try all combinations of return and parameter types. |
126 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 141 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
127 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 142 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
128 for (size_t k = 0; k < arraysize(kLocalTypes); k++) { | 143 for (size_t k = 0; k < arraysize(kLocalTypes); k++) { |
129 LocalType types[] = {kLocalTypes[i], kLocalTypes[j], kLocalTypes[k]}; | 144 LocalType types[] = {kLocalTypes[i], kLocalTypes[j], kLocalTypes[k]}; |
130 if (types[0] != success->GetReturn(0) || | 145 if (types[0] != success->GetReturn(0) || |
131 types[1] != success->GetParam(0) || | 146 types[1] != success->GetParam(0) || |
132 types[2] != success->GetParam(1)) { | 147 types[2] != success->GetParam(1)) { |
133 // Test signature mismatch. | 148 // Test signature mismatch. |
134 FunctionSig sig(1, 2, types); | 149 FunctionSig sig(1, 2, types); |
135 EXPECT_FAILURE(&sig, code); | 150 EXPECT_FAILURE_SC(&sig, code); |
136 } | 151 } |
137 } | 152 } |
138 } | 153 } |
139 } | 154 } |
140 } | 155 } |
141 | 156 |
142 void TestUnop(WasmOpcode opcode, FunctionSig* success) { | 157 void TestUnop(WasmOpcode opcode, FunctionSig* success) { |
143 TestUnop(opcode, success->GetReturn(), success->GetParam(0)); | 158 TestUnop(opcode, success->GetReturn(), success->GetParam(0)); |
144 } | 159 } |
145 | 160 |
146 void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) { | 161 void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) { |
147 // Return(op(local[0])) | 162 // Return(op(local[0])) |
148 byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))}; | 163 byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))}; |
149 { | 164 { |
150 LocalType types[] = {ret_type, param_type}; | 165 LocalType types[] = {ret_type, param_type}; |
151 FunctionSig sig(1, 1, types); | 166 FunctionSig sig(1, 1, types); |
152 EXPECT_VERIFIES(&sig, code); | 167 EXPECT_VERIFIES_SC(&sig, code); |
153 } | 168 } |
154 | 169 |
155 // Try all combinations of return and parameter types. | 170 // Try all combinations of return and parameter types. |
156 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 171 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
157 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 172 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
158 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; | 173 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; |
159 if (types[0] != ret_type || types[1] != param_type) { | 174 if (types[0] != ret_type || types[1] != param_type) { |
160 // Test signature mismatch. | 175 // Test signature mismatch. |
161 FunctionSig sig(1, 1, types); | 176 FunctionSig sig(1, 1, types); |
162 EXPECT_FAILURE(&sig, code); | 177 EXPECT_FAILURE_SC(&sig, code); |
163 } | 178 } |
164 } | 179 } |
165 } | 180 } |
166 } | 181 } |
167 }; | 182 }; |
168 | 183 |
169 TEST_F(AstDecoderTest, Int8Const) { | 184 TEST_F(AstDecoderTest, Int8Const) { |
170 byte code[] = {kExprI8Const, 0}; | 185 byte code[] = {kExprI8Const, 0}; |
171 for (int i = -128; i < 128; i++) { | 186 for (int i = -128; i < 128; i++) { |
172 code[1] = static_cast<byte>(i); | 187 code[1] = static_cast<byte>(i); |
173 EXPECT_VERIFIES(sigs.i_i(), code); | 188 EXPECT_VERIFIES_C(i_i, code); |
174 } | 189 } |
175 } | 190 } |
176 | 191 |
177 TEST_F(AstDecoderTest, EmptyFunction) { | 192 TEST_F(AstDecoderTest, EmptyFunction) { |
178 byte code[] = {0}; | 193 byte code[] = {0}; |
179 Verify(kSuccess, sigs.v_v(), code, code); | 194 Verify(kSuccess, sigs.v_v(), code, code); |
180 Verify(kError, sigs.i_i(), code, code); | 195 Verify(kError, sigs.i_i(), code, code); |
181 } | 196 } |
182 | 197 |
183 TEST_F(AstDecoderTest, IncompleteIf1) { | 198 TEST_F(AstDecoderTest, IncompleteIf1) { |
184 byte code[] = {kExprIf}; | 199 byte code[] = {kExprIf}; |
185 EXPECT_FAILURE(sigs.v_v(), code); | 200 EXPECT_FAILURE_C(v_v, code); |
186 EXPECT_FAILURE(sigs.i_i(), code); | 201 EXPECT_FAILURE_C(i_i, code); |
187 } | 202 } |
188 | 203 |
189 TEST_F(AstDecoderTest, Int8Const_fallthru) { | 204 TEST_F(AstDecoderTest, Int8Const_fallthru) { |
190 byte code[] = {kExprI8Const, 0, kExprI8Const, 1}; | 205 EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); |
191 EXPECT_VERIFIES(sigs.i_i(), code); | 206 } |
| 207 |
| 208 TEST_F(AstDecoderTest, Int8Const_fallthru2) { |
| 209 EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); |
192 } | 210 } |
193 | 211 |
194 TEST_F(AstDecoderTest, Int32Const) { | 212 TEST_F(AstDecoderTest, Int32Const) { |
195 const int kInc = 4498211; | 213 const int kInc = 4498211; |
196 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { | 214 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
197 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. | 215 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. |
198 byte code[] = {WASM_I32V(i)}; | 216 byte code[] = {WASM_I32V(i)}; |
199 EXPECT_VERIFIES(sigs.i_i(), code); | 217 EXPECT_VERIFIES_C(i_i, code); |
200 } | 218 } |
201 } | 219 } |
202 | 220 |
203 TEST_F(AstDecoderTest, Int8Const_fallthru2) { | |
204 byte code[] = {WASM_I8(0), WASM_I32V_4(0x1122334)}; | |
205 EXPECT_VERIFIES(sigs.i_i(), code); | |
206 } | |
207 | |
208 TEST_F(AstDecoderTest, Int64Const) { | 221 TEST_F(AstDecoderTest, Int64Const) { |
209 const int kInc = 4498211; | 222 const int kInc = 4498211; |
210 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { | 223 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
211 byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; | 224 byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; |
212 EXPECT_VERIFIES(sigs.l_l(), code); | 225 EXPECT_VERIFIES_C(l_l, code); |
213 } | 226 } |
214 } | 227 } |
215 | 228 |
216 TEST_F(AstDecoderTest, Float32Const) { | 229 TEST_F(AstDecoderTest, Float32Const) { |
217 byte code[] = {kExprF32Const, 0, 0, 0, 0}; | 230 byte code[] = {kExprF32Const, 0, 0, 0, 0}; |
218 float* ptr = reinterpret_cast<float*>(code + 1); | 231 float* ptr = reinterpret_cast<float*>(code + 1); |
219 for (int i = 0; i < 30; i++) { | 232 for (int i = 0; i < 30; i++) { |
220 WriteLittleEndianValue<float>(ptr, i * -7.75f); | 233 WriteLittleEndianValue<float>(ptr, i * -7.75f); |
221 EXPECT_VERIFIES(sigs.f_ff(), code); | 234 EXPECT_VERIFIES_C(f_ff, code); |
222 } | 235 } |
223 } | 236 } |
224 | 237 |
225 TEST_F(AstDecoderTest, Float64Const) { | 238 TEST_F(AstDecoderTest, Float64Const) { |
226 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; | 239 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; |
227 double* ptr = reinterpret_cast<double*>(code + 1); | 240 double* ptr = reinterpret_cast<double*>(code + 1); |
228 for (int i = 0; i < 30; i++) { | 241 for (int i = 0; i < 30; i++) { |
229 WriteLittleEndianValue<double>(ptr, i * 33.45); | 242 WriteLittleEndianValue<double>(ptr, i * 33.45); |
230 EXPECT_VERIFIES(sigs.d_dd(), code); | 243 EXPECT_VERIFIES_C(d_dd, code); |
231 } | 244 } |
232 } | 245 } |
233 | 246 |
234 TEST_F(AstDecoderTest, Int32Const_off_end) { | 247 TEST_F(AstDecoderTest, Int32Const_off_end) { |
235 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; | 248 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; |
236 | 249 |
237 for (int size = 1; size <= 4; size++) { | 250 for (int size = 1; size <= 4; size++) { |
238 Verify(kError, sigs.i_i(), code, code + size); | 251 Verify(kError, sigs.i_i(), code, code + size); |
239 } | 252 } |
240 } | 253 } |
241 | 254 |
242 TEST_F(AstDecoderTest, GetLocal0_param) { | 255 TEST_F(AstDecoderTest, GetLocal0_param) { |
243 EXPECT_VERIFIES(sigs.i_i(), kCodeGetLocal0); | 256 EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); |
244 } | 257 } |
245 | 258 |
246 TEST_F(AstDecoderTest, GetLocal0_local) { | 259 TEST_F(AstDecoderTest, GetLocal0_local) { |
247 AddLocals(kAstI32, 1); | 260 AddLocals(kAstI32, 1); |
248 EXPECT_VERIFIES(sigs.i_v(), kCodeGetLocal0); | 261 EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); |
249 } | 262 } |
250 | 263 |
251 TEST_F(AstDecoderTest, TooManyLocals) { | 264 TEST_F(AstDecoderTest, TooManyLocals) { |
252 AddLocals(kAstI32, 4034986500); | 265 AddLocals(kAstI32, 4034986500); |
253 EXPECT_FAILURE(sigs.i_v(), kCodeGetLocal0); | 266 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
254 } | 267 } |
255 | 268 |
256 TEST_F(AstDecoderTest, GetLocal0_param_n) { | 269 TEST_F(AstDecoderTest, GetLocal0_param_n) { |
257 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; | 270 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; |
258 | 271 |
259 for (size_t i = 0; i < arraysize(array); i++) { | 272 for (size_t i = 0; i < arraysize(array); i++) { |
260 EXPECT_VERIFIES(array[i], kCodeGetLocal0); | 273 EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); |
261 } | 274 } |
262 } | 275 } |
263 | 276 |
264 TEST_F(AstDecoderTest, GetLocalN_local) { | 277 TEST_F(AstDecoderTest, GetLocalN_local) { |
265 for (byte i = 1; i < 8; i++) { | 278 for (byte i = 1; i < 8; i++) { |
266 AddLocals(kAstI32, 1); | 279 AddLocals(kAstI32, 1); |
267 for (byte j = 0; j < i; j++) { | 280 for (byte j = 0; j < i; j++) { |
268 byte code[] = {kExprGetLocal, j}; | 281 byte code[] = {kExprGetLocal, j}; |
269 EXPECT_VERIFIES(sigs.i_v(), code); | 282 EXPECT_VERIFIES_C(i_v, code); |
270 } | 283 } |
271 } | 284 } |
272 } | 285 } |
273 | 286 |
274 TEST_F(AstDecoderTest, GetLocal0_fail_no_params) { | 287 TEST_F(AstDecoderTest, GetLocal0_fail_no_params) { |
275 EXPECT_FAILURE(sigs.i_v(), kCodeGetLocal0); | 288 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
276 } | 289 } |
277 | 290 |
278 TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) { | 291 TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) { |
279 EXPECT_FAILURE(sigs.i_i(), kCodeGetLocal1); | 292 EXPECT_FAILURE_C(i_i, kCodeGetLocal1); |
280 } | 293 } |
281 | 294 |
282 TEST_F(AstDecoderTest, GetLocal_off_end) { | 295 TEST_F(AstDecoderTest, GetLocal_off_end) { |
283 static const byte code[] = {kExprGetLocal}; | 296 static const byte code[] = {kExprGetLocal}; |
284 EXPECT_FAILURE(sigs.i_i(), code); | 297 EXPECT_FAILURE_C(i_i, code); |
285 } | 298 } |
286 | 299 |
287 TEST_F(AstDecoderTest, NumLocalBelowLimit) { | 300 TEST_F(AstDecoderTest, NumLocalBelowLimit) { |
288 AddLocals(kAstI32, kMaxNumWasmLocals - 1); | 301 AddLocals(kAstI32, kMaxNumWasmLocals - 1); |
289 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_NOP); | 302 EXPECT_VERIFIES(v_v, WASM_NOP); |
290 } | 303 } |
291 | 304 |
292 TEST_F(AstDecoderTest, NumLocalAtLimit) { | 305 TEST_F(AstDecoderTest, NumLocalAtLimit) { |
293 AddLocals(kAstI32, kMaxNumWasmLocals); | 306 AddLocals(kAstI32, kMaxNumWasmLocals); |
294 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_NOP); | 307 EXPECT_VERIFIES(v_v, WASM_NOP); |
295 } | 308 } |
296 | 309 |
297 TEST_F(AstDecoderTest, NumLocalAboveLimit) { | 310 TEST_F(AstDecoderTest, NumLocalAboveLimit) { |
298 AddLocals(kAstI32, kMaxNumWasmLocals + 1); | 311 AddLocals(kAstI32, kMaxNumWasmLocals + 1); |
299 EXPECT_FAILURE_INLINE(sigs.v_v(), WASM_NOP); | 312 EXPECT_FAILURE(v_v, WASM_NOP); |
300 } | 313 } |
301 | 314 |
302 TEST_F(AstDecoderTest, GetLocal_varint) { | 315 TEST_F(AstDecoderTest, GetLocal_varint) { |
303 const int kMaxLocals = kMaxNumWasmLocals; | 316 const int kMaxLocals = kMaxNumWasmLocals; |
304 AddLocals(kAstI32, kMaxLocals); | 317 AddLocals(kAstI32, kMaxLocals); |
305 | 318 |
306 for (int index = 0; index < kMaxLocals; index = index * 11 + 5) { | 319 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); |
307 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_1(index)); | 320 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); |
308 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_2(index)); | 321 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(888888)); |
309 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_3(index)); | 322 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(3999999)); |
310 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(index)); | 323 |
311 } | 324 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); |
312 | 325 |
313 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_5(kMaxLocals - 1)); | 326 EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
314 | 327 |
315 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals - 1)); | 328 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); |
316 EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals)); | 329 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); |
317 EXPECT_FAILURE_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals + 1)); | 330 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
318 | 331 |
319 EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals)); | 332 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); |
320 EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals + 1)); | 333 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
321 } | 334 } |
322 | 335 |
323 TEST_F(AstDecoderTest, Binops_off_end) { | 336 TEST_F(AstDecoderTest, Binops_off_end) { |
324 byte code1[] = {0}; // [opcode] | 337 byte code1[] = {0}; // [opcode] |
325 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 338 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
326 code1[0] = kInt32BinopOpcodes[i]; | 339 code1[0] = kInt32BinopOpcodes[i]; |
327 EXPECT_FAILURE(sigs.i_i(), code1); | 340 EXPECT_FAILURE_C(i_i, code1); |
328 } | 341 } |
329 | 342 |
330 byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] | 343 byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] |
331 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 344 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
332 code3[2] = kInt32BinopOpcodes[i]; | 345 code3[2] = kInt32BinopOpcodes[i]; |
333 EXPECT_FAILURE(sigs.i_i(), code3); | 346 EXPECT_FAILURE_C(i_i, code3); |
334 } | 347 } |
335 | 348 |
336 byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] | 349 byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] |
337 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 350 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
338 code4[2] = kInt32BinopOpcodes[i]; | 351 code4[2] = kInt32BinopOpcodes[i]; |
339 code4[3] = kInt32BinopOpcodes[i]; | 352 code4[3] = kInt32BinopOpcodes[i]; |
340 EXPECT_FAILURE(sigs.i_i(), code4); | 353 EXPECT_FAILURE_C(i_i, code4); |
341 } | 354 } |
342 } | 355 } |
343 | 356 |
344 TEST_F(AstDecoderTest, BinopsAcrossBlock1) { | 357 TEST_F(AstDecoderTest, BinopsAcrossBlock1) { |
345 static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add, | 358 static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add, |
346 kExprEnd}; | 359 kExprEnd}; |
347 EXPECT_FAILURE(sigs.i_i(), code); | 360 EXPECT_FAILURE_C(i_i, code); |
348 } | 361 } |
349 | 362 |
350 TEST_F(AstDecoderTest, BinopsAcrossBlock2) { | 363 TEST_F(AstDecoderTest, BinopsAcrossBlock2) { |
351 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add, | 364 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add, |
352 kExprEnd}; | 365 kExprEnd}; |
353 EXPECT_FAILURE(sigs.i_i(), code); | 366 EXPECT_FAILURE_C(i_i, code); |
354 } | 367 } |
355 | 368 |
356 TEST_F(AstDecoderTest, BinopsAcrossBlock3) { | 369 TEST_F(AstDecoderTest, BinopsAcrossBlock3) { |
357 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add, | 370 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add, |
358 kExprElse, kExprI32Add, kExprEnd}; | 371 kExprElse, kExprI32Add, kExprEnd}; |
359 EXPECT_FAILURE(sigs.i_i(), code); | 372 EXPECT_FAILURE_C(i_i, code); |
360 } | 373 } |
361 | 374 |
362 TEST_F(AstDecoderTest, Nop) { | 375 TEST_F(AstDecoderTest, Nop) { |
363 static const byte code[] = {kExprNop}; | 376 static const byte code[] = {kExprNop}; |
364 EXPECT_VERIFIES(sigs.v_v(), code); | 377 EXPECT_VERIFIES_C(v_v, code); |
| 378 } |
| 379 |
| 380 TEST_F(AstDecoderTest, SetLocal0_void) { |
| 381 EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO)); |
365 } | 382 } |
366 | 383 |
367 TEST_F(AstDecoderTest, SetLocal0_param) { | 384 TEST_F(AstDecoderTest, SetLocal0_param) { |
368 EXPECT_VERIFIES(sigs.i_i(), kCodeSetLocal0); | 385 EXPECT_FAILURE_C(i_i, kCodeSetLocal0); |
369 EXPECT_FAILURE(sigs.f_ff(), kCodeSetLocal0); | 386 EXPECT_FAILURE_C(f_ff, kCodeSetLocal0); |
370 EXPECT_FAILURE(sigs.d_dd(), kCodeSetLocal0); | 387 EXPECT_FAILURE_C(d_dd, kCodeSetLocal0); |
| 388 } |
| 389 |
| 390 TEST_F(AstDecoderTest, TeeLocal0_param) { |
| 391 EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); |
| 392 EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); |
| 393 EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); |
371 } | 394 } |
372 | 395 |
373 TEST_F(AstDecoderTest, SetLocal0_local) { | 396 TEST_F(AstDecoderTest, SetLocal0_local) { |
374 EXPECT_FAILURE(sigs.i_v(), kCodeSetLocal0); | 397 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
| 398 EXPECT_FAILURE_C(v_v, kCodeSetLocal0); |
375 AddLocals(kAstI32, 1); | 399 AddLocals(kAstI32, 1); |
376 EXPECT_VERIFIES(sigs.i_v(), kCodeSetLocal0); | 400 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
377 } | 401 EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); |
378 | 402 } |
379 TEST_F(AstDecoderTest, SetLocalN_local) { | 403 |
| 404 TEST_F(AstDecoderTest, TeeLocal0_local) { |
| 405 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); |
| 406 AddLocals(kAstI32, 1); |
| 407 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); |
| 408 } |
| 409 |
| 410 TEST_F(AstDecoderTest, TeeLocalN_local) { |
380 for (byte i = 1; i < 8; i++) { | 411 for (byte i = 1; i < 8; i++) { |
381 AddLocals(kAstI32, 1); | 412 AddLocals(kAstI32, 1); |
382 for (byte j = 0; j < i; j++) { | 413 for (byte j = 0; j < i; j++) { |
383 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_SET_LOCAL(j, WASM_I8(i))); | 414 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); |
| 415 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); |
384 } | 416 } |
385 } | 417 } |
386 } | 418 } |
387 | 419 |
388 TEST_F(AstDecoderTest, BlockN) { | 420 TEST_F(AstDecoderTest, BlockN) { |
389 const int kMaxSize = 200; | 421 const int kMaxSize = 200; |
390 byte buffer[kMaxSize + 2]; | 422 byte buffer[kMaxSize + 3]; |
391 | 423 |
392 for (int i = 0; i <= kMaxSize; i++) { | 424 for (int i = 0; i <= kMaxSize; i++) { |
393 memset(buffer, kExprNop, sizeof(buffer)); | 425 memset(buffer, kExprNop, sizeof(buffer)); |
394 buffer[0] = kExprBlock; | 426 buffer[0] = kExprBlock; |
395 buffer[i + 1] = kExprEnd; | 427 buffer[1] = kLocalVoid; |
396 Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 2); | 428 buffer[i + 2] = kExprEnd; |
397 } | 429 Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 3); |
398 } | 430 } |
| 431 } |
| 432 |
| 433 #define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd |
399 | 434 |
400 TEST_F(AstDecoderTest, Block0) { | 435 TEST_F(AstDecoderTest, Block0) { |
401 static const byte code[] = {kExprBlock, kExprEnd}; | 436 static const byte code[] = {WASM_EMPTY_BLOCK}; |
402 EXPECT_VERIFIES(sigs.v_v(), code); | 437 EXPECT_VERIFIES_C(v_v, code); |
403 EXPECT_FAILURE(sigs.i_i(), code); | 438 EXPECT_FAILURE_C(i_i, code); |
404 } | 439 } |
405 | 440 |
406 TEST_F(AstDecoderTest, Block0_fallthru1) { | 441 TEST_F(AstDecoderTest, Block0_fallthru1) { |
407 static const byte code[] = {kExprBlock, kExprBlock, kExprEnd, kExprEnd}; | 442 static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)}; |
408 EXPECT_VERIFIES(sigs.v_v(), code); | 443 EXPECT_VERIFIES_C(v_v, code); |
409 EXPECT_FAILURE(sigs.i_i(), code); | 444 EXPECT_FAILURE_C(i_i, code); |
410 } | 445 } |
411 | 446 |
412 TEST_F(AstDecoderTest, Block0Block0) { | 447 TEST_F(AstDecoderTest, Block0Block0) { |
413 static const byte code[] = {kExprBlock, kExprEnd, kExprBlock, kExprEnd}; | 448 static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; |
414 EXPECT_VERIFIES(sigs.v_v(), code); | 449 EXPECT_VERIFIES_C(v_v, code); |
415 EXPECT_FAILURE(sigs.i_i(), code); | 450 EXPECT_FAILURE_C(i_i, code); |
| 451 } |
| 452 |
| 453 TEST_F(AstDecoderTest, Block0_end) { |
| 454 EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd); |
416 } | 455 } |
417 | 456 |
418 TEST_F(AstDecoderTest, Block0_end_end) { | 457 TEST_F(AstDecoderTest, Block0_end_end) { |
419 static const byte code[] = {kExprBlock, kExprEnd, kExprEnd}; | 458 EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd); |
420 EXPECT_FAILURE(sigs.v_v(), code); | |
421 } | 459 } |
422 | 460 |
423 TEST_F(AstDecoderTest, Block1) { | 461 TEST_F(AstDecoderTest, Block1) { |
424 byte code[] = {B1(WASM_SET_LOCAL(0, WASM_ZERO))}; | 462 byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; |
425 EXPECT_VERIFIES(sigs.i_i(), code); | 463 EXPECT_VERIFIES_C(i_i, code); |
426 EXPECT_VERIFIES(sigs.v_i(), code); | 464 EXPECT_FAILURE_C(v_i, code); |
427 EXPECT_FAILURE(sigs.d_dd(), code); | 465 EXPECT_FAILURE_C(d_dd, code); |
| 466 EXPECT_FAILURE_C(i_f, code); |
| 467 EXPECT_FAILURE_C(i_d, code); |
428 } | 468 } |
429 | 469 |
430 TEST_F(AstDecoderTest, Block1_i) { | 470 TEST_F(AstDecoderTest, Block1_i) { |
431 byte code[] = {B1(WASM_ZERO)}; | 471 byte code[] = {WASM_BLOCK_I(WASM_ZERO)}; |
432 EXPECT_VERIFIES(sigs.i_i(), code); | 472 EXPECT_VERIFIES_C(i_i, code); |
433 EXPECT_FAILURE(sigs.f_ff(), code); | 473 EXPECT_FAILURE_C(f_ff, code); |
434 EXPECT_FAILURE(sigs.d_dd(), code); | 474 EXPECT_FAILURE_C(d_dd, code); |
435 EXPECT_FAILURE(sigs.l_ll(), code); | 475 EXPECT_FAILURE_C(l_ll, code); |
436 } | 476 } |
437 | 477 |
438 TEST_F(AstDecoderTest, Block1_f) { | 478 TEST_F(AstDecoderTest, Block1_f) { |
439 byte code[] = {B1(WASM_F32(0))}; | 479 byte code[] = {WASM_BLOCK_F(WASM_F32(0))}; |
440 EXPECT_FAILURE(sigs.i_i(), code); | 480 EXPECT_FAILURE_C(i_i, code); |
441 EXPECT_VERIFIES(sigs.f_ff(), code); | 481 EXPECT_VERIFIES_C(f_ff, code); |
442 EXPECT_FAILURE(sigs.d_dd(), code); | 482 EXPECT_FAILURE_C(d_dd, code); |
443 EXPECT_FAILURE(sigs.l_ll(), code); | 483 EXPECT_FAILURE_C(l_ll, code); |
444 } | 484 } |
445 | 485 |
446 TEST_F(AstDecoderTest, Block1_continue) { | 486 TEST_F(AstDecoderTest, Block1_continue) { |
447 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0))); | 487 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
448 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(1))); | |
449 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(2))); | |
450 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(3))); | |
451 } | 488 } |
452 | 489 |
453 TEST_F(AstDecoderTest, Block1_br) { | 490 TEST_F(AstDecoderTest, Block1_br) { |
454 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_1, DEPTH_0, | 491 EXPECT_VERIFIES(v_v, B1(WASM_BR(0))); |
455 kExprEnd); | 492 EXPECT_VERIFIES(v_v, B1(WASM_BR(1))); |
456 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_0, DEPTH_0, | 493 EXPECT_FAILURE(v_v, B1(WASM_BR(2))); |
457 kExprEnd); | |
458 } | 494 } |
459 | 495 |
460 TEST_F(AstDecoderTest, Block2_br) { | 496 TEST_F(AstDecoderTest, Block2_br) { |
461 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_NOP, WASM_BR(0))); | 497 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0))); |
462 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_NOP)); | 498 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP)); |
463 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_BR(0))); | 499 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0))); |
464 } | 500 } |
465 | 501 |
466 TEST_F(AstDecoderTest, Block2) { | 502 TEST_F(AstDecoderTest, Block2) { |
467 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 503 EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP)); |
468 B2(WASM_NOP, WASM_SET_LOCAL(0, WASM_ZERO))); | 504 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP)); |
469 EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); | 505 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO)); |
470 EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 506 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP)); |
471 WASM_SET_LOCAL(0, WASM_ZERO))); | 507 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)); |
472 } | 508 } |
473 | 509 |
474 TEST_F(AstDecoderTest, Block2b) { | 510 TEST_F(AstDecoderTest, Block2b) { |
475 byte code[] = {B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; | 511 byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; |
476 EXPECT_VERIFIES(sigs.i_i(), code); | 512 EXPECT_VERIFIES_C(i_i, code); |
477 EXPECT_FAILURE(sigs.v_v(), code); | 513 EXPECT_FAILURE_C(v_v, code); |
478 EXPECT_FAILURE(sigs.f_ff(), code); | 514 EXPECT_FAILURE_C(f_ff, code); |
479 } | 515 } |
480 | 516 |
481 TEST_F(AstDecoderTest, Block2_fallthru) { | 517 TEST_F(AstDecoderTest, Block2_fallthru) { |
482 EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 518 EXPECT_VERIFIES( |
483 WASM_SET_LOCAL(0, WASM_ZERO)), | 519 i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), |
484 WASM_I8(23)); | 520 WASM_I8(23)); |
485 } | 521 } |
486 | 522 |
487 TEST_F(AstDecoderTest, Block3) { | 523 TEST_F(AstDecoderTest, Block3) { |
488 EXPECT_VERIFIES_INLINE( | 524 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), |
489 sigs.i_i(), B3(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO), | 525 WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); |
490 WASM_I8(11))); | |
491 } | 526 } |
492 | 527 |
493 TEST_F(AstDecoderTest, Block5) { | 528 TEST_F(AstDecoderTest, Block5) { |
494 EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0))); | 529 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); |
495 | 530 |
496 EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 531 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); |
497 | 532 |
498 EXPECT_VERIFIES_INLINE( | 533 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
499 sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 534 |
500 | 535 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
501 EXPECT_VERIFIES_INLINE(sigs.v_i(), | 536 |
502 WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), | 537 EXPECT_FAILURE( |
503 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 538 v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
504 | 539 } |
505 EXPECT_VERIFIES_INLINE( | 540 |
506 sigs.v_i(), | 541 TEST_F(AstDecoderTest, BlockType) { |
507 WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), | 542 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0))); |
508 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 543 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0))); |
| 544 EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0))); |
| 545 EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0))); |
| 546 } |
| 547 |
| 548 TEST_F(AstDecoderTest, BlockType_fail) { |
| 549 EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0))); |
| 550 EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0))); |
| 551 EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1))); |
| 552 |
| 553 EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO)); |
| 554 EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0))); |
| 555 EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1))); |
| 556 |
| 557 EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO)); |
| 558 EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0))); |
| 559 EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1))); |
| 560 |
| 561 EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO)); |
| 562 EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0))); |
| 563 EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0))); |
509 } | 564 } |
510 | 565 |
511 TEST_F(AstDecoderTest, BlockF32) { | 566 TEST_F(AstDecoderTest, BlockF32) { |
512 static const byte code[] = {kExprBlock, kExprF32Const, 0, 0, 0, 0, kExprEnd}; | 567 static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)}; |
513 EXPECT_VERIFIES(sigs.f_ff(), code); | 568 EXPECT_VERIFIES_C(f_ff, code); |
514 EXPECT_FAILURE(sigs.i_i(), code); | 569 EXPECT_FAILURE_C(i_i, code); |
515 EXPECT_FAILURE(sigs.d_dd(), code); | 570 EXPECT_FAILURE_C(d_dd, code); |
516 } | 571 } |
517 | 572 |
518 TEST_F(AstDecoderTest, BlockN_off_end) { | 573 TEST_F(AstDecoderTest, BlockN_off_end) { |
519 byte code[] = {kExprBlock, kExprNop, kExprNop, kExprNop, kExprNop, kExprEnd}; | 574 byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)}; |
520 EXPECT_VERIFIES(sigs.v_v(), code); | 575 EXPECT_VERIFIES_C(v_v, code); |
521 for (size_t i = 1; i < arraysize(code); i++) { | 576 for (size_t i = 1; i < arraysize(code); i++) { |
522 Verify(kError, sigs.v_v(), code, code + i); | 577 Verify(kError, sigs.v_v(), code, code + i); |
523 } | 578 } |
524 } | 579 } |
525 | 580 |
526 TEST_F(AstDecoderTest, Block2_continue) { | 581 TEST_F(AstDecoderTest, Block2_continue) { |
527 static const byte code[] = {kExprBlock, kExprBr, ARITY_0, | 582 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0))); |
528 DEPTH_1, kExprNop, kExprEnd}; | 583 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1))); |
529 EXPECT_FAILURE(sigs.v_v(), code); | 584 EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2))); |
| 585 } |
| 586 |
| 587 TEST_F(AstDecoderTest, Block3_continue) { |
| 588 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); |
| 589 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); |
| 590 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); |
| 591 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); |
530 } | 592 } |
531 | 593 |
532 TEST_F(AstDecoderTest, NestedBlock_return) { | 594 TEST_F(AstDecoderTest, NestedBlock_return) { |
533 EXPECT_VERIFIES_INLINE(sigs.i_i(), B1(B1(WASM_RETURN1(WASM_ZERO)))); | 595 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); |
534 } | |
535 | |
536 TEST_F(AstDecoderTest, BlockBinop) { | |
537 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(B1(WASM_I8(1)), WASM_I8(2))); | |
538 } | 596 } |
539 | 597 |
540 TEST_F(AstDecoderTest, BlockBrBinop) { | 598 TEST_F(AstDecoderTest, BlockBrBinop) { |
541 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 599 EXPECT_VERIFIES( |
542 WASM_I32_AND(B1(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); | 600 i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); |
543 } | 601 } |
544 | 602 |
545 TEST_F(AstDecoderTest, If_empty1) { | 603 TEST_F(AstDecoderTest, If_empty1) { |
546 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprEnd); | 604 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); |
547 } | 605 } |
548 | 606 |
549 TEST_F(AstDecoderTest, If_empty2) { | 607 TEST_F(AstDecoderTest, If_empty2) { |
550 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprElse, kExprEnd); | 608 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); |
551 } | 609 } |
552 | 610 |
553 TEST_F(AstDecoderTest, If_empty3) { | 611 TEST_F(AstDecoderTest, If_empty3) { |
554 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, WASM_ZERO, kExprElse, | 612 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); |
555 kExprEnd); | 613 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); |
556 } | 614 } |
557 | 615 |
558 TEST_F(AstDecoderTest, If_empty4) { | 616 TEST_F(AstDecoderTest, If_empty4) { |
559 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprElse, WASM_ZERO, | 617 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); |
560 kExprEnd); | 618 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); |
561 } | 619 } |
562 | 620 |
563 TEST_F(AstDecoderTest, If_empty_stack) { | 621 TEST_F(AstDecoderTest, If_empty_stack) { |
564 byte code[] = {kExprIf}; | 622 byte code[] = {kExprIf}; |
565 EXPECT_FAILURE(sigs.v_v(), code); | 623 EXPECT_FAILURE_C(v_v, code); |
566 EXPECT_FAILURE(sigs.i_i(), code); | 624 EXPECT_FAILURE_C(i_i, code); |
567 } | 625 } |
568 | 626 |
569 TEST_F(AstDecoderTest, If_incomplete1) { | 627 TEST_F(AstDecoderTest, If_incomplete1) { |
570 byte code[] = {kExprI8Const, 0, kExprIf}; | 628 byte code[] = {kExprI8Const, 0, kExprIf}; |
571 EXPECT_FAILURE(sigs.v_v(), code); | 629 EXPECT_FAILURE_C(v_v, code); |
572 EXPECT_FAILURE(sigs.i_i(), code); | 630 EXPECT_FAILURE_C(i_i, code); |
573 } | 631 } |
574 | 632 |
575 TEST_F(AstDecoderTest, If_incomplete2) { | 633 TEST_F(AstDecoderTest, If_incomplete2) { |
576 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; | 634 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; |
577 EXPECT_FAILURE(sigs.v_v(), code); | 635 EXPECT_FAILURE_C(v_v, code); |
578 EXPECT_FAILURE(sigs.i_i(), code); | 636 EXPECT_FAILURE_C(i_i, code); |
579 } | 637 } |
580 | 638 |
581 TEST_F(AstDecoderTest, If_else_else) { | 639 TEST_F(AstDecoderTest, If_else_else) { |
582 byte code[] = {kExprI8Const, 0, kExprIf, kExprElse, kExprElse, kExprEnd}; | 640 byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; |
583 EXPECT_FAILURE(sigs.v_v(), code); | 641 EXPECT_FAILURE_C(v_v, code); |
584 EXPECT_FAILURE(sigs.i_i(), code); | 642 EXPECT_FAILURE_C(i_i, code); |
585 } | 643 } |
586 | 644 |
587 TEST_F(AstDecoderTest, IfEmpty) { | 645 TEST_F(AstDecoderTest, IfEmpty) { |
588 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0, kExprIf, kExprEnd); | 646 EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); |
589 } | 647 } |
590 | 648 |
591 TEST_F(AstDecoderTest, IfSet) { | 649 TEST_F(AstDecoderTest, IfSet) { |
592 EXPECT_VERIFIES_INLINE( | 650 EXPECT_VERIFIES(v_i, |
593 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); | 651 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); |
594 EXPECT_VERIFIES_INLINE( | 652 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), |
595 sigs.v_i(), | 653 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
596 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); | |
597 } | 654 } |
598 | 655 |
599 TEST_F(AstDecoderTest, IfElseEmpty) { | 656 TEST_F(AstDecoderTest, IfElseEmpty) { |
600 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprIf, kExprElse, | 657 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd); |
601 kExprEnd); | 658 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
602 EXPECT_VERIFIES_INLINE(sigs.v_i(), | |
603 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | |
604 } | 659 } |
605 | 660 |
606 TEST_F(AstDecoderTest, IfElseUnreachable1) { | 661 TEST_F(AstDecoderTest, IfElseUnreachable1) { |
607 EXPECT_VERIFIES_INLINE( | 662 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, |
608 sigs.i_i(), | 663 WASM_GET_LOCAL(0))); |
609 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))); | 664 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
610 EXPECT_VERIFIES_INLINE( | 665 WASM_UNREACHABLE)); |
611 sigs.i_i(), | |
612 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); | |
613 } | 666 } |
614 | 667 |
615 TEST_F(AstDecoderTest, IfElseUnreachable2) { | 668 TEST_F(AstDecoderTest, IfElseUnreachable2) { |
616 static const byte code[] = { | 669 static const byte code[] = { |
617 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; | 670 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
618 | 671 |
619 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 672 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
620 LocalType types[] = {kAstI32, kLocalTypes[i]}; | 673 LocalType types[] = {kAstI32, kLocalTypes[i]}; |
621 FunctionSig sig(1, 1, types); | 674 FunctionSig sig(1, 1, types); |
622 | 675 |
623 if (kLocalTypes[i] == kAstI32) { | 676 if (kLocalTypes[i] == kAstI32) { |
624 EXPECT_VERIFIES(&sig, code); | 677 EXPECT_VERIFIES_SC(&sig, code); |
625 } else { | 678 } else { |
626 EXPECT_FAILURE(&sig, code); | 679 EXPECT_FAILURE_SC(&sig, code); |
627 } | 680 } |
628 } | 681 } |
629 } | 682 } |
630 | 683 |
631 TEST_F(AstDecoderTest, IfBreak) { | 684 TEST_F(AstDecoderTest, IfBreak) { |
632 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); | 685 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); |
633 EXPECT_FAILURE_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); | 686 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); |
| 687 EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); |
634 } | 688 } |
635 | 689 |
636 TEST_F(AstDecoderTest, IfElseBreak) { | 690 TEST_F(AstDecoderTest, IfElseBreak) { |
637 EXPECT_VERIFIES_INLINE(sigs.v_i(), | 691 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); |
638 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); | 692 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); |
639 EXPECT_FAILURE_INLINE(sigs.v_i(), | 693 EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); |
640 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); | |
641 } | 694 } |
642 | 695 |
643 TEST_F(AstDecoderTest, Block_else) { | 696 TEST_F(AstDecoderTest, Block_else) { |
644 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; | 697 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; |
645 EXPECT_FAILURE(sigs.v_v(), code); | 698 EXPECT_FAILURE_C(v_v, code); |
646 EXPECT_FAILURE(sigs.i_i(), code); | 699 EXPECT_FAILURE_C(i_i, code); |
647 } | 700 } |
648 | 701 |
649 TEST_F(AstDecoderTest, IfNop) { | 702 TEST_F(AstDecoderTest, IfNop) { |
650 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 703 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
651 } | 704 } |
652 | 705 |
653 TEST_F(AstDecoderTest, IfNopElseNop) { | 706 TEST_F(AstDecoderTest, IfNopElseNop) { |
654 EXPECT_VERIFIES_INLINE(sigs.v_i(), | 707 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
655 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | |
656 } | 708 } |
657 | 709 |
658 TEST_F(AstDecoderTest, If_end_end) { | 710 TEST_F(AstDecoderTest, If_end_end) { |
659 static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprEnd, kExprEnd}; | 711 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; |
660 EXPECT_FAILURE(sigs.v_i(), code); | 712 EXPECT_VERIFIES_C(v_i, code); |
661 } | 713 } |
662 | 714 |
663 TEST_F(AstDecoderTest, If_falloff) { | 715 TEST_F(AstDecoderTest, If_end_end_end) { |
| 716 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, |
| 717 kExprEnd, kExprEnd, kExprEnd}; |
| 718 EXPECT_FAILURE_C(v_i, code); |
| 719 } |
| 720 |
| 721 TEST_F(AstDecoderTest, If_falloff1) { |
664 static const byte code[] = {kExprGetLocal, 0, kExprIf}; | 722 static const byte code[] = {kExprGetLocal, 0, kExprIf}; |
665 EXPECT_FAILURE(sigs.v_i(), code); | 723 EXPECT_FAILURE_C(v_i, code); |
| 724 } |
| 725 |
| 726 TEST_F(AstDecoderTest, If_falloff2) { |
| 727 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP}; |
| 728 EXPECT_FAILURE_C(v_i, code); |
666 } | 729 } |
667 | 730 |
668 TEST_F(AstDecoderTest, IfElse_falloff) { | 731 TEST_F(AstDecoderTest, IfElse_falloff) { |
669 static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprNop, kExprElse}; | 732 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop, |
670 EXPECT_FAILURE(sigs.v_i(), code); | 733 kExprElse}; |
| 734 EXPECT_FAILURE_C(v_i, code); |
671 } | 735 } |
672 | 736 |
673 TEST_F(AstDecoderTest, IfElseNop) { | 737 TEST_F(AstDecoderTest, IfElseNop) { |
674 EXPECT_VERIFIES_INLINE( | 738 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), |
675 sigs.v_i(), | 739 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
676 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); | |
677 } | 740 } |
678 | 741 |
679 TEST_F(AstDecoderTest, IfBlock1) { | 742 TEST_F(AstDecoderTest, IfBlock1) { |
680 EXPECT_VERIFIES_INLINE( | 743 EXPECT_VERIFIES( |
681 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), | 744 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)), |
682 B1(WASM_SET_LOCAL(0, WASM_ZERO)), WASM_NOP)); | 745 WASM_NOP)); |
683 } | 746 } |
684 | 747 |
685 TEST_F(AstDecoderTest, IfBlock1b) { | 748 TEST_F(AstDecoderTest, IfBlock1b) { |
686 EXPECT_VERIFIES_INLINE( | 749 EXPECT_VERIFIES(v_i, |
687 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); | 750 WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); |
688 } | 751 } |
689 | 752 |
690 TEST_F(AstDecoderTest, IfBlock2a) { | 753 TEST_F(AstDecoderTest, IfBlock2a) { |
691 EXPECT_VERIFIES_INLINE( | 754 EXPECT_VERIFIES(v_i, |
692 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 755 WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
693 WASM_SET_LOCAL(0, WASM_ZERO)))); | 756 WASM_SET_LOCAL(0, WASM_ZERO)))); |
694 } | 757 } |
695 | 758 |
696 TEST_F(AstDecoderTest, IfBlock2b) { | 759 TEST_F(AstDecoderTest, IfBlock2b) { |
697 EXPECT_VERIFIES_INLINE( | 760 EXPECT_VERIFIES( |
698 sigs.v_i(), | 761 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
699 WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 762 WASM_SET_LOCAL(0, WASM_ZERO)), |
700 WASM_SET_LOCAL(0, WASM_ZERO)), | 763 WASM_NOP)); |
701 WASM_NOP)); | |
702 } | 764 } |
703 | 765 |
704 TEST_F(AstDecoderTest, IfElseSet) { | 766 TEST_F(AstDecoderTest, IfElseSet) { |
705 EXPECT_VERIFIES_INLINE( | 767 EXPECT_VERIFIES(v_i, |
706 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), | 768 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), |
707 WASM_SET_LOCAL(0, WASM_I8(1)))); | 769 WASM_SET_LOCAL(0, WASM_I8(1)))); |
708 } | 770 } |
709 | 771 |
710 TEST_F(AstDecoderTest, Loop0) { | 772 TEST_F(AstDecoderTest, Loop0) { EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); } |
711 static const byte code[] = {kExprLoop, kExprEnd}; | |
712 EXPECT_VERIFIES(sigs.v_v(), code); | |
713 } | |
714 | 773 |
715 TEST_F(AstDecoderTest, Loop1) { | 774 TEST_F(AstDecoderTest, Loop1) { |
716 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; | 775 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; |
717 EXPECT_VERIFIES(sigs.v_i(), code); | 776 EXPECT_VERIFIES_C(v_i, code); |
718 EXPECT_FAILURE(sigs.v_v(), code); | 777 EXPECT_FAILURE_C(v_v, code); |
719 EXPECT_FAILURE(sigs.f_ff(), code); | 778 EXPECT_FAILURE_C(f_ff, code); |
720 } | 779 } |
721 | 780 |
722 TEST_F(AstDecoderTest, Loop2) { | 781 TEST_F(AstDecoderTest, Loop2) { |
723 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), | 782 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), |
724 WASM_SET_LOCAL(0, WASM_ZERO))); | 783 WASM_SET_LOCAL(0, WASM_ZERO))); |
725 } | 784 } |
726 | 785 |
727 TEST_F(AstDecoderTest, Loop1_continue) { | 786 TEST_F(AstDecoderTest, Loop1_continue) { |
728 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0))); | 787 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
729 } | 788 } |
730 | 789 |
731 TEST_F(AstDecoderTest, Loop1_break) { | 790 TEST_F(AstDecoderTest, Loop1_break) { |
732 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1))); | 791 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1))); |
733 } | 792 } |
734 | 793 |
735 TEST_F(AstDecoderTest, Loop2_continue) { | 794 TEST_F(AstDecoderTest, Loop2_continue) { |
736 EXPECT_VERIFIES_INLINE(sigs.v_i(), | 795 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); |
737 WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); | |
738 } | 796 } |
739 | 797 |
740 TEST_F(AstDecoderTest, Loop2_break) { | 798 TEST_F(AstDecoderTest, Loop2_break) { |
741 EXPECT_VERIFIES_INLINE(sigs.v_i(), | 799 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); |
742 WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); | 800 } |
743 } | 801 |
744 | 802 TEST_F(AstDecoderTest, InfiniteLoop) { |
745 TEST_F(AstDecoderTest, ExprLoop0) { | 803 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0))); |
746 static const byte code[] = {kExprLoop, kExprEnd}; | 804 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
747 EXPECT_VERIFIES(sigs.v_v(), code); | 805 } |
748 } | 806 |
749 | 807 TEST_F(AstDecoderTest, Loop2_unreachable) { |
750 TEST_F(AstDecoderTest, ExprLoop1a) { | 808 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP)); |
751 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(0, WASM_ZERO))); | 809 } |
752 } | 810 |
753 | 811 TEST_F(AstDecoderTest, LoopType) { |
754 TEST_F(AstDecoderTest, ExprLoop1b) { | 812 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); |
755 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); | 813 EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); |
756 EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); | 814 EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); |
757 } | 815 EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); |
758 | 816 } |
759 TEST_F(AstDecoderTest, ExprLoop2_unreachable) { | 817 |
760 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BR(0), WASM_NOP)); | 818 TEST_F(AstDecoderTest, LoopType_void) { |
| 819 EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO)); |
| 820 EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0))); |
| 821 EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0))); |
| 822 EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1))); |
| 823 } |
| 824 |
| 825 TEST_F(AstDecoderTest, LoopType_fail) { |
| 826 EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0))); |
| 827 EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0))); |
| 828 EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1))); |
| 829 |
| 830 EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO)); |
| 831 EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0))); |
| 832 EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1))); |
| 833 |
| 834 EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO)); |
| 835 EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0))); |
| 836 EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1))); |
| 837 |
| 838 EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO)); |
| 839 EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0))); |
| 840 EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0))); |
761 } | 841 } |
762 | 842 |
763 TEST_F(AstDecoderTest, ReturnVoid1) { | 843 TEST_F(AstDecoderTest, ReturnVoid1) { |
764 static const byte code[] = {kExprNop}; | 844 static const byte code[] = {kExprNop}; |
765 EXPECT_VERIFIES(sigs.v_v(), code); | 845 EXPECT_VERIFIES_C(v_v, code); |
766 EXPECT_FAILURE(sigs.i_i(), code); | 846 EXPECT_FAILURE_C(i_i, code); |
767 EXPECT_FAILURE(sigs.i_f(), code); | 847 EXPECT_FAILURE_C(i_f, code); |
768 } | 848 } |
769 | 849 |
770 TEST_F(AstDecoderTest, ReturnVoid2) { | 850 TEST_F(AstDecoderTest, ReturnVoid2) { |
771 static const byte code[] = {kExprBlock, kExprBr, ARITY_0, DEPTH_0, kExprEnd}; | 851 static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; |
772 EXPECT_VERIFIES(sigs.v_v(), code); | 852 EXPECT_VERIFIES_C(v_v, code); |
773 EXPECT_FAILURE(sigs.i_i(), code); | 853 EXPECT_FAILURE_C(i_i, code); |
774 EXPECT_FAILURE(sigs.i_f(), code); | 854 EXPECT_FAILURE_C(i_f, code); |
775 } | 855 } |
776 | 856 |
777 TEST_F(AstDecoderTest, ReturnVoid3) { | 857 TEST_F(AstDecoderTest, ReturnVoid3) { |
778 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI8Const, 0); | 858 EXPECT_FAILURE(v_v, kExprI8Const, 0); |
779 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI32Const, 0, 0, 0, 0); | 859 EXPECT_FAILURE(v_v, kExprI32Const, 0); |
780 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0); | 860 EXPECT_FAILURE(v_v, kExprI64Const, 0); |
781 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF32Const, 0, 0, 0, 0); | 861 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); |
782 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); | 862 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); |
783 | 863 |
784 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0); | 864 EXPECT_FAILURE(v_i, kExprGetLocal, 0); |
785 } | 865 } |
786 | 866 |
787 TEST_F(AstDecoderTest, Unreachable1) { | 867 TEST_F(AstDecoderTest, Unreachable1) { |
788 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable); | 868 EXPECT_VERIFIES(v_v, kExprUnreachable); |
789 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable); | 869 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); |
790 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_UNREACHABLE, WASM_ZERO)); | 870 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); |
791 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_ZERO)); | 871 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO)); |
792 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); | 872 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); |
793 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0), WASM_ZERO)); | 873 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); |
794 } | 874 } |
795 | 875 |
796 TEST_F(AstDecoderTest, Unreachable_binop) { | 876 TEST_F(AstDecoderTest, Unreachable_binop) { |
797 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); | 877 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); |
798 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); | 878 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); |
799 } | 879 } |
800 | 880 |
801 TEST_F(AstDecoderTest, Unreachable_select) { | 881 TEST_F(AstDecoderTest, Unreachable_select) { |
802 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 882 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); |
803 WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); | 883 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); |
804 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 884 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); |
805 WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); | |
806 EXPECT_VERIFIES_INLINE(sigs.i_i(), | |
807 WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); | |
808 } | 885 } |
809 | 886 |
810 TEST_F(AstDecoderTest, If1) { | 887 TEST_F(AstDecoderTest, If1) { |
811 EXPECT_VERIFIES_INLINE( | 888 EXPECT_VERIFIES(i_i, |
812 sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); | 889 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); |
813 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), | 890 EXPECT_VERIFIES( |
814 WASM_GET_LOCAL(0))); | 891 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); |
815 EXPECT_VERIFIES_INLINE( | 892 EXPECT_VERIFIES( |
816 sigs.i_i(), | 893 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); |
817 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); | |
818 } | 894 } |
819 | 895 |
820 TEST_F(AstDecoderTest, If_off_end) { | 896 TEST_F(AstDecoderTest, If_off_end) { |
821 static const byte kCode[] = { | 897 static const byte kCode[] = { |
822 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; | 898 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; |
823 for (size_t len = 3; len < arraysize(kCode); len++) { | 899 for (size_t len = 3; len < arraysize(kCode); len++) { |
824 Verify(kError, sigs.i_i(), kCode, kCode + len); | 900 Verify(kError, sigs.i_i(), kCode, kCode + len); |
825 } | 901 } |
826 } | 902 } |
827 | 903 |
828 TEST_F(AstDecoderTest, If_type1) { | 904 TEST_F(AstDecoderTest, If_type1) { |
829 // float|double ? 1 : 2 | 905 // float|double ? 1 : 2 |
830 static const byte kCode[] = { | 906 static const byte kCode[] = { |
831 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; | 907 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; |
832 EXPECT_VERIFIES(sigs.i_i(), kCode); | 908 EXPECT_VERIFIES_C(i_i, kCode); |
833 EXPECT_FAILURE(sigs.i_f(), kCode); | 909 EXPECT_FAILURE_C(i_f, kCode); |
834 EXPECT_FAILURE(sigs.i_d(), kCode); | 910 EXPECT_FAILURE_C(i_d, kCode); |
835 } | 911 } |
836 | 912 |
837 TEST_F(AstDecoderTest, If_type2) { | 913 TEST_F(AstDecoderTest, If_type2) { |
838 // 1 ? float|double : 2 | 914 // 1 ? float|double : 2 |
839 static const byte kCode[] = { | 915 static const byte kCode[] = { |
840 WASM_IF_ELSE(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; | 916 WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; |
841 EXPECT_VERIFIES(sigs.i_i(), kCode); | 917 EXPECT_VERIFIES_C(i_i, kCode); |
842 EXPECT_FAILURE(sigs.i_f(), kCode); | 918 EXPECT_FAILURE_C(i_f, kCode); |
843 EXPECT_FAILURE(sigs.i_d(), kCode); | 919 EXPECT_FAILURE_C(i_d, kCode); |
844 } | 920 } |
845 | 921 |
846 TEST_F(AstDecoderTest, If_type3) { | 922 TEST_F(AstDecoderTest, If_type3) { |
847 // stmt ? 0 : 1 | 923 // stmt ? 0 : 1 |
848 static const byte kCode[] = {WASM_IF_ELSE(WASM_NOP, WASM_I8(0), WASM_I8(1))}; | 924 static const byte kCode[] = { |
849 EXPECT_FAILURE(sigs.i_i(), kCode); | 925 WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; |
850 EXPECT_FAILURE(sigs.i_f(), kCode); | 926 EXPECT_FAILURE_C(i_i, kCode); |
851 EXPECT_FAILURE(sigs.i_d(), kCode); | 927 EXPECT_FAILURE_C(i_f, kCode); |
| 928 EXPECT_FAILURE_C(i_d, kCode); |
852 } | 929 } |
853 | 930 |
854 TEST_F(AstDecoderTest, If_type4) { | 931 TEST_F(AstDecoderTest, If_type4) { |
855 // 0 ? stmt : 1 | 932 // 0 ? stmt : 1 |
856 static const byte kCode[] = { | 933 static const byte kCode[] = { |
857 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; | 934 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; |
858 EXPECT_FAILURE(sigs.i_i(), kCode); | 935 EXPECT_FAILURE_C(i_i, kCode); |
859 EXPECT_FAILURE(sigs.i_f(), kCode); | 936 EXPECT_FAILURE_C(i_f, kCode); |
860 EXPECT_FAILURE(sigs.i_d(), kCode); | 937 EXPECT_FAILURE_C(i_d, kCode); |
861 } | 938 } |
862 | 939 |
863 TEST_F(AstDecoderTest, If_type5) { | 940 TEST_F(AstDecoderTest, If_type5) { |
864 // 0 ? 1 : stmt | 941 // 0 ? 1 : stmt |
865 static const byte kCode[] = {WASM_IF_ELSE(WASM_ZERO, WASM_I8(1), WASM_NOP)}; | 942 static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; |
866 EXPECT_FAILURE(sigs.i_i(), kCode); | 943 EXPECT_FAILURE_C(i_i, kCode); |
867 EXPECT_FAILURE(sigs.i_f(), kCode); | 944 EXPECT_FAILURE_C(i_f, kCode); |
868 EXPECT_FAILURE(sigs.i_d(), kCode); | 945 EXPECT_FAILURE_C(i_d, kCode); |
869 } | 946 } |
870 | 947 |
871 TEST_F(AstDecoderTest, Int64Local_param) { | 948 TEST_F(AstDecoderTest, Int64Local_param) { |
872 EXPECT_VERIFIES(sigs.l_l(), kCodeGetLocal0); | 949 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); |
873 } | 950 } |
874 | 951 |
875 TEST_F(AstDecoderTest, Int64Locals) { | 952 TEST_F(AstDecoderTest, Int64Locals) { |
876 for (byte i = 1; i < 8; i++) { | 953 for (byte i = 1; i < 8; i++) { |
877 AddLocals(kAstI64, 1); | 954 AddLocals(kAstI64, 1); |
878 for (byte j = 0; j < i; j++) { | 955 for (byte j = 0; j < i; j++) { |
879 EXPECT_VERIFIES_INLINE(sigs.l_v(), WASM_GET_LOCAL(j)); | 956 EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); |
880 } | 957 } |
881 } | 958 } |
882 } | 959 } |
883 | 960 |
884 TEST_F(AstDecoderTest, Int32Binops) { | 961 TEST_F(AstDecoderTest, Int32Binops) { |
885 TestBinop(kExprI32Add, sigs.i_ii()); | 962 TestBinop(kExprI32Add, sigs.i_ii()); |
886 TestBinop(kExprI32Sub, sigs.i_ii()); | 963 TestBinop(kExprI32Sub, sigs.i_ii()); |
887 TestBinop(kExprI32Mul, sigs.i_ii()); | 964 TestBinop(kExprI32Mul, sigs.i_ii()); |
888 TestBinop(kExprI32DivS, sigs.i_ii()); | 965 TestBinop(kExprI32DivS, sigs.i_ii()); |
889 TestBinop(kExprI32DivU, sigs.i_ii()); | 966 TestBinop(kExprI32DivU, sigs.i_ii()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); | 1008 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); |
932 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); | 1009 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); |
933 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); | 1010 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); |
934 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); | 1011 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); |
935 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); | 1012 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); |
936 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); | 1013 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); |
937 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); | 1014 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); |
938 } | 1015 } |
939 | 1016 |
940 TEST_F(AstDecoderTest, MacrosStmt) { | 1017 TEST_F(AstDecoderTest, MacrosStmt) { |
941 VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348))); | 1018 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
942 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); | 1019 EXPECT_VERIFIES( |
943 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 1020 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); |
944 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 1021 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
945 VERIFY(WASM_NOP); | 1022 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
946 VERIFY(B1(WASM_NOP)); | 1023 EXPECT_VERIFIES(v_v, WASM_NOP); |
947 VERIFY(WASM_LOOP(WASM_NOP)); | 1024 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); |
948 VERIFY(WASM_LOOP(WASM_BREAK(0))); | 1025 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); |
949 VERIFY(WASM_LOOP(WASM_CONTINUE(0))); | 1026 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
950 } | |
951 | |
952 TEST_F(AstDecoderTest, MacrosBreak) { | |
953 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BREAK(0))); | |
954 | |
955 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BREAKV(0, WASM_ZERO))); | |
956 EXPECT_VERIFIES_INLINE(sigs.l_l(), WASM_LOOP(WASM_BREAKV(0, WASM_I64V_1(0)))); | |
957 EXPECT_VERIFIES_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BREAKV(0, WASM_F32(0.0)))); | |
958 EXPECT_VERIFIES_INLINE(sigs.d_dd(), WASM_LOOP(WASM_BREAKV(0, WASM_F64(0.0)))); | |
959 } | 1027 } |
960 | 1028 |
961 TEST_F(AstDecoderTest, MacrosContinue) { | 1029 TEST_F(AstDecoderTest, MacrosContinue) { |
962 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_CONTINUE(0))); | 1030 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); |
963 } | 1031 } |
964 | 1032 |
965 TEST_F(AstDecoderTest, MacrosVariadic) { | 1033 TEST_F(AstDecoderTest, MacrosVariadic) { |
966 VERIFY(B2(WASM_NOP, WASM_NOP)); | 1034 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP)); |
967 VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP)); | 1035 EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP)); |
968 VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP)); | 1036 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP)); |
969 VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); | 1037 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); |
970 } | 1038 } |
971 | 1039 |
972 TEST_F(AstDecoderTest, MacrosNestedBlocks) { | 1040 TEST_F(AstDecoderTest, MacrosNestedBlocks) { |
973 VERIFY(B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); | 1041 EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); |
974 VERIFY(B3(WASM_NOP, // -- | 1042 EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- |
975 B2(WASM_NOP, WASM_NOP), // -- | 1043 B2(WASM_NOP, WASM_NOP), // -- |
976 B2(WASM_NOP, WASM_NOP))); // -- | 1044 B2(WASM_NOP, WASM_NOP))); // -- |
977 VERIFY(B1(B1(B2(WASM_NOP, WASM_NOP)))); | 1045 EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); |
978 } | 1046 } |
979 | 1047 |
980 TEST_F(AstDecoderTest, MultipleReturn) { | 1048 TEST_F(AstDecoderTest, MultipleReturn) { |
981 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1049 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
982 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1050 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
983 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1051 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
984 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); | 1052 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
985 | 1053 |
986 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1054 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
987 EXPECT_VERIFIES_INLINE(&sig_iii_v, | 1055 EXPECT_VERIFIES_S(&sig_iii_v, |
988 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); | 1056 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
989 EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1057 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
990 } | 1058 } |
991 | 1059 |
992 TEST_F(AstDecoderTest, MultipleReturn_fallthru) { | 1060 TEST_F(AstDecoderTest, MultipleReturn_fallthru) { |
993 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1061 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
994 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1062 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
995 | 1063 |
996 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_ZERO, WASM_ONE); | 1064 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); |
997 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_ZERO); | 1065 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); |
998 | 1066 |
999 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1067 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
1000 EXPECT_VERIFIES_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); | 1068 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); |
1001 EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE); | 1069 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); |
1002 } | 1070 } |
1003 | 1071 |
1004 TEST_F(AstDecoderTest, MacrosInt32) { | 1072 TEST_F(AstDecoderTest, MacrosInt32) { |
1005 VERIFY(WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); | 1073 EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); |
1006 VERIFY(WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); | 1074 EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); |
1007 VERIFY(WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); | 1075 EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); |
1008 VERIFY(WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); | 1076 EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); |
1009 VERIFY(WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); | 1077 EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); |
1010 VERIFY(WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); | 1078 EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); |
1011 VERIFY(WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); | 1079 EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); |
1012 VERIFY(WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); | 1080 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); |
1013 VERIFY(WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); | 1081 EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); |
1014 VERIFY(WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); | 1082 EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); |
1015 VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); | 1083 EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); |
1016 VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); | 1084 EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); |
1017 VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); | 1085 EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); |
1018 VERIFY(WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); | 1086 EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); |
1019 VERIFY(WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); | 1087 EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); |
1020 VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); | 1088 EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); |
1021 VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); | 1089 EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); |
1022 | 1090 |
1023 VERIFY(WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); | 1091 EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
1024 VERIFY(WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); | 1092 EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); |
1025 VERIFY(WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); | 1093 EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
1026 VERIFY(WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); | 1094 EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
1027 | 1095 |
1028 VERIFY(WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); | 1096 EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
1029 VERIFY(WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); | 1097 EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); |
1030 VERIFY(WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); | 1098 EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
1031 VERIFY(WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); | 1099 EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
1032 } | 1100 } |
1033 | 1101 |
1034 TEST_F(AstDecoderTest, MacrosInt64) { | 1102 TEST_F(AstDecoderTest, MacrosInt64) { |
1035 #define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(sigs.l_ll(), __VA_ARGS__) | 1103 EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); |
1036 #define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(sigs.i_ll(), __VA_ARGS__) | 1104 EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); |
| 1105 EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); |
| 1106 EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); |
| 1107 EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); |
| 1108 EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); |
| 1109 EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); |
| 1110 EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); |
| 1111 EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
| 1112 EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); |
1037 | 1113 |
1038 VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); | 1114 EXPECT_VERIFIES(l_ll, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))); |
1039 VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); | 1115 EXPECT_VERIFIES(l_ll, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))); |
1040 VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); | 1116 EXPECT_VERIFIES(l_ll, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
1041 VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); | 1117 EXPECT_VERIFIES(l_ll, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
1042 VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); | 1118 EXPECT_VERIFIES(l_ll, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
1043 VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); | |
1044 VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); | |
1045 VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); | |
1046 VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | |
1047 VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); | |
1048 | 1119 |
1049 VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))); | 1120 EXPECT_VERIFIES(i_ll, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
1050 VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))); | 1121 EXPECT_VERIFIES(i_ll, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
1051 VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); | 1122 EXPECT_VERIFIES(i_ll, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
1052 VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); | 1123 EXPECT_VERIFIES(i_ll, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
1053 VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))); | |
1054 | 1124 |
1055 VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); | 1125 EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
1056 VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); | 1126 EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
1057 VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); | 1127 EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
1058 VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); | 1128 EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
1059 | 1129 |
1060 VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); | 1130 EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
1061 VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); | 1131 EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
1062 VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); | |
1063 VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); | |
1064 | |
1065 VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); | |
1066 VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); | |
1067 } | 1132 } |
1068 | 1133 |
1069 TEST_F(AstDecoderTest, AllSimpleExpressions) { | 1134 TEST_F(AstDecoderTest, AllSimpleExpressions) { |
1070 // Test all simple expressions which are described by a signature. | 1135 // Test all simple expressions which are described by a signature. |
1071 #define DECODE_TEST(name, opcode, sig) \ | 1136 #define DECODE_TEST(name, opcode, sig) \ |
1072 { \ | 1137 { \ |
1073 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \ | 1138 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \ |
1074 if (sig->parameter_count() == 1) { \ | 1139 if (sig->parameter_count() == 1) { \ |
1075 TestUnop(kExpr##name, sig); \ | 1140 TestUnop(kExpr##name, sig); \ |
1076 } else { \ | 1141 } else { \ |
1077 TestBinop(kExpr##name, sig); \ | 1142 TestBinop(kExpr##name, sig); \ |
1078 } \ | 1143 } \ |
1079 } | 1144 } |
1080 | 1145 |
1081 FOREACH_SIMPLE_OPCODE(DECODE_TEST); | 1146 FOREACH_SIMPLE_OPCODE(DECODE_TEST); |
1082 | 1147 |
1083 #undef DECODE_TEST | 1148 #undef DECODE_TEST |
1084 } | 1149 } |
1085 | 1150 |
1086 TEST_F(AstDecoderTest, MemorySize) { | 1151 TEST_F(AstDecoderTest, MemorySize) { |
1087 byte code[] = {kExprMemorySize}; | 1152 byte code[] = {kExprMemorySize}; |
1088 EXPECT_VERIFIES(sigs.i_i(), code); | 1153 EXPECT_VERIFIES_C(i_i, code); |
1089 EXPECT_FAILURE(sigs.f_ff(), code); | 1154 EXPECT_FAILURE_C(f_ff, code); |
1090 } | 1155 } |
1091 | 1156 |
1092 TEST_F(AstDecoderTest, LoadMemOffset) { | 1157 TEST_F(AstDecoderTest, LoadMemOffset) { |
1093 for (int offset = 0; offset < 128; offset += 7) { | 1158 for (int offset = 0; offset < 128; offset += 7) { |
1094 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, | 1159 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, |
1095 static_cast<byte>(offset)}; | 1160 static_cast<byte>(offset)}; |
1096 EXPECT_VERIFIES(sigs.i_i(), code); | 1161 EXPECT_VERIFIES_C(i_i, code); |
1097 } | 1162 } |
1098 } | 1163 } |
1099 | 1164 |
1100 TEST_F(AstDecoderTest, LoadMemAlignment) { | 1165 TEST_F(AstDecoderTest, LoadMemAlignment) { |
1101 struct { | 1166 struct { |
1102 WasmOpcode instruction; | 1167 WasmOpcode instruction; |
1103 uint32_t maximum_aligment; | 1168 uint32_t maximum_aligment; |
1104 } values[] = { | 1169 } values[] = { |
1105 {kExprI32LoadMem8U, 0}, // -- | 1170 {kExprI32LoadMem8U, 0}, // -- |
1106 {kExprI32LoadMem8S, 0}, // -- | 1171 {kExprI32LoadMem8S, 0}, // -- |
1107 {kExprI32LoadMem16U, 1}, // -- | 1172 {kExprI32LoadMem16U, 1}, // -- |
1108 {kExprI32LoadMem16S, 1}, // -- | 1173 {kExprI32LoadMem16S, 1}, // -- |
1109 {kExprI64LoadMem8U, 0}, // -- | 1174 {kExprI64LoadMem8U, 0}, // -- |
1110 {kExprI64LoadMem8S, 0}, // -- | 1175 {kExprI64LoadMem8S, 0}, // -- |
1111 {kExprI64LoadMem16U, 1}, // -- | 1176 {kExprI64LoadMem16U, 1}, // -- |
1112 {kExprI64LoadMem16S, 1}, // -- | 1177 {kExprI64LoadMem16S, 1}, // -- |
1113 {kExprI64LoadMem32U, 2}, // -- | 1178 {kExprI64LoadMem32U, 2}, // -- |
1114 {kExprI64LoadMem32S, 2}, // -- | 1179 {kExprI64LoadMem32S, 2}, // -- |
1115 {kExprI32LoadMem, 2}, // -- | 1180 {kExprI32LoadMem, 2}, // -- |
1116 {kExprI64LoadMem, 3}, // -- | 1181 {kExprI64LoadMem, 3}, // -- |
1117 {kExprF32LoadMem, 2}, // -- | 1182 {kExprF32LoadMem, 2}, // -- |
1118 {kExprF64LoadMem, 3}, // -- | 1183 {kExprF64LoadMem, 3}, // -- |
1119 }; | 1184 }; |
1120 | 1185 |
1121 for (int i = 0; i < arraysize(values); i++) { | 1186 for (int i = 0; i < arraysize(values); i++) { |
1122 for (byte alignment = 0; alignment <= 4; alignment++) { | 1187 for (byte alignment = 0; alignment <= 4; alignment++) { |
1123 byte code[] = {kExprI8Const, 0, static_cast<byte>(values[i].instruction), | 1188 byte code[] = {WASM_ZERO, static_cast<byte>(values[i].instruction), |
1124 alignment, ZERO_OFFSET}; | 1189 alignment, ZERO_OFFSET, WASM_DROP}; |
1125 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { | 1190 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { |
1126 EXPECT_VERIFIES(sigs.v_i(), code); | 1191 EXPECT_VERIFIES_C(v_i, code); |
1127 } else { | 1192 } else { |
1128 EXPECT_FAILURE(sigs.v_i(), code); | 1193 EXPECT_FAILURE_C(v_i, code); |
1129 } | 1194 } |
1130 } | 1195 } |
1131 } | 1196 } |
1132 } | 1197 } |
1133 | 1198 |
1134 TEST_F(AstDecoderTest, StoreMemOffset) { | 1199 TEST_F(AstDecoderTest, StoreMemOffset) { |
1135 for (int offset = 0; offset < 128; offset += 7) { | 1200 for (int offset = 0; offset < 128; offset += 7) { |
1136 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, | 1201 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, |
1137 WASM_ZERO, WASM_ZERO)}; | 1202 WASM_ZERO, WASM_ZERO)}; |
1138 EXPECT_VERIFIES(sigs.i_i(), code); | 1203 EXPECT_VERIFIES_C(v_i, code); |
1139 } | 1204 } |
1140 } | 1205 } |
1141 | 1206 |
| 1207 TEST_F(AstDecoderTest, StoreMemOffset_void) { |
| 1208 EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, |
| 1209 WASM_ZERO)); |
| 1210 } |
| 1211 |
1142 #define BYTE0(x) ((x)&0x7F) | 1212 #define BYTE0(x) ((x)&0x7F) |
1143 #define BYTE1(x) ((x >> 7) & 0x7F) | 1213 #define BYTE1(x) ((x >> 7) & 0x7F) |
1144 #define BYTE2(x) ((x >> 14) & 0x7F) | 1214 #define BYTE2(x) ((x >> 14) & 0x7F) |
1145 #define BYTE3(x) ((x >> 21) & 0x7F) | 1215 #define BYTE3(x) ((x >> 21) & 0x7F) |
1146 | 1216 |
1147 #define VARINT1(x) BYTE0(x) | 1217 #define VARINT1(x) BYTE0(x) |
1148 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) | 1218 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) |
1149 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 1219 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) |
1150 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) | 1220 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) |
1151 | 1221 |
1152 TEST_F(AstDecoderTest, LoadMemOffset_varint) { | 1222 TEST_F(AstDecoderTest, LoadMemOffset_varint) { |
1153 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1223 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1154 VARINT1(0x45)); | 1224 VARINT1(0x45)); |
1155 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1225 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1156 VARINT2(0x3999)); | 1226 VARINT2(0x3999)); |
1157 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1227 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1158 VARINT3(0x344445)); | 1228 VARINT3(0x344445)); |
1159 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1229 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1160 VARINT4(0x36666667)); | 1230 VARINT4(0x36666667)); |
1161 } | 1231 } |
1162 | 1232 |
1163 TEST_F(AstDecoderTest, StoreMemOffset_varint) { | 1233 TEST_F(AstDecoderTest, StoreMemOffset_varint) { |
1164 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, | 1234 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1165 ZERO_ALIGNMENT, VARINT1(0x33)); | 1235 VARINT1(0x33)); |
1166 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, | 1236 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1167 ZERO_ALIGNMENT, VARINT2(0x1111)); | 1237 VARINT2(0x1111)); |
1168 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, | 1238 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1169 ZERO_ALIGNMENT, VARINT3(0x222222)); | 1239 VARINT3(0x222222)); |
1170 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, | 1240 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1171 ZERO_ALIGNMENT, VARINT4(0x44444444)); | 1241 VARINT4(0x44444444)); |
1172 } | 1242 } |
1173 | 1243 |
1174 TEST_F(AstDecoderTest, AllLoadMemCombinations) { | 1244 TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
1175 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1245 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1176 LocalType local_type = kLocalTypes[i]; | 1246 LocalType local_type = kLocalTypes[i]; |
1177 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1247 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1178 MachineType mem_type = machineTypes[j]; | 1248 MachineType mem_type = machineTypes[j]; |
1179 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; | 1249 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; |
1180 FunctionSig sig(1, 0, &local_type); | 1250 FunctionSig sig(1, 0, &local_type); |
1181 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1251 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
1182 EXPECT_VERIFIES(&sig, code); | 1252 EXPECT_VERIFIES_SC(&sig, code); |
1183 } else { | 1253 } else { |
1184 EXPECT_FAILURE(&sig, code); | 1254 EXPECT_FAILURE_SC(&sig, code); |
1185 } | 1255 } |
1186 } | 1256 } |
1187 } | 1257 } |
1188 } | 1258 } |
1189 | 1259 |
1190 TEST_F(AstDecoderTest, AllStoreMemCombinations) { | 1260 TEST_F(AstDecoderTest, AllStoreMemCombinations) { |
1191 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1261 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1192 LocalType local_type = kLocalTypes[i]; | 1262 LocalType local_type = kLocalTypes[i]; |
1193 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1263 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1194 MachineType mem_type = machineTypes[j]; | 1264 MachineType mem_type = machineTypes[j]; |
1195 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; | 1265 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; |
1196 FunctionSig sig(0, 1, &local_type); | 1266 FunctionSig sig(0, 1, &local_type); |
1197 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1267 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
1198 EXPECT_VERIFIES(&sig, code); | 1268 EXPECT_VERIFIES_SC(&sig, code); |
1199 } else { | 1269 } else { |
1200 EXPECT_FAILURE(&sig, code); | 1270 EXPECT_FAILURE_SC(&sig, code); |
1201 } | 1271 } |
1202 } | 1272 } |
1203 } | 1273 } |
1204 } | 1274 } |
1205 | 1275 |
1206 namespace { | 1276 namespace { |
1207 // A helper for tests that require a module environment for functions and | 1277 // A helper for tests that require a module environment for functions and |
1208 // globals. | 1278 // globals. |
1209 class TestModuleEnv : public ModuleEnv { | 1279 class TestModuleEnv : public ModuleEnv { |
1210 public: | 1280 public: |
1211 TestModuleEnv() { | 1281 TestModuleEnv() { |
1212 instance = nullptr; | 1282 instance = nullptr; |
1213 module = &mod; | 1283 module = &mod; |
1214 } | 1284 } |
1215 byte AddGlobal(LocalType type) { | 1285 byte AddGlobal(LocalType type, bool mutability = true) { |
1216 mod.globals.push_back({0, 0, type, 0, false}); | 1286 mod.globals.push_back({type, mutability, NO_INIT, 0, false, false}); |
1217 CHECK(mod.globals.size() <= 127); | 1287 CHECK(mod.globals.size() <= 127); |
1218 return static_cast<byte>(mod.globals.size() - 1); | 1288 return static_cast<byte>(mod.globals.size() - 1); |
1219 } | 1289 } |
1220 byte AddSignature(FunctionSig* sig) { | 1290 byte AddSignature(FunctionSig* sig) { |
1221 mod.signatures.push_back(sig); | 1291 mod.signatures.push_back(sig); |
1222 CHECK(mod.signatures.size() <= 127); | 1292 CHECK(mod.signatures.size() <= 127); |
1223 return static_cast<byte>(mod.signatures.size() - 1); | 1293 return static_cast<byte>(mod.signatures.size() - 1); |
1224 } | 1294 } |
1225 byte AddFunction(FunctionSig* sig) { | 1295 byte AddFunction(FunctionSig* sig) { |
1226 mod.functions.push_back({sig, // sig | 1296 mod.functions.push_back({sig, // sig |
1227 0, // func_index | 1297 0, // func_index |
1228 0, // sig_index | 1298 0, // sig_index |
1229 0, // name_offset | 1299 0, // name_offset |
1230 0, // name_length | 1300 0, // name_length |
1231 0, // code_start_offset | 1301 0, // code_start_offset |
1232 0}); // code_end_offset | 1302 0, // code_end_offset |
| 1303 false, // import |
| 1304 false}); // export |
1233 CHECK(mod.functions.size() <= 127); | 1305 CHECK(mod.functions.size() <= 127); |
1234 return static_cast<byte>(mod.functions.size() - 1); | 1306 return static_cast<byte>(mod.functions.size() - 1); |
1235 } | 1307 } |
1236 byte AddImport(FunctionSig* sig) { | 1308 byte AddImport(FunctionSig* sig) { |
1237 mod.import_table.push_back({sig, // sig | 1309 byte result = AddFunction(sig); |
1238 0, // sig_index | 1310 mod.functions[result].imported = true; |
1239 0, // module_name_offset | 1311 return result; |
1240 0, // module_name_length | |
1241 0, // function_name_offset | |
1242 0}); // function_name_length | |
1243 CHECK(mod.import_table.size() <= 127); | |
1244 return static_cast<byte>(mod.import_table.size() - 1); | |
1245 } | 1312 } |
1246 | 1313 |
1247 private: | 1314 private: |
1248 WasmModule mod; | 1315 WasmModule mod; |
1249 }; | 1316 }; |
1250 } // namespace | 1317 } // namespace |
1251 | 1318 |
1252 TEST_F(AstDecoderTest, SimpleCalls) { | 1319 TEST_F(AstDecoderTest, SimpleCalls) { |
1253 FunctionSig* sig = sigs.i_i(); | 1320 FunctionSig* sig = sigs.i_i(); |
1254 TestModuleEnv module_env; | 1321 TestModuleEnv module_env; |
1255 module = &module_env; | 1322 module = &module_env; |
1256 | 1323 |
1257 module_env.AddFunction(sigs.i_v()); | 1324 module_env.AddFunction(sigs.i_v()); |
1258 module_env.AddFunction(sigs.i_i()); | 1325 module_env.AddFunction(sigs.i_i()); |
1259 module_env.AddFunction(sigs.i_ii()); | 1326 module_env.AddFunction(sigs.i_ii()); |
1260 | 1327 |
1261 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION0(0)); | 1328 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); |
1262 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(27))); | 1329 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); |
1263 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION2(2, WASM_I8(37), WASM_I8(77))); | 1330 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); |
1264 } | 1331 } |
1265 | 1332 |
1266 TEST_F(AstDecoderTest, CallsWithTooFewArguments) { | 1333 TEST_F(AstDecoderTest, CallsWithTooFewArguments) { |
1267 FunctionSig* sig = sigs.i_i(); | 1334 FunctionSig* sig = sigs.i_i(); |
1268 TestModuleEnv module_env; | 1335 TestModuleEnv module_env; |
1269 module = &module_env; | 1336 module = &module_env; |
1270 | 1337 |
1271 module_env.AddFunction(sigs.i_i()); | 1338 module_env.AddFunction(sigs.i_i()); |
1272 module_env.AddFunction(sigs.i_ii()); | 1339 module_env.AddFunction(sigs.i_ii()); |
1273 module_env.AddFunction(sigs.f_ff()); | 1340 module_env.AddFunction(sigs.f_ff()); |
1274 | 1341 |
1275 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0)); | 1342 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0)); |
1276 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_ZERO)); | 1343 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); |
1277 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(2, WASM_GET_LOCAL(0))); | 1344 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); |
1278 } | 1345 } |
1279 | 1346 |
1280 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { | 1347 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { |
1281 FunctionSig* sig = sigs.i_i(); | 1348 FunctionSig* sig = sigs.i_i(); |
1282 TestModuleEnv module_env; | 1349 TestModuleEnv module_env; |
1283 module = &module_env; | 1350 module = &module_env; |
1284 | 1351 |
1285 module_env.AddFunction(sigs.i_i()); | 1352 module_env.AddFunction(sigs.i_i()); |
1286 | 1353 |
1287 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(17))); | 1354 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); |
1288 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F32(17.1))); | 1355 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); |
1289 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(17.1))); | 1356 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); |
1290 } | 1357 } |
1291 | 1358 |
1292 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { | 1359 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { |
1293 FunctionSig* sig = sigs.i_i(); | 1360 FunctionSig* sig = sigs.i_i(); |
1294 TestModuleEnv module_env; | 1361 TestModuleEnv module_env; |
1295 module = &module_env; | 1362 module = &module_env; |
1296 | 1363 |
1297 module_env.AddFunction(sigs.i_f()); | 1364 module_env.AddFunction(sigs.i_f()); |
1298 | 1365 |
1299 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I8(17))); | 1366 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); |
1300 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(27))); | 1367 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); |
1301 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(37.2))); | 1368 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); |
1302 | 1369 |
1303 module_env.AddFunction(sigs.i_d()); | 1370 module_env.AddFunction(sigs.i_d()); |
1304 | 1371 |
1305 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(16))); | 1372 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); |
1306 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I64V_1(16))); | 1373 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); |
1307 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_F32(17.6))); | 1374 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); |
| 1375 } |
| 1376 |
| 1377 TEST_F(AstDecoderTest, MultiReturn) { |
| 1378 FLAG_wasm_mv_prototype = true; |
| 1379 LocalType storage[] = {kAstI32, kAstI32}; |
| 1380 FunctionSig sig_ii_v(2, 0, storage); |
| 1381 FunctionSig sig_v_ii(0, 2, storage); |
| 1382 TestModuleEnv module_env; |
| 1383 module = &module_env; |
| 1384 |
| 1385 module_env.AddFunction(&sig_v_ii); |
| 1386 module_env.AddFunction(&sig_ii_v); |
| 1387 |
| 1388 EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); |
| 1389 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); |
| 1390 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); |
| 1391 } |
| 1392 |
| 1393 TEST_F(AstDecoderTest, MultiReturnType) { |
| 1394 FLAG_wasm_mv_prototype = true; |
| 1395 for (size_t a = 0; a < arraysize(kLocalTypes); a++) { |
| 1396 for (size_t b = 0; b < arraysize(kLocalTypes); b++) { |
| 1397 for (size_t c = 0; c < arraysize(kLocalTypes); c++) { |
| 1398 for (size_t d = 0; d < arraysize(kLocalTypes); d++) { |
| 1399 LocalType storage_ab[] = {kLocalTypes[a], kLocalTypes[b]}; |
| 1400 FunctionSig sig_ab_v(2, 0, storage_ab); |
| 1401 LocalType storage_cd[] = {kLocalTypes[c], kLocalTypes[d]}; |
| 1402 FunctionSig sig_cd_v(2, 0, storage_cd); |
| 1403 |
| 1404 TestModuleEnv module_env; |
| 1405 module = &module_env; |
| 1406 module_env.AddFunction(&sig_cd_v); |
| 1407 |
| 1408 EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); |
| 1409 |
| 1410 if (a == c && b == d) { |
| 1411 EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
| 1412 } else { |
| 1413 EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
| 1414 } |
| 1415 } |
| 1416 } |
| 1417 } |
| 1418 } |
1308 } | 1419 } |
1309 | 1420 |
1310 TEST_F(AstDecoderTest, SimpleIndirectCalls) { | 1421 TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
1311 FunctionSig* sig = sigs.i_i(); | 1422 FunctionSig* sig = sigs.i_i(); |
1312 TestModuleEnv module_env; | 1423 TestModuleEnv module_env; |
1313 module = &module_env; | 1424 module = &module_env; |
1314 | 1425 |
1315 byte f0 = module_env.AddSignature(sigs.i_v()); | 1426 byte f0 = module_env.AddSignature(sigs.i_v()); |
1316 byte f1 = module_env.AddSignature(sigs.i_i()); | 1427 byte f1 = module_env.AddSignature(sigs.i_i()); |
1317 byte f2 = module_env.AddSignature(sigs.i_ii()); | 1428 byte f2 = module_env.AddSignature(sigs.i_ii()); |
1318 | 1429 |
1319 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); | 1430 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
1320 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); | 1431 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
1321 EXPECT_VERIFIES_INLINE( | 1432 EXPECT_VERIFIES_S( |
1322 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); | 1433 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
1323 } | 1434 } |
1324 | 1435 |
1325 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { | 1436 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { |
1326 FunctionSig* sig = sigs.i_i(); | 1437 FunctionSig* sig = sigs.i_i(); |
1327 TestModuleEnv module_env; | 1438 TestModuleEnv module_env; |
1328 module = &module_env; | 1439 module = &module_env; |
1329 | 1440 |
1330 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1441 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1331 module_env.AddSignature(sigs.i_v()); | 1442 module_env.AddSignature(sigs.i_v()); |
1332 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1443 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1333 | 1444 |
1334 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); | 1445 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
1335 module_env.AddSignature(sigs.i_i()); | 1446 module_env.AddSignature(sigs.i_i()); |
1336 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); | 1447 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
1337 | 1448 |
1338 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); | 1449 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
1339 } | 1450 } |
1340 | 1451 |
1341 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { | 1452 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
1342 FunctionSig* sig = sigs.i_i(); | 1453 FunctionSig* sig = sigs.i_i(); |
1343 TestModuleEnv module_env; | 1454 TestModuleEnv module_env; |
1344 module = &module_env; | 1455 module = &module_env; |
1345 | 1456 |
1346 byte f0 = module_env.AddFunction(sigs.i_f()); | 1457 byte f0 = module_env.AddFunction(sigs.i_f()); |
1347 | 1458 |
1348 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); | 1459 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); |
1349 EXPECT_FAILURE_INLINE(sig, | 1460 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); |
1350 WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); | 1461 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); |
1351 EXPECT_FAILURE_INLINE(sig, | |
1352 WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); | |
1353 | 1462 |
1354 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); | 1463 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); |
1355 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); | 1464 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); |
1356 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); | 1465 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); |
1357 | 1466 |
1358 byte f1 = module_env.AddFunction(sigs.i_d()); | 1467 byte f1 = module_env.AddFunction(sigs.i_d()); |
1359 | 1468 |
1360 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); | 1469 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); |
1361 EXPECT_FAILURE_INLINE(sig, | 1470 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); |
1362 WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); | 1471 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
1363 EXPECT_FAILURE_INLINE(sig, | |
1364 WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); | |
1365 } | 1472 } |
1366 | 1473 |
1367 TEST_F(AstDecoderTest, SimpleImportCalls) { | 1474 TEST_F(AstDecoderTest, SimpleImportCalls) { |
1368 FunctionSig* sig = sigs.i_i(); | 1475 FunctionSig* sig = sigs.i_i(); |
1369 TestModuleEnv module_env; | 1476 TestModuleEnv module_env; |
1370 module = &module_env; | 1477 module = &module_env; |
1371 | 1478 |
1372 byte f0 = module_env.AddImport(sigs.i_v()); | 1479 byte f0 = module_env.AddImport(sigs.i_v()); |
1373 byte f1 = module_env.AddImport(sigs.i_i()); | 1480 byte f1 = module_env.AddImport(sigs.i_i()); |
1374 byte f2 = module_env.AddImport(sigs.i_ii()); | 1481 byte f2 = module_env.AddImport(sigs.i_ii()); |
1375 | 1482 |
1376 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0)); | 1483 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); |
1377 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(22))); | 1484 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22))); |
1378 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT2(f2, WASM_I8(32), WASM_I8(72))); | 1485 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); |
1379 } | 1486 } |
1380 | 1487 |
1381 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { | 1488 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { |
1382 FunctionSig* sig = sigs.i_i(); | 1489 FunctionSig* sig = sigs.i_i(); |
1383 TestModuleEnv module_env; | 1490 TestModuleEnv module_env; |
1384 module = &module_env; | 1491 module = &module_env; |
1385 | 1492 |
1386 byte f0 = module_env.AddImport(sigs.i_f()); | 1493 byte f0 = module_env.AddImport(sigs.i_f()); |
1387 | 1494 |
1388 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f0)); | 1495 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); |
1389 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I8(17))); | 1496 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17))); |
1390 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I64V_1(27))); | 1497 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); |
1391 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_F64(37.2))); | 1498 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); |
1392 | 1499 |
1393 byte f1 = module_env.AddImport(sigs.i_d()); | 1500 byte f1 = module_env.AddImport(sigs.i_d()); |
1394 | 1501 |
1395 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f1)); | 1502 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); |
1396 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(16))); | 1503 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); |
1397 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I64V_1(16))); | 1504 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); |
1398 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_F32(17.6))); | 1505 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); |
1399 } | 1506 } |
1400 | 1507 |
1401 TEST_F(AstDecoderTest, Int32Globals) { | 1508 TEST_F(AstDecoderTest, Int32Globals) { |
1402 FunctionSig* sig = sigs.i_i(); | 1509 FunctionSig* sig = sigs.i_i(); |
1403 TestModuleEnv module_env; | 1510 TestModuleEnv module_env; |
1404 module = &module_env; | 1511 module = &module_env; |
1405 | 1512 |
1406 module_env.AddGlobal(kAstI32); | 1513 module_env.AddGlobal(kAstI32); |
1407 | 1514 |
1408 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); | 1515 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1409 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1516 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1517 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
| 1518 } |
| 1519 |
| 1520 TEST_F(AstDecoderTest, ImmutableGlobal) { |
| 1521 FunctionSig* sig = sigs.v_v(); |
| 1522 TestModuleEnv module_env; |
| 1523 module = &module_env; |
| 1524 |
| 1525 uint32_t g0 = module_env.AddGlobal(kAstI32, true); |
| 1526 uint32_t g1 = module_env.AddGlobal(kAstI32, false); |
| 1527 |
| 1528 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); |
| 1529 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); |
1410 } | 1530 } |
1411 | 1531 |
1412 TEST_F(AstDecoderTest, Int32Globals_fail) { | 1532 TEST_F(AstDecoderTest, Int32Globals_fail) { |
1413 FunctionSig* sig = sigs.i_i(); | 1533 FunctionSig* sig = sigs.i_i(); |
1414 TestModuleEnv module_env; | 1534 TestModuleEnv module_env; |
1415 module = &module_env; | 1535 module = &module_env; |
1416 | 1536 |
1417 module_env.AddGlobal(kAstI64); | 1537 module_env.AddGlobal(kAstI64); |
1418 module_env.AddGlobal(kAstI64); | 1538 module_env.AddGlobal(kAstI64); |
1419 module_env.AddGlobal(kAstF32); | 1539 module_env.AddGlobal(kAstF32); |
1420 module_env.AddGlobal(kAstF64); | 1540 module_env.AddGlobal(kAstF64); |
1421 | 1541 |
1422 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(0)); | 1542 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); |
1423 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(1)); | 1543 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); |
1424 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(2)); | 1544 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); |
1425 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(3)); | 1545 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); |
1426 | 1546 |
1427 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1547 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
1428 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); | 1548 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); |
1429 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0))); | 1549 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); |
1430 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0))); | 1550 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); |
1431 } | 1551 } |
1432 | 1552 |
1433 TEST_F(AstDecoderTest, Int64Globals) { | 1553 TEST_F(AstDecoderTest, Int64Globals) { |
1434 FunctionSig* sig = sigs.l_l(); | 1554 FunctionSig* sig = sigs.l_l(); |
1435 TestModuleEnv module_env; | 1555 TestModuleEnv module_env; |
1436 module = &module_env; | 1556 module = &module_env; |
1437 | 1557 |
1438 module_env.AddGlobal(kAstI64); | 1558 module_env.AddGlobal(kAstI64); |
1439 module_env.AddGlobal(kAstI64); | 1559 module_env.AddGlobal(kAstI64); |
1440 | 1560 |
1441 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); | 1561 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1442 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(1)); | 1562 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); |
1443 | 1563 |
1444 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1564 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1445 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); | 1565 WASM_GET_LOCAL(0)); |
| 1566 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), |
| 1567 WASM_GET_LOCAL(0)); |
1446 } | 1568 } |
1447 | 1569 |
1448 TEST_F(AstDecoderTest, Float32Globals) { | 1570 TEST_F(AstDecoderTest, Float32Globals) { |
1449 FunctionSig* sig = sigs.f_ff(); | 1571 FunctionSig* sig = sigs.f_ff(); |
1450 TestModuleEnv module_env; | 1572 TestModuleEnv module_env; |
1451 module = &module_env; | 1573 module = &module_env; |
1452 | 1574 |
1453 module_env.AddGlobal(kAstF32); | 1575 module_env.AddGlobal(kAstF32); |
1454 | 1576 |
1455 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); | 1577 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1456 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1578 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
| 1579 WASM_GET_LOCAL(0)); |
1457 } | 1580 } |
1458 | 1581 |
1459 TEST_F(AstDecoderTest, Float64Globals) { | 1582 TEST_F(AstDecoderTest, Float64Globals) { |
1460 FunctionSig* sig = sigs.d_dd(); | 1583 FunctionSig* sig = sigs.d_dd(); |
1461 TestModuleEnv module_env; | 1584 TestModuleEnv module_env; |
1462 module = &module_env; | 1585 module = &module_env; |
1463 | 1586 |
1464 module_env.AddGlobal(kAstF64); | 1587 module_env.AddGlobal(kAstF64); |
1465 | 1588 |
1466 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); | 1589 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1467 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1590 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
| 1591 WASM_GET_LOCAL(0)); |
1468 } | 1592 } |
1469 | 1593 |
1470 TEST_F(AstDecoderTest, AllGetGlobalCombinations) { | 1594 TEST_F(AstDecoderTest, AllGetGlobalCombinations) { |
1471 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1595 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1472 LocalType local_type = kLocalTypes[i]; | 1596 LocalType local_type = kLocalTypes[i]; |
1473 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1597 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1474 LocalType global_type = kLocalTypes[j]; | 1598 LocalType global_type = kLocalTypes[j]; |
1475 FunctionSig sig(1, 0, &local_type); | 1599 FunctionSig sig(1, 0, &local_type); |
1476 TestModuleEnv module_env; | 1600 TestModuleEnv module_env; |
1477 module = &module_env; | 1601 module = &module_env; |
1478 module_env.AddGlobal(global_type); | 1602 module_env.AddGlobal(global_type); |
1479 if (local_type == global_type) { | 1603 if (local_type == global_type) { |
1480 EXPECT_VERIFIES_INLINE(&sig, WASM_GET_GLOBAL(0)); | 1604 EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); |
1481 } else { | 1605 } else { |
1482 EXPECT_FAILURE_INLINE(&sig, WASM_GET_GLOBAL(0)); | 1606 EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); |
1483 } | 1607 } |
1484 } | 1608 } |
1485 } | 1609 } |
1486 } | 1610 } |
1487 | 1611 |
1488 TEST_F(AstDecoderTest, AllSetGlobalCombinations) { | 1612 TEST_F(AstDecoderTest, AllSetGlobalCombinations) { |
1489 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1613 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1490 LocalType local_type = kLocalTypes[i]; | 1614 LocalType local_type = kLocalTypes[i]; |
1491 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1615 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1492 LocalType global_type = kLocalTypes[j]; | 1616 LocalType global_type = kLocalTypes[j]; |
1493 FunctionSig sig(0, 1, &local_type); | 1617 FunctionSig sig(0, 1, &local_type); |
1494 TestModuleEnv module_env; | 1618 TestModuleEnv module_env; |
1495 module = &module_env; | 1619 module = &module_env; |
1496 module_env.AddGlobal(global_type); | 1620 module_env.AddGlobal(global_type); |
1497 if (local_type == global_type) { | 1621 if (local_type == global_type) { |
1498 EXPECT_VERIFIES_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1622 EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1499 } else { | 1623 } else { |
1500 EXPECT_FAILURE_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1624 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1501 } | 1625 } |
1502 } | 1626 } |
1503 } | 1627 } |
1504 } | 1628 } |
1505 | 1629 |
1506 TEST_F(AstDecoderTest, WasmGrowMemory) { | 1630 TEST_F(AstDecoderTest, WasmGrowMemory) { |
1507 TestModuleEnv module_env; | 1631 TestModuleEnv module_env; |
1508 module = &module_env; | 1632 module = &module_env; |
1509 module->origin = kWasmOrigin; | 1633 module->origin = kWasmOrigin; |
1510 | 1634 |
1511 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; | 1635 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; |
1512 EXPECT_VERIFIES(sigs.i_i(), code); | 1636 EXPECT_VERIFIES_C(i_i, code); |
1513 EXPECT_FAILURE(sigs.i_d(), code); | 1637 EXPECT_FAILURE_C(i_d, code); |
1514 } | 1638 } |
1515 | 1639 |
1516 TEST_F(AstDecoderTest, AsmJsGrowMemory) { | 1640 TEST_F(AstDecoderTest, AsmJsGrowMemory) { |
1517 TestModuleEnv module_env; | 1641 TestModuleEnv module_env; |
1518 module = &module_env; | 1642 module = &module_env; |
1519 module->origin = kAsmJsOrigin; | 1643 module->origin = kAsmJsOrigin; |
1520 | 1644 |
1521 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; | 1645 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; |
1522 EXPECT_FAILURE(sigs.i_i(), code); | 1646 EXPECT_FAILURE_C(i_i, code); |
1523 } | 1647 } |
1524 | 1648 |
1525 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { | 1649 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { |
1526 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; | 1650 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; |
1527 FunctionSig sig_f_if(1, 2, float32int32float32); | 1651 FunctionSig sig_f_if(1, 2, float32int32float32); |
1528 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; | 1652 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; |
1529 FunctionSig sig_d_id(1, 2, float64int32float64); | 1653 FunctionSig sig_d_id(1, 2, float64int32float64); |
1530 struct { | 1654 struct { |
1531 WasmOpcode op; | 1655 WasmOpcode op; |
1532 FunctionSig* sig; | 1656 FunctionSig* sig; |
(...skipping 21 matching lines...) Expand all Loading... |
1554 } | 1678 } |
1555 } | 1679 } |
1556 | 1680 |
1557 { | 1681 { |
1558 TestModuleEnv module_env; | 1682 TestModuleEnv module_env; |
1559 module = &module_env; | 1683 module = &module_env; |
1560 module->origin = kWasmOrigin; | 1684 module->origin = kWasmOrigin; |
1561 for (int i = 0; i < arraysize(AsmJsBinOps); i++) { | 1685 for (int i = 0; i < arraysize(AsmJsBinOps); i++) { |
1562 byte code[] = { | 1686 byte code[] = { |
1563 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 1687 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
1564 EXPECT_FAILURE(AsmJsBinOps[i].sig, code); | 1688 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); |
1565 } | 1689 } |
1566 } | 1690 } |
1567 } | 1691 } |
1568 | 1692 |
1569 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) { | 1693 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) { |
1570 LocalType float32int32[] = {kAstF32, kAstI32}; | 1694 LocalType float32int32[] = {kAstF32, kAstI32}; |
1571 FunctionSig sig_f_i(1, 1, float32int32); | 1695 FunctionSig sig_f_i(1, 1, float32int32); |
1572 LocalType float64int32[] = {kAstF64, kAstI32}; | 1696 LocalType float64int32[] = {kAstF64, kAstI32}; |
1573 FunctionSig sig_d_i(1, 1, float64int32); | 1697 FunctionSig sig_d_i(1, 1, float64int32); |
1574 struct { | 1698 struct { |
(...skipping 26 matching lines...) Expand all Loading... |
1601 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig); | 1725 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig); |
1602 } | 1726 } |
1603 } | 1727 } |
1604 | 1728 |
1605 { | 1729 { |
1606 TestModuleEnv module_env; | 1730 TestModuleEnv module_env; |
1607 module = &module_env; | 1731 module = &module_env; |
1608 module->origin = kWasmOrigin; | 1732 module->origin = kWasmOrigin; |
1609 for (int i = 0; i < arraysize(AsmJsUnOps); i++) { | 1733 for (int i = 0; i < arraysize(AsmJsUnOps); i++) { |
1610 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; | 1734 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; |
1611 EXPECT_FAILURE(AsmJsUnOps[i].sig, code); | 1735 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); |
1612 } | 1736 } |
1613 } | 1737 } |
1614 } | 1738 } |
1615 | 1739 |
1616 TEST_F(AstDecoderTest, BreakEnd) { | 1740 TEST_F(AstDecoderTest, BreakEnd) { |
1617 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 1741 EXPECT_VERIFIES( |
1618 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); | 1742 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
1619 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 1743 EXPECT_VERIFIES( |
1620 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); | 1744 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); |
1621 } | 1745 } |
1622 | 1746 |
1623 TEST_F(AstDecoderTest, BreakIfBinop) { | 1747 TEST_F(AstDecoderTest, BreakIfBinop) { |
1624 EXPECT_FAILURE_INLINE( | 1748 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
1625 sigs.i_i(), WASM_BLOCK(WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), | 1749 WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); |
1626 WASM_ZERO))); | 1750 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
1627 EXPECT_FAILURE_INLINE(sigs.i_i(), | 1751 WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
1628 WASM_BLOCK(WASM_I32_ADD( | 1752 EXPECT_VERIFIES_S( |
1629 WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); | 1753 sigs.f_ff(), |
| 1754 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); |
| 1755 } |
| 1756 |
| 1757 TEST_F(AstDecoderTest, BreakIfBinop_fail) { |
| 1758 EXPECT_FAILURE_S( |
| 1759 sigs.f_ff(), |
| 1760 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
| 1761 EXPECT_FAILURE_S( |
| 1762 sigs.i_i(), |
| 1763 WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); |
1630 } | 1764 } |
1631 | 1765 |
1632 TEST_F(AstDecoderTest, BreakNesting1) { | 1766 TEST_F(AstDecoderTest, BreakNesting1) { |
1633 for (int i = 0; i < 5; i++) { | 1767 for (int i = 0; i < 5; i++) { |
1634 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) | 1768 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) |
1635 byte code[] = {WASM_BLOCK( | 1769 byte code[] = {WASM_BLOCK_I( |
1636 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), | 1770 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), |
1637 WASM_SET_LOCAL(0, WASM_I8(1))), | 1771 WASM_SET_LOCAL(0, WASM_I8(1))), |
1638 WASM_GET_LOCAL(0))}; | 1772 WASM_ZERO)}; |
1639 if (i < 3) { | 1773 if (i < 3) { |
1640 EXPECT_VERIFIES(sigs.i_i(), code); | 1774 EXPECT_VERIFIES_C(i_i, code); |
1641 } else { | 1775 } else { |
1642 EXPECT_FAILURE(sigs.i_i(), code); | 1776 EXPECT_FAILURE_C(i_i, code); |
1643 } | 1777 } |
1644 } | 1778 } |
1645 } | 1779 } |
1646 | 1780 |
1647 TEST_F(AstDecoderTest, BreakNesting2) { | 1781 TEST_F(AstDecoderTest, BreakNesting2) { |
1648 AddLocals(kAstI32, 1); | 1782 for (int i = 0; i < 7; i++) { |
1649 for (int i = 0; i < 5; i++) { | 1783 byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))}; |
1650 // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11) | 1784 if (i <= 3) { |
1651 byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)), | 1785 EXPECT_VERIFIES_C(v_v, code); |
1652 WASM_SET_LOCAL(0, WASM_I8(1)))), | |
1653 WASM_I8(11)}; | |
1654 if (i < 2) { | |
1655 EXPECT_VERIFIES(sigs.v_v(), code); | |
1656 } else { | 1786 } else { |
1657 EXPECT_FAILURE(sigs.v_v(), code); | 1787 EXPECT_FAILURE_C(v_v, code); |
1658 } | 1788 } |
1659 } | 1789 } |
1660 } | 1790 } |
1661 | 1791 |
1662 TEST_F(AstDecoderTest, BreakNesting3) { | 1792 TEST_F(AstDecoderTest, BreakNesting3) { |
1663 for (int i = 0; i < 5; i++) { | 1793 for (int i = 0; i < 7; i++) { |
1664 // (block[1] (loop[1] (block[1] (if 0 break[N]) | 1794 // (block[1] (loop[1] (block[1] (if 0 break[N]) |
1665 byte code[] = { | 1795 byte code[] = { |
1666 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))}; | 1796 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; |
1667 if (i < 3) { | 1797 if (i < 4) { |
1668 EXPECT_VERIFIES(sigs.v_v(), code); | 1798 EXPECT_VERIFIES_C(v_v, code); |
1669 } else { | 1799 } else { |
1670 EXPECT_FAILURE(sigs.v_v(), code); | 1800 EXPECT_FAILURE_C(v_v, code); |
1671 } | 1801 } |
1672 } | 1802 } |
1673 } | 1803 } |
1674 | 1804 |
1675 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { | 1805 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { |
1676 EXPECT_FAILURE_INLINE(sigs.i_i(), | 1806 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); |
1677 B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); | 1807 |
1678 | 1808 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), |
1679 EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), | 1809 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
1680 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); | 1810 EXPECT_FAILURE( |
1681 EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), | 1811 i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), WASM_BRV_IF_ZERO(0, WASM_I8(0)), |
1682 WASM_BRV_IF_ZERO(0, WASM_I8(0)), | 1812 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
1683 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); | 1813 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), |
1684 EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), | 1814 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), |
1685 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), | 1815 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); |
1686 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); | |
1687 } | 1816 } |
1688 | 1817 |
1689 TEST_F(AstDecoderTest, BreakNesting_6_levels) { | 1818 TEST_F(AstDecoderTest, BreakNesting_6_levels) { |
1690 for (int mask = 0; mask < 64; mask++) { | 1819 for (int mask = 0; mask < 64; mask++) { |
1691 for (int i = 0; i < 14; i++) { | 1820 for (int i = 0; i < 14; i++) { |
1692 byte code[] = { | 1821 byte code[] = {WASM_BLOCK(WASM_BLOCK( |
1693 kExprBlock, // -- | 1822 WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))}; |
1694 kExprBlock, // -- | |
1695 kExprBlock, // -- | |
1696 kExprBlock, // -- | |
1697 kExprBlock, // -- | |
1698 kExprBlock, // -- | |
1699 kExprBr, ARITY_0, static_cast<byte>(i), // -- | |
1700 kExprEnd, // -- | |
1701 kExprEnd, // -- | |
1702 kExprEnd, // -- | |
1703 kExprEnd, // -- | |
1704 kExprEnd, // -- | |
1705 kExprEnd // -- | |
1706 }; | |
1707 | 1823 |
1708 int depth = 6; | 1824 int depth = 6; |
1709 for (int l = 0; l < 6; l++) { | 1825 int m = mask; |
1710 if (mask & (1 << l)) { | 1826 for (size_t pos = 0; pos < sizeof(code); pos++) { |
1711 code[l] = kExprLoop; | 1827 if (code[pos] != kExprBlock) continue; |
1712 depth++; | 1828 if (m & 1) { |
| 1829 code[pos] = kExprLoop; |
| 1830 code[pos + 1] = kLocalVoid; |
1713 } | 1831 } |
1714 } | 1832 m >>= 1; |
1715 | 1833 } |
1716 if (i < depth) { | 1834 |
1717 EXPECT_VERIFIES(sigs.v_v(), code); | 1835 if (i <= depth) { |
1718 } else { | 1836 EXPECT_VERIFIES_C(v_v, code); |
1719 EXPECT_FAILURE(sigs.v_v(), code); | 1837 } else { |
1720 } | 1838 EXPECT_FAILURE_C(v_v, code); |
1721 } | 1839 } |
1722 } | 1840 } |
1723 } | 1841 } |
1724 | 1842 } |
1725 TEST_F(AstDecoderTest, ExprBreak_TypeCheck) { | 1843 |
| 1844 TEST_F(AstDecoderTest, Break_TypeCheck) { |
1726 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; | 1845 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; |
1727 for (size_t i = 0; i < arraysize(sigarray); i++) { | 1846 for (size_t i = 0; i < arraysize(sigarray); i++) { |
1728 FunctionSig* sig = sigarray[i]; | 1847 FunctionSig* sig = sigarray[i]; |
1729 // unify X and X => OK | 1848 // unify X and X => OK |
1730 EXPECT_VERIFIES_INLINE( | 1849 byte code[] = {WASM_BLOCK_T( |
1731 sig, B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1850 sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1732 WASM_GET_LOCAL(0))); | 1851 WASM_GET_LOCAL(0))}; |
| 1852 EXPECT_VERIFIES_SC(sig, code); |
1733 } | 1853 } |
1734 | 1854 |
1735 // unify i32 and f32 => fail | 1855 // unify i32 and f32 => fail |
1736 EXPECT_FAILURE_INLINE( | 1856 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), |
1737 sigs.i_i(), | 1857 WASM_F32(1.2))); |
1738 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); | |
1739 | 1858 |
1740 // unify f64 and f64 => OK | 1859 // unify f64 and f64 => OK |
1741 EXPECT_VERIFIES_INLINE( | 1860 EXPECT_VERIFIES( |
1742 sigs.d_dd(), | 1861 d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1743 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2))); | 1862 WASM_F64(1.2))); |
1744 } | 1863 } |
1745 | 1864 |
1746 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) { | 1865 TEST_F(AstDecoderTest, Break_TypeCheckAll1) { |
1747 byte code1[] = {WASM_BLOCK(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | |
1748 WASM_GET_LOCAL(1))}; | |
1749 byte code2[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), | |
1750 WASM_GET_LOCAL(1))}; | |
1751 | |
1752 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1866 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1753 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1867 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1754 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1868 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1755 FunctionSig sig(1, 2, storage); | 1869 FunctionSig sig(1, 2, storage); |
| 1870 byte code[] = {WASM_BLOCK_T( |
| 1871 sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
| 1872 WASM_GET_LOCAL(1))}; |
1756 | 1873 |
1757 if (i == j) { | 1874 if (i == j) { |
1758 EXPECT_VERIFIES(&sig, code1); | 1875 EXPECT_VERIFIES_SC(&sig, code); |
1759 EXPECT_VERIFIES(&sig, code2); | 1876 } else { |
1760 } else { | 1877 EXPECT_FAILURE_SC(&sig, code); |
1761 EXPECT_FAILURE(&sig, code1); | 1878 } |
1762 EXPECT_FAILURE(&sig, code2); | 1879 } |
1763 } | 1880 } |
1764 } | 1881 } |
1765 } | 1882 |
1766 } | 1883 TEST_F(AstDecoderTest, Break_TypeCheckAll2) { |
1767 | 1884 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1768 TEST_F(AstDecoderTest, ExprBr_Unify) { | 1885 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
| 1886 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
| 1887 FunctionSig sig(1, 2, storage); |
| 1888 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, |
| 1889 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), |
| 1890 WASM_GET_LOCAL(1))}; |
| 1891 |
| 1892 if (i == j) { |
| 1893 EXPECT_VERIFIES_SC(&sig, code); |
| 1894 } else { |
| 1895 EXPECT_FAILURE_SC(&sig, code); |
| 1896 } |
| 1897 } |
| 1898 } |
| 1899 } |
| 1900 |
| 1901 TEST_F(AstDecoderTest, Break_TypeCheckAll3) { |
| 1902 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
| 1903 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
| 1904 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
| 1905 FunctionSig sig(1, 2, storage); |
| 1906 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, |
| 1907 WASM_GET_LOCAL(1), |
| 1908 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; |
| 1909 |
| 1910 if (i == j) { |
| 1911 EXPECT_VERIFIES_SC(&sig, code); |
| 1912 } else { |
| 1913 EXPECT_FAILURE_SC(&sig, code); |
| 1914 } |
| 1915 } |
| 1916 } |
| 1917 } |
| 1918 |
| 1919 TEST_F(AstDecoderTest, Break_Unify) { |
1769 for (int which = 0; which < 2; which++) { | 1920 for (int which = 0; which < 2; which++) { |
1770 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1921 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1771 LocalType type = kLocalTypes[i]; | 1922 LocalType type = kLocalTypes[i]; |
1772 LocalType storage[] = {kAstI32, kAstI32, type}; | 1923 LocalType storage[] = {kAstI32, kAstI32, type}; |
1773 FunctionSig sig(1, 2, storage); | 1924 FunctionSig sig(1, 2, storage); |
1774 | 1925 |
1775 byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), | 1926 byte code1[] = {WASM_BLOCK_T( |
1776 WASM_GET_LOCAL(which ^ 1))}; | 1927 type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
1777 byte code2[] = { | 1928 WASM_GET_LOCAL(which ^ 1))}; |
1778 WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))), | |
1779 WASM_GET_LOCAL(which ^ 1))}; | |
1780 | 1929 |
1781 if (type == kAstI32) { | 1930 if (type == kAstI32) { |
1782 EXPECT_VERIFIES(&sig, code1); | 1931 EXPECT_VERIFIES_SC(&sig, code1); |
1783 EXPECT_VERIFIES(&sig, code2); | 1932 } else { |
1784 } else { | 1933 EXPECT_FAILURE_SC(&sig, code1); |
1785 EXPECT_FAILURE(&sig, code1); | 1934 } |
1786 EXPECT_FAILURE(&sig, code2); | 1935 } |
1787 } | 1936 } |
1788 } | 1937 } |
1789 } | 1938 |
1790 } | 1939 TEST_F(AstDecoderTest, BreakIf_cond_type) { |
1791 | 1940 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1792 TEST_F(AstDecoderTest, ExprBrIf_cond_type) { | 1941 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1793 byte code[] = {B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; | 1942 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1794 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1943 FunctionSig sig(1, 2, types); |
1795 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1944 byte code[] = {WASM_BLOCK_T( |
1796 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; | 1945 types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
1797 FunctionSig sig(0, 2, types); | 1946 |
1798 | 1947 if (types[2] == kAstI32) { |
1799 if (types[1] == kAstI32) { | 1948 EXPECT_VERIFIES_SC(&sig, code); |
1800 EXPECT_VERIFIES(&sig, code); | 1949 } else { |
1801 } else { | 1950 EXPECT_FAILURE_SC(&sig, code); |
1802 EXPECT_FAILURE(&sig, code); | 1951 } |
1803 } | 1952 } |
1804 } | 1953 } |
1805 } | 1954 } |
1806 } | 1955 |
1807 | 1956 TEST_F(AstDecoderTest, BreakIf_val_type) { |
1808 TEST_F(AstDecoderTest, ExprBrIf_val_type) { | |
1809 byte code[] = {B2(WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), | |
1810 WASM_GET_LOCAL(0))}; | |
1811 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1957 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1812 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1958 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1813 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], | 1959 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], |
1814 kAstI32}; | 1960 kAstI32}; |
1815 FunctionSig sig(1, 3, types); | 1961 FunctionSig sig(1, 3, types); |
| 1962 byte code[] = {WASM_BLOCK_T( |
| 1963 types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
| 1964 WASM_DROP, WASM_GET_LOCAL(0))}; |
1816 | 1965 |
1817 if (i == j) { | 1966 if (i == j) { |
1818 EXPECT_VERIFIES(&sig, code); | 1967 EXPECT_VERIFIES_SC(&sig, code); |
1819 } else { | 1968 } else { |
1820 EXPECT_FAILURE(&sig, code); | 1969 EXPECT_FAILURE_SC(&sig, code); |
1821 } | 1970 } |
1822 } | 1971 } |
1823 } | 1972 } |
1824 } | 1973 } |
1825 | 1974 |
1826 TEST_F(AstDecoderTest, ExprBrIf_Unify) { | 1975 TEST_F(AstDecoderTest, BreakIf_Unify) { |
1827 for (int which = 0; which < 2; which++) { | 1976 for (int which = 0; which < 2; which++) { |
1828 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1977 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1829 LocalType type = kLocalTypes[i]; | 1978 LocalType type = kLocalTypes[i]; |
1830 LocalType storage[] = {kAstI32, kAstI32, type}; | 1979 LocalType storage[] = {kAstI32, kAstI32, type}; |
1831 FunctionSig sig(1, 2, storage); | 1980 FunctionSig sig(1, 2, storage); |
1832 | 1981 byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
1833 byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), | 1982 WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; |
1834 WASM_GET_LOCAL(which ^ 1))}; | |
1835 byte code2[] = {WASM_LOOP(WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), | |
1836 WASM_GET_LOCAL(which ^ 1))}; | |
1837 | 1983 |
1838 if (type == kAstI32) { | 1984 if (type == kAstI32) { |
1839 EXPECT_VERIFIES(&sig, code1); | 1985 EXPECT_VERIFIES_SC(&sig, code); |
1840 EXPECT_VERIFIES(&sig, code2); | 1986 } else { |
1841 } else { | 1987 EXPECT_FAILURE_SC(&sig, code); |
1842 EXPECT_FAILURE(&sig, code1); | |
1843 EXPECT_FAILURE(&sig, code2); | |
1844 } | 1988 } |
1845 } | 1989 } |
1846 } | 1990 } |
1847 } | 1991 } |
1848 | 1992 |
1849 TEST_F(AstDecoderTest, BrTable0) { | 1993 TEST_F(AstDecoderTest, BrTable0) { |
1850 static byte code[] = {kExprNop, kExprBrTable, 0, 0}; | 1994 static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; |
1851 EXPECT_FAILURE(sigs.v_v(), code); | 1995 EXPECT_FAILURE_C(v_v, code); |
1852 } | 1996 } |
1853 | 1997 |
1854 TEST_F(AstDecoderTest, BrTable0b) { | 1998 TEST_F(AstDecoderTest, BrTable0b) { |
1855 static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 0}; | 1999 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)}; |
1856 EXPECT_FAILURE(sigs.v_v(), code); | 2000 EXPECT_VERIFIES_C(v_v, code); |
1857 EXPECT_FAILURE(sigs.i_i(), code); | 2001 EXPECT_FAILURE_C(i_i, code); |
1858 } | 2002 } |
1859 | 2003 |
1860 TEST_F(AstDecoderTest, BrTable0c) { | 2004 TEST_F(AstDecoderTest, BrTable0c) { |
1861 static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 1, 0, 0}; | 2005 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; |
1862 EXPECT_FAILURE(sigs.v_v(), code); | 2006 EXPECT_FAILURE_C(v_v, code); |
1863 EXPECT_FAILURE(sigs.i_i(), code); | 2007 EXPECT_FAILURE_C(i_i, code); |
1864 } | 2008 } |
1865 | 2009 |
1866 TEST_F(AstDecoderTest, BrTable1a) { | 2010 TEST_F(AstDecoderTest, BrTable1a) { |
1867 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; | 2011 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; |
1868 EXPECT_VERIFIES(sigs.v_v(), code); | 2012 EXPECT_VERIFIES_C(v_v, code); |
1869 } | 2013 } |
1870 | 2014 |
1871 TEST_F(AstDecoderTest, BrTable1b) { | 2015 TEST_F(AstDecoderTest, BrTable1b) { |
1872 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; | 2016 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; |
1873 EXPECT_VERIFIES(sigs.v_v(), code); | 2017 EXPECT_VERIFIES_C(v_v, code); |
1874 EXPECT_FAILURE(sigs.i_i(), code); | 2018 EXPECT_FAILURE_C(i_i, code); |
1875 EXPECT_FAILURE(sigs.f_ff(), code); | 2019 EXPECT_FAILURE_C(f_ff, code); |
1876 EXPECT_FAILURE(sigs.d_dd(), code); | 2020 EXPECT_FAILURE_C(d_dd, code); |
1877 } | 2021 } |
1878 | 2022 |
1879 TEST_F(AstDecoderTest, BrTable2a) { | 2023 TEST_F(AstDecoderTest, BrTable2a) { |
1880 static byte code[] = { | 2024 static byte code[] = { |
1881 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; | 2025 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; |
1882 EXPECT_VERIFIES(sigs.v_v(), code); | 2026 EXPECT_VERIFIES_C(v_v, code); |
1883 } | 2027 } |
1884 | 2028 |
1885 TEST_F(AstDecoderTest, BrTable2b) { | 2029 TEST_F(AstDecoderTest, BrTable2b) { |
1886 static byte code[] = {WASM_BLOCK( | 2030 static byte code[] = {WASM_BLOCK( |
1887 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; | 2031 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; |
1888 EXPECT_VERIFIES(sigs.v_v(), code); | 2032 EXPECT_VERIFIES_C(v_v, code); |
1889 } | 2033 } |
1890 | 2034 |
1891 TEST_F(AstDecoderTest, BrTable_off_end) { | 2035 TEST_F(AstDecoderTest, BrTable_off_end) { |
1892 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; | 2036 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; |
1893 for (size_t len = 1; len < sizeof(code); len++) { | 2037 for (size_t len = 1; len < sizeof(code); len++) { |
1894 Verify(kError, sigs.i_i(), code, code + len); | 2038 Verify(kError, sigs.i_i(), code, code + len); |
1895 } | 2039 } |
1896 } | 2040 } |
1897 | 2041 |
1898 TEST_F(AstDecoderTest, BrTable_invalid_br1) { | 2042 TEST_F(AstDecoderTest, BrTable_invalid_br1) { |
1899 for (int depth = 0; depth < 4; depth++) { | 2043 for (int depth = 0; depth < 4; depth++) { |
1900 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; | 2044 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
1901 if (depth == 0) { | 2045 if (depth <= 1) { |
1902 EXPECT_VERIFIES(sigs.v_i(), code); | 2046 EXPECT_VERIFIES_C(v_i, code); |
1903 } else { | 2047 } else { |
1904 EXPECT_FAILURE(sigs.v_i(), code); | 2048 EXPECT_FAILURE_C(v_i, code); |
1905 } | 2049 } |
1906 } | 2050 } |
1907 } | 2051 } |
1908 | 2052 |
1909 TEST_F(AstDecoderTest, BrTable_invalid_br2) { | 2053 TEST_F(AstDecoderTest, BrTable_invalid_br2) { |
1910 for (int depth = 0; depth < 4; depth++) { | 2054 for (int depth = 0; depth < 7; depth++) { |
1911 byte code[] = { | 2055 byte code[] = { |
1912 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; | 2056 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
1913 if (depth <= 1) { | 2057 if (depth < 2) { |
1914 EXPECT_VERIFIES(sigs.v_i(), code); | 2058 EXPECT_VERIFIES_C(v_i, code); |
1915 } else { | 2059 } else { |
1916 EXPECT_FAILURE(sigs.v_i(), code); | 2060 EXPECT_FAILURE_C(v_i, code); |
1917 } | 2061 } |
1918 } | 2062 } |
1919 } | 2063 } |
1920 | 2064 |
1921 TEST_F(AstDecoderTest, ExprBreakNesting1) { | 2065 TEST_F(AstDecoderTest, Brv1) { |
1922 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV(0, WASM_ZERO))); | 2066 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); |
1923 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0))); | 2067 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO)))); |
1924 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); | 2068 } |
1925 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR_IF(0, WASM_ZERO))); | |
1926 | 2069 |
1927 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(0, WASM_ZERO))); | 2070 TEST_F(AstDecoderTest, Brv1_type) { |
1928 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0))); | 2071 EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1929 EXPECT_VERIFIES_INLINE(sigs.v_v(), | 2072 EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1930 WASM_LOOP(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); | 2073 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1931 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR_IF(0, WASM_ZERO))); | 2074 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
| 2075 } |
1932 | 2076 |
1933 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); | 2077 TEST_F(AstDecoderTest, Brv1_type_n) { |
1934 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1))); | 2078 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
| 2079 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
| 2080 } |
| 2081 |
| 2082 TEST_F(AstDecoderTest, BrvIf1) { |
| 2083 EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))); |
| 2084 } |
| 2085 |
| 2086 TEST_F(AstDecoderTest, BrvIf1_type) { |
| 2087 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
| 2088 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
| 2089 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
| 2090 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
| 2091 } |
| 2092 |
| 2093 TEST_F(AstDecoderTest, BrvIf1_type_n) { |
| 2094 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
| 2095 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
1935 } | 2096 } |
1936 | 2097 |
1937 TEST_F(AstDecoderTest, Select) { | 2098 TEST_F(AstDecoderTest, Select) { |
1938 EXPECT_VERIFIES_INLINE( | 2099 EXPECT_VERIFIES(i_i, |
1939 sigs.i_i(), WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); | 2100 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); |
1940 EXPECT_VERIFIES_INLINE(sigs.f_ff(), | 2101 EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); |
1941 WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); | 2102 EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); |
1942 EXPECT_VERIFIES_INLINE(sigs.d_dd(), | 2103 EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); |
1943 WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); | |
1944 EXPECT_VERIFIES_INLINE( | |
1945 sigs.l_l(), WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); | |
1946 } | 2104 } |
1947 | 2105 |
1948 TEST_F(AstDecoderTest, Select_fail1) { | 2106 TEST_F(AstDecoderTest, Select_fail1) { |
1949 EXPECT_FAILURE_INLINE( | 2107 EXPECT_FAILURE( |
1950 sigs.i_i(), | 2108 i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
1951 WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 2109 EXPECT_FAILURE( |
1952 EXPECT_FAILURE_INLINE( | 2110 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); |
1953 sigs.i_i(), | 2111 EXPECT_FAILURE( |
1954 WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); | 2112 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); |
1955 EXPECT_FAILURE_INLINE( | |
1956 sigs.i_i(), | |
1957 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); | |
1958 } | 2113 } |
1959 | 2114 |
1960 TEST_F(AstDecoderTest, Select_fail2) { | 2115 TEST_F(AstDecoderTest, Select_fail2) { |
1961 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2116 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1962 LocalType type = kLocalTypes[i]; | 2117 LocalType type = kLocalTypes[i]; |
1963 if (type == kAstI32) continue; | 2118 if (type == kAstI32) continue; |
1964 | 2119 |
1965 LocalType types[] = {type, kAstI32, type}; | 2120 LocalType types[] = {type, kAstI32, type}; |
1966 FunctionSig sig(1, 2, types); | 2121 FunctionSig sig(1, 2, types); |
1967 | 2122 |
1968 EXPECT_VERIFIES_INLINE( | 2123 EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), |
1969 &sig, | 2124 WASM_GET_LOCAL(0))); |
1970 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); | |
1971 | 2125 |
1972 EXPECT_FAILURE_INLINE( | 2126 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), |
1973 &sig, | 2127 WASM_GET_LOCAL(0))); |
1974 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | |
1975 | 2128 |
1976 EXPECT_FAILURE_INLINE( | 2129 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
1977 &sig, | 2130 WASM_GET_LOCAL(0))); |
1978 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); | |
1979 | 2131 |
1980 EXPECT_FAILURE_INLINE( | 2132 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
1981 &sig, | 2133 WASM_GET_LOCAL(1))); |
1982 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | |
1983 } | 2134 } |
1984 } | 2135 } |
1985 | 2136 |
1986 TEST_F(AstDecoderTest, Select_TypeCheck) { | 2137 TEST_F(AstDecoderTest, Select_TypeCheck) { |
1987 EXPECT_FAILURE_INLINE( | 2138 EXPECT_FAILURE( |
1988 sigs.i_i(), | 2139 i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
1989 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | |
1990 | 2140 |
1991 EXPECT_FAILURE_INLINE( | 2141 EXPECT_FAILURE( |
1992 sigs.i_i(), | 2142 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); |
1993 WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); | |
1994 | 2143 |
1995 EXPECT_FAILURE_INLINE( | 2144 EXPECT_FAILURE(i_i, |
1996 sigs.i_i(), | 2145 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
1997 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); | |
1998 } | 2146 } |
1999 | 2147 |
2000 TEST_F(AstDecoderTest, Throw) { | 2148 TEST_F(AstDecoderTest, Throw) { |
2001 FLAG_wasm_eh_prototype = true; | 2149 FLAG_wasm_eh_prototype = true; |
2002 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprThrow); | 2150 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow); |
2003 | 2151 |
2004 EXPECT_FAILURE_INLINE(sigs.i_d(), WASM_GET_LOCAL(0), kExprThrow, | 2152 EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
2005 WASM_I32V(0)); | 2153 EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
2006 EXPECT_FAILURE_INLINE(sigs.i_f(), WASM_GET_LOCAL(0), kExprThrow, | 2154 EXPECT_FAILURE(l_l, WASM_GET_LOCAL(0), kExprThrow, WASM_I64V(0)); |
2007 WASM_I32V(0)); | |
2008 EXPECT_FAILURE_INLINE(sigs.l_l(), WASM_GET_LOCAL(0), kExprThrow, | |
2009 WASM_I64V(0)); | |
2010 } | 2155 } |
2011 | 2156 |
| 2157 #define WASM_TRY_OP kExprTry, kLocalVoid |
| 2158 |
2012 #define WASM_CATCH(local) kExprCatch, static_cast<byte>(local) | 2159 #define WASM_CATCH(local) kExprCatch, static_cast<byte>(local) |
| 2160 |
2013 TEST_F(AstDecoderTest, TryCatch) { | 2161 TEST_F(AstDecoderTest, TryCatch) { |
2014 FLAG_wasm_eh_prototype = true; | 2162 FLAG_wasm_eh_prototype = true; |
2015 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0), kExprEnd); | 2163 EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd); |
2016 | 2164 |
2017 // Missing catch. | 2165 // Missing catch. |
2018 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTry, kExprEnd); | 2166 EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd); |
2019 | 2167 |
2020 // Missing end. | 2168 // Missing end. |
2021 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0)); | 2169 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); |
2022 | 2170 |
2023 // Double catch. | 2171 // Double catch. |
2024 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0), WASM_CATCH(0), | 2172 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); |
2025 kExprEnd); | 2173 } |
| 2174 |
| 2175 TEST_F(AstDecoderTest, MultiValBlock1) { |
| 2176 FLAG_wasm_mv_prototype = true; |
| 2177 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2178 WASM_GET_LOCAL(1)), |
| 2179 kExprI32Add); |
| 2180 } |
| 2181 |
| 2182 TEST_F(AstDecoderTest, MultiValBlock2) { |
| 2183 FLAG_wasm_mv_prototype = true; |
| 2184 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2185 WASM_GET_LOCAL(1)), |
| 2186 WASM_I32_ADD(WASM_NOP, WASM_NOP)); |
| 2187 } |
| 2188 |
| 2189 TEST_F(AstDecoderTest, MultiValBlockBr1) { |
| 2190 FLAG_wasm_mv_prototype = true; |
| 2191 EXPECT_FAILURE(i_ii, |
| 2192 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_BR(0)), |
| 2193 kExprI32Add); |
| 2194 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2195 WASM_GET_LOCAL(1), WASM_BR(0)), |
| 2196 kExprI32Add); |
| 2197 } |
| 2198 |
| 2199 TEST_F(AstDecoderTest, MultiValIf1) { |
| 2200 FLAG_wasm_mv_prototype = true; |
| 2201 EXPECT_FAILURE( |
| 2202 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2203 WASM_SEQ(WASM_GET_LOCAL(0)), |
| 2204 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
| 2205 kExprI32Add); |
| 2206 EXPECT_FAILURE(i_ii, |
| 2207 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2208 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
| 2209 WASM_SEQ(WASM_GET_LOCAL(1))), |
| 2210 kExprI32Add); |
| 2211 EXPECT_VERIFIES( |
| 2212 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
| 2213 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
| 2214 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
| 2215 kExprI32Add); |
| 2216 } |
| 2217 |
| 2218 class BranchTableIteratorTest : public TestWithZone { |
| 2219 public: |
| 2220 BranchTableIteratorTest() : TestWithZone() {} |
| 2221 void CheckBrTableSize(const byte* start, const byte* end) { |
| 2222 Decoder decoder(start, end); |
| 2223 BranchTableOperand operand(&decoder, start); |
| 2224 BranchTableIterator iterator(&decoder, operand); |
| 2225 EXPECT_EQ(end - start - 1, iterator.length()); |
| 2226 EXPECT_TRUE(decoder.ok()); |
| 2227 } |
| 2228 void CheckBrTableError(const byte* start, const byte* end) { |
| 2229 Decoder decoder(start, end); |
| 2230 BranchTableOperand operand(&decoder, start); |
| 2231 BranchTableIterator iterator(&decoder, operand); |
| 2232 iterator.length(); |
| 2233 EXPECT_FALSE(decoder.ok()); |
| 2234 } |
| 2235 }; |
| 2236 |
| 2237 #define CHECK_BR_TABLE_LENGTH(...) \ |
| 2238 { \ |
| 2239 static byte code[] = {kExprBrTable, __VA_ARGS__}; \ |
| 2240 CheckBrTableSize(code, code + sizeof(code)); \ |
| 2241 } |
| 2242 |
| 2243 #define CHECK_BR_TABLE_ERROR(...) \ |
| 2244 { \ |
| 2245 static byte code[] = {kExprBrTable, __VA_ARGS__}; \ |
| 2246 CheckBrTableError(code, code + sizeof(code)); \ |
| 2247 } |
| 2248 |
| 2249 TEST_F(BranchTableIteratorTest, count0) { |
| 2250 CHECK_BR_TABLE_LENGTH(0, U32V_1(1)); |
| 2251 CHECK_BR_TABLE_LENGTH(0, U32V_2(200)); |
| 2252 CHECK_BR_TABLE_LENGTH(0, U32V_3(30000)); |
| 2253 CHECK_BR_TABLE_LENGTH(0, U32V_4(400000)); |
| 2254 |
| 2255 CHECK_BR_TABLE_LENGTH(0, U32V_1(2)); |
| 2256 CHECK_BR_TABLE_LENGTH(0, U32V_2(300)); |
| 2257 CHECK_BR_TABLE_LENGTH(0, U32V_3(40000)); |
| 2258 CHECK_BR_TABLE_LENGTH(0, U32V_4(500000)); |
| 2259 } |
| 2260 |
| 2261 TEST_F(BranchTableIteratorTest, count1) { |
| 2262 CHECK_BR_TABLE_LENGTH(1, U32V_1(1), U32V_1(6)); |
| 2263 CHECK_BR_TABLE_LENGTH(1, U32V_2(200), U32V_1(8)); |
| 2264 CHECK_BR_TABLE_LENGTH(1, U32V_3(30000), U32V_1(9)); |
| 2265 CHECK_BR_TABLE_LENGTH(1, U32V_4(400000), U32V_1(11)); |
| 2266 |
| 2267 CHECK_BR_TABLE_LENGTH(1, U32V_1(2), U32V_2(6)); |
| 2268 CHECK_BR_TABLE_LENGTH(1, U32V_2(300), U32V_2(7)); |
| 2269 CHECK_BR_TABLE_LENGTH(1, U32V_3(40000), U32V_2(8)); |
| 2270 CHECK_BR_TABLE_LENGTH(1, U32V_4(500000), U32V_2(9)); |
| 2271 } |
| 2272 |
| 2273 TEST_F(BranchTableIteratorTest, error0) { |
| 2274 CHECK_BR_TABLE_ERROR(0); |
| 2275 CHECK_BR_TABLE_ERROR(1, U32V_1(33)); |
2026 } | 2276 } |
2027 | 2277 |
2028 class WasmOpcodeLengthTest : public TestWithZone { | 2278 class WasmOpcodeLengthTest : public TestWithZone { |
2029 public: | 2279 public: |
2030 WasmOpcodeLengthTest() : TestWithZone() {} | 2280 WasmOpcodeLengthTest() : TestWithZone() {} |
2031 }; | 2281 }; |
2032 | 2282 |
2033 #define EXPECT_LENGTH(expected, opcode) \ | 2283 #define EXPECT_LENGTH(expected, opcode) \ |
2034 { \ | 2284 { \ |
2035 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ | 2285 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ |
2036 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ | 2286 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ |
2037 } | 2287 } |
2038 | 2288 |
2039 #define EXPECT_LENGTH_N(expected, ...) \ | 2289 #define EXPECT_LENGTH_N(expected, ...) \ |
2040 { \ | 2290 { \ |
2041 static const byte code[] = {__VA_ARGS__}; \ | 2291 static const byte code[] = {__VA_ARGS__}; \ |
2042 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ | 2292 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ |
2043 } | 2293 } |
2044 | 2294 |
2045 TEST_F(WasmOpcodeLengthTest, Statements) { | 2295 TEST_F(WasmOpcodeLengthTest, Statements) { |
2046 EXPECT_LENGTH(1, kExprNop); | 2296 EXPECT_LENGTH(1, kExprNop); |
2047 EXPECT_LENGTH(1, kExprBlock); | 2297 EXPECT_LENGTH(2, kExprBlock); |
2048 EXPECT_LENGTH(1, kExprLoop); | 2298 EXPECT_LENGTH(2, kExprLoop); |
2049 EXPECT_LENGTH(1, kExprIf); | 2299 EXPECT_LENGTH(2, kExprIf); |
2050 EXPECT_LENGTH(1, kExprElse); | 2300 EXPECT_LENGTH(1, kExprElse); |
2051 EXPECT_LENGTH(1, kExprEnd); | 2301 EXPECT_LENGTH(1, kExprEnd); |
2052 EXPECT_LENGTH(1, kExprSelect); | 2302 EXPECT_LENGTH(1, kExprSelect); |
2053 EXPECT_LENGTH(3, kExprBr); | 2303 EXPECT_LENGTH(2, kExprBr); |
2054 EXPECT_LENGTH(3, kExprBrIf); | 2304 EXPECT_LENGTH(2, kExprBrIf); |
2055 EXPECT_LENGTH(1, kExprThrow); | 2305 EXPECT_LENGTH(1, kExprThrow); |
2056 EXPECT_LENGTH(1, kExprTry); | 2306 EXPECT_LENGTH(2, kExprTry); |
2057 EXPECT_LENGTH(2, kExprCatch); | 2307 EXPECT_LENGTH(2, kExprCatch); |
2058 } | 2308 } |
2059 | 2309 |
2060 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { | 2310 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { |
2061 EXPECT_LENGTH(2, kExprI8Const); | 2311 EXPECT_LENGTH(2, kExprI8Const); |
2062 EXPECT_LENGTH(5, kExprF32Const); | 2312 EXPECT_LENGTH(5, kExprF32Const); |
2063 EXPECT_LENGTH(9, kExprF64Const); | 2313 EXPECT_LENGTH(9, kExprF64Const); |
2064 EXPECT_LENGTH(2, kExprGetLocal); | 2314 EXPECT_LENGTH(2, kExprGetLocal); |
2065 EXPECT_LENGTH(2, kExprSetLocal); | 2315 EXPECT_LENGTH(2, kExprSetLocal); |
2066 EXPECT_LENGTH(2, kExprGetGlobal); | 2316 EXPECT_LENGTH(2, kExprGetGlobal); |
2067 EXPECT_LENGTH(2, kExprSetGlobal); | 2317 EXPECT_LENGTH(2, kExprSetGlobal); |
2068 EXPECT_LENGTH(3, kExprCallFunction); | 2318 EXPECT_LENGTH(2, kExprCallFunction); |
2069 EXPECT_LENGTH(3, kExprCallImport); | 2319 EXPECT_LENGTH(2, kExprCallIndirect); |
2070 EXPECT_LENGTH(3, kExprCallIndirect); | |
2071 EXPECT_LENGTH(1, kExprIf); | |
2072 EXPECT_LENGTH(1, kExprBlock); | |
2073 EXPECT_LENGTH(1, kExprLoop); | |
2074 EXPECT_LENGTH(3, kExprBr); | |
2075 EXPECT_LENGTH(3, kExprBrIf); | |
2076 } | 2320 } |
2077 | 2321 |
2078 TEST_F(WasmOpcodeLengthTest, I32Const) { | 2322 TEST_F(WasmOpcodeLengthTest, I32Const) { |
2079 EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1)); | 2323 EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1)); |
2080 EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999)); | 2324 EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999)); |
2081 EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999)); | 2325 EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999)); |
2082 EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999)); | 2326 EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999)); |
2083 EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999)); | 2327 EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999)); |
2084 } | 2328 } |
2085 | 2329 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 EXPECT_LENGTH(1, kExprF64SConvertI32); | 2493 EXPECT_LENGTH(1, kExprF64SConvertI32); |
2250 EXPECT_LENGTH(1, kExprF64UConvertI32); | 2494 EXPECT_LENGTH(1, kExprF64UConvertI32); |
2251 EXPECT_LENGTH(1, kExprF64SConvertI64); | 2495 EXPECT_LENGTH(1, kExprF64SConvertI64); |
2252 EXPECT_LENGTH(1, kExprF64UConvertI64); | 2496 EXPECT_LENGTH(1, kExprF64UConvertI64); |
2253 EXPECT_LENGTH(1, kExprF64ConvertF32); | 2497 EXPECT_LENGTH(1, kExprF64ConvertF32); |
2254 EXPECT_LENGTH(1, kExprF64ReinterpretI64); | 2498 EXPECT_LENGTH(1, kExprF64ReinterpretI64); |
2255 EXPECT_LENGTH(1, kExprI32ReinterpretF32); | 2499 EXPECT_LENGTH(1, kExprI32ReinterpretF32); |
2256 EXPECT_LENGTH(1, kExprI64ReinterpretF64); | 2500 EXPECT_LENGTH(1, kExprI64ReinterpretF64); |
2257 } | 2501 } |
2258 | 2502 |
2259 class WasmOpcodeArityTest : public TestWithZone { | |
2260 public: | |
2261 WasmOpcodeArityTest() : TestWithZone() {} | |
2262 }; | |
2263 | |
2264 #define EXPECT_ARITY(expected, ...) \ | |
2265 { \ | |
2266 static const byte code[] = {__VA_ARGS__}; \ | |
2267 EXPECT_EQ(expected, OpcodeArity(code, code + sizeof(code))); \ | |
2268 } | |
2269 | |
2270 TEST_F(WasmOpcodeArityTest, Control) { | |
2271 EXPECT_ARITY(0, kExprNop); | |
2272 | |
2273 EXPECT_ARITY(0, kExprBlock, 0); | |
2274 EXPECT_ARITY(0, kExprBlock, 1); | |
2275 EXPECT_ARITY(0, kExprBlock, 2); | |
2276 EXPECT_ARITY(0, kExprBlock, 5); | |
2277 EXPECT_ARITY(0, kExprBlock, 10); | |
2278 | |
2279 EXPECT_ARITY(0, kExprLoop, 0); | |
2280 EXPECT_ARITY(0, kExprLoop, 1); | |
2281 EXPECT_ARITY(0, kExprLoop, 2); | |
2282 EXPECT_ARITY(0, kExprLoop, 7); | |
2283 EXPECT_ARITY(0, kExprLoop, 11); | |
2284 | |
2285 EXPECT_ARITY(3, kExprSelect); | |
2286 | |
2287 EXPECT_ARITY(0, kExprBr); | |
2288 EXPECT_ARITY(1, kExprBrIf); | |
2289 EXPECT_ARITY(1, kExprBrTable); | |
2290 | |
2291 EXPECT_ARITY(1, kExprBr, ARITY_1); | |
2292 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | |
2293 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | |
2294 | |
2295 { | |
2296 EXPECT_ARITY(0, kExprReturn, ARITY_0); | |
2297 EXPECT_ARITY(1, kExprReturn, ARITY_1); | |
2298 } | |
2299 | |
2300 EXPECT_ARITY(0, kExprThrow); | |
2301 EXPECT_ARITY(0, kExprTry); | |
2302 EXPECT_ARITY(1, kExprCatch, 2); | |
2303 } | |
2304 | |
2305 TEST_F(WasmOpcodeArityTest, Misc) { | |
2306 EXPECT_ARITY(0, kExprI8Const); | |
2307 EXPECT_ARITY(0, kExprI32Const); | |
2308 EXPECT_ARITY(0, kExprF32Const); | |
2309 EXPECT_ARITY(0, kExprI64Const); | |
2310 EXPECT_ARITY(0, kExprF64Const); | |
2311 EXPECT_ARITY(0, kExprGetLocal); | |
2312 EXPECT_ARITY(1, kExprSetLocal); | |
2313 EXPECT_ARITY(0, kExprGetGlobal); | |
2314 EXPECT_ARITY(1, kExprSetGlobal); | |
2315 } | |
2316 | |
2317 TEST_F(WasmOpcodeArityTest, Calls) { | |
2318 { | |
2319 EXPECT_ARITY(2, kExprCallFunction, 2, 0); | |
2320 EXPECT_ARITY(2, kExprCallImport, 2, 0); | |
2321 EXPECT_ARITY(3, kExprCallIndirect, 2, 0); | |
2322 | |
2323 EXPECT_ARITY(1, kExprBr, ARITY_1); | |
2324 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | |
2325 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | |
2326 | |
2327 EXPECT_ARITY(0, kExprBr, ARITY_0); | |
2328 EXPECT_ARITY(1, kExprBrIf, ARITY_0); | |
2329 EXPECT_ARITY(1, kExprBrTable, ARITY_0); | |
2330 } | |
2331 | |
2332 { | |
2333 EXPECT_ARITY(1, kExprCallFunction, ARITY_1, 1); | |
2334 EXPECT_ARITY(1, kExprCallImport, ARITY_1, 1); | |
2335 EXPECT_ARITY(2, kExprCallIndirect, ARITY_1, 1); | |
2336 | |
2337 EXPECT_ARITY(1, kExprBr, ARITY_1); | |
2338 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | |
2339 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | |
2340 | |
2341 EXPECT_ARITY(0, kExprBr, ARITY_0); | |
2342 EXPECT_ARITY(1, kExprBrIf, ARITY_0); | |
2343 EXPECT_ARITY(1, kExprBrTable, ARITY_0); | |
2344 } | |
2345 } | |
2346 | |
2347 TEST_F(WasmOpcodeArityTest, LoadsAndStores) { | |
2348 EXPECT_ARITY(1, kExprI32LoadMem8S); | |
2349 EXPECT_ARITY(1, kExprI32LoadMem8U); | |
2350 EXPECT_ARITY(1, kExprI32LoadMem16S); | |
2351 EXPECT_ARITY(1, kExprI32LoadMem16U); | |
2352 EXPECT_ARITY(1, kExprI32LoadMem); | |
2353 | |
2354 EXPECT_ARITY(1, kExprI64LoadMem8S); | |
2355 EXPECT_ARITY(1, kExprI64LoadMem8U); | |
2356 EXPECT_ARITY(1, kExprI64LoadMem16S); | |
2357 EXPECT_ARITY(1, kExprI64LoadMem16U); | |
2358 EXPECT_ARITY(1, kExprI64LoadMem32S); | |
2359 EXPECT_ARITY(1, kExprI64LoadMem32U); | |
2360 EXPECT_ARITY(1, kExprI64LoadMem); | |
2361 EXPECT_ARITY(1, kExprF32LoadMem); | |
2362 EXPECT_ARITY(1, kExprF64LoadMem); | |
2363 | |
2364 EXPECT_ARITY(2, kExprI32StoreMem8); | |
2365 EXPECT_ARITY(2, kExprI32StoreMem16); | |
2366 EXPECT_ARITY(2, kExprI32StoreMem); | |
2367 EXPECT_ARITY(2, kExprI64StoreMem8); | |
2368 EXPECT_ARITY(2, kExprI64StoreMem16); | |
2369 EXPECT_ARITY(2, kExprI64StoreMem32); | |
2370 EXPECT_ARITY(2, kExprI64StoreMem); | |
2371 EXPECT_ARITY(2, kExprF32StoreMem); | |
2372 EXPECT_ARITY(2, kExprF64StoreMem); | |
2373 } | |
2374 | |
2375 TEST_F(WasmOpcodeArityTest, MiscMemExpressions) { | |
2376 EXPECT_ARITY(0, kExprMemorySize); | |
2377 EXPECT_ARITY(1, kExprGrowMemory); | |
2378 } | |
2379 | |
2380 TEST_F(WasmOpcodeArityTest, SimpleExpressions) { | |
2381 EXPECT_ARITY(2, kExprI32Add); | |
2382 EXPECT_ARITY(2, kExprI32Sub); | |
2383 EXPECT_ARITY(2, kExprI32Mul); | |
2384 EXPECT_ARITY(2, kExprI32DivS); | |
2385 EXPECT_ARITY(2, kExprI32DivU); | |
2386 EXPECT_ARITY(2, kExprI32RemS); | |
2387 EXPECT_ARITY(2, kExprI32RemU); | |
2388 EXPECT_ARITY(2, kExprI32And); | |
2389 EXPECT_ARITY(2, kExprI32Ior); | |
2390 EXPECT_ARITY(2, kExprI32Xor); | |
2391 EXPECT_ARITY(2, kExprI32Shl); | |
2392 EXPECT_ARITY(2, kExprI32ShrU); | |
2393 EXPECT_ARITY(2, kExprI32ShrS); | |
2394 EXPECT_ARITY(2, kExprI32Eq); | |
2395 EXPECT_ARITY(2, kExprI32Ne); | |
2396 EXPECT_ARITY(2, kExprI32LtS); | |
2397 EXPECT_ARITY(2, kExprI32LeS); | |
2398 EXPECT_ARITY(2, kExprI32LtU); | |
2399 EXPECT_ARITY(2, kExprI32LeU); | |
2400 EXPECT_ARITY(2, kExprI32GtS); | |
2401 EXPECT_ARITY(2, kExprI32GeS); | |
2402 EXPECT_ARITY(2, kExprI32GtU); | |
2403 EXPECT_ARITY(2, kExprI32GeU); | |
2404 EXPECT_ARITY(1, kExprI32Clz); | |
2405 EXPECT_ARITY(1, kExprI32Ctz); | |
2406 EXPECT_ARITY(1, kExprI32Popcnt); | |
2407 EXPECT_ARITY(1, kExprI32Eqz); | |
2408 EXPECT_ARITY(2, kExprI64Add); | |
2409 EXPECT_ARITY(2, kExprI64Sub); | |
2410 EXPECT_ARITY(2, kExprI64Mul); | |
2411 EXPECT_ARITY(2, kExprI64DivS); | |
2412 EXPECT_ARITY(2, kExprI64DivU); | |
2413 EXPECT_ARITY(2, kExprI64RemS); | |
2414 EXPECT_ARITY(2, kExprI64RemU); | |
2415 EXPECT_ARITY(2, kExprI64And); | |
2416 EXPECT_ARITY(2, kExprI64Ior); | |
2417 EXPECT_ARITY(2, kExprI64Xor); | |
2418 EXPECT_ARITY(2, kExprI64Shl); | |
2419 EXPECT_ARITY(2, kExprI64ShrU); | |
2420 EXPECT_ARITY(2, kExprI64ShrS); | |
2421 EXPECT_ARITY(2, kExprI64Eq); | |
2422 EXPECT_ARITY(2, kExprI64Ne); | |
2423 EXPECT_ARITY(2, kExprI64LtS); | |
2424 EXPECT_ARITY(2, kExprI64LeS); | |
2425 EXPECT_ARITY(2, kExprI64LtU); | |
2426 EXPECT_ARITY(2, kExprI64LeU); | |
2427 EXPECT_ARITY(2, kExprI64GtS); | |
2428 EXPECT_ARITY(2, kExprI64GeS); | |
2429 EXPECT_ARITY(2, kExprI64GtU); | |
2430 EXPECT_ARITY(2, kExprI64GeU); | |
2431 EXPECT_ARITY(1, kExprI64Clz); | |
2432 EXPECT_ARITY(1, kExprI64Ctz); | |
2433 EXPECT_ARITY(1, kExprI64Popcnt); | |
2434 EXPECT_ARITY(2, kExprF32Add); | |
2435 EXPECT_ARITY(2, kExprF32Sub); | |
2436 EXPECT_ARITY(2, kExprF32Mul); | |
2437 EXPECT_ARITY(2, kExprF32Div); | |
2438 EXPECT_ARITY(2, kExprF32Min); | |
2439 EXPECT_ARITY(2, kExprF32Max); | |
2440 EXPECT_ARITY(1, kExprF32Abs); | |
2441 EXPECT_ARITY(1, kExprF32Neg); | |
2442 EXPECT_ARITY(2, kExprF32CopySign); | |
2443 EXPECT_ARITY(1, kExprF32Ceil); | |
2444 EXPECT_ARITY(1, kExprF32Floor); | |
2445 EXPECT_ARITY(1, kExprF32Trunc); | |
2446 EXPECT_ARITY(1, kExprF32NearestInt); | |
2447 EXPECT_ARITY(1, kExprF32Sqrt); | |
2448 EXPECT_ARITY(2, kExprF32Eq); | |
2449 EXPECT_ARITY(2, kExprF32Ne); | |
2450 EXPECT_ARITY(2, kExprF32Lt); | |
2451 EXPECT_ARITY(2, kExprF32Le); | |
2452 EXPECT_ARITY(2, kExprF32Gt); | |
2453 EXPECT_ARITY(2, kExprF32Ge); | |
2454 EXPECT_ARITY(2, kExprF64Add); | |
2455 EXPECT_ARITY(2, kExprF64Sub); | |
2456 EXPECT_ARITY(2, kExprF64Mul); | |
2457 EXPECT_ARITY(2, kExprF64Div); | |
2458 EXPECT_ARITY(2, kExprF64Min); | |
2459 EXPECT_ARITY(2, kExprF64Max); | |
2460 EXPECT_ARITY(1, kExprF64Abs); | |
2461 EXPECT_ARITY(1, kExprF64Neg); | |
2462 EXPECT_ARITY(2, kExprF64CopySign); | |
2463 EXPECT_ARITY(1, kExprF64Ceil); | |
2464 EXPECT_ARITY(1, kExprF64Floor); | |
2465 EXPECT_ARITY(1, kExprF64Trunc); | |
2466 EXPECT_ARITY(1, kExprF64NearestInt); | |
2467 EXPECT_ARITY(1, kExprF64Sqrt); | |
2468 EXPECT_ARITY(2, kExprF64Eq); | |
2469 EXPECT_ARITY(2, kExprF64Ne); | |
2470 EXPECT_ARITY(2, kExprF64Lt); | |
2471 EXPECT_ARITY(2, kExprF64Le); | |
2472 EXPECT_ARITY(2, kExprF64Gt); | |
2473 EXPECT_ARITY(2, kExprF64Ge); | |
2474 EXPECT_ARITY(1, kExprI32SConvertF32); | |
2475 EXPECT_ARITY(1, kExprI32SConvertF64); | |
2476 EXPECT_ARITY(1, kExprI32UConvertF32); | |
2477 EXPECT_ARITY(1, kExprI32UConvertF64); | |
2478 EXPECT_ARITY(1, kExprI32ConvertI64); | |
2479 EXPECT_ARITY(1, kExprI64SConvertF32); | |
2480 EXPECT_ARITY(1, kExprI64SConvertF64); | |
2481 EXPECT_ARITY(1, kExprI64UConvertF32); | |
2482 EXPECT_ARITY(1, kExprI64UConvertF64); | |
2483 EXPECT_ARITY(1, kExprI64SConvertI32); | |
2484 EXPECT_ARITY(1, kExprI64UConvertI32); | |
2485 EXPECT_ARITY(1, kExprF32SConvertI32); | |
2486 EXPECT_ARITY(1, kExprF32UConvertI32); | |
2487 EXPECT_ARITY(1, kExprF32SConvertI64); | |
2488 EXPECT_ARITY(1, kExprF32UConvertI64); | |
2489 EXPECT_ARITY(1, kExprF32ConvertF64); | |
2490 EXPECT_ARITY(1, kExprF32ReinterpretI32); | |
2491 EXPECT_ARITY(1, kExprF64SConvertI32); | |
2492 EXPECT_ARITY(1, kExprF64UConvertI32); | |
2493 EXPECT_ARITY(1, kExprF64SConvertI64); | |
2494 EXPECT_ARITY(1, kExprF64UConvertI64); | |
2495 EXPECT_ARITY(1, kExprF64ConvertF32); | |
2496 EXPECT_ARITY(1, kExprF64ReinterpretI64); | |
2497 EXPECT_ARITY(1, kExprI32ReinterpretF32); | |
2498 EXPECT_ARITY(1, kExprI64ReinterpretF64); | |
2499 } | |
2500 | |
2501 typedef ZoneVector<LocalType> LocalTypeMap; | 2503 typedef ZoneVector<LocalType> LocalTypeMap; |
2502 | 2504 |
2503 class LocalDeclDecoderTest : public TestWithZone { | 2505 class LocalDeclDecoderTest : public TestWithZone { |
2504 public: | 2506 public: |
2505 v8::internal::AccountingAllocator allocator; | 2507 v8::internal::AccountingAllocator allocator; |
2506 | 2508 |
2507 size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected, | 2509 size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected, |
2508 size_t count) { | 2510 size_t count) { |
2509 for (size_t i = 0; i < count; i++) { | 2511 for (size_t i = 0; i < count; i++) { |
2510 EXPECT_EQ(expected, map[pos++]); | 2512 EXPECT_EQ(expected, map[pos++]); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2667 iter.next(); | 2669 iter.next(); |
2668 EXPECT_TRUE(iter.has_next()); | 2670 EXPECT_TRUE(iter.has_next()); |
2669 EXPECT_EQ(kExprI8Const, iter.current()); | 2671 EXPECT_EQ(kExprI8Const, iter.current()); |
2670 iter.next(); | 2672 iter.next(); |
2671 EXPECT_FALSE(iter.has_next()); | 2673 EXPECT_FALSE(iter.has_next()); |
2672 } | 2674 } |
2673 | 2675 |
2674 } // namespace wasm | 2676 } // namespace wasm |
2675 } // namespace internal | 2677 } // namespace internal |
2676 } // namespace v8 | 2678 } // namespace v8 |
OLD | NEW |