Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 1746653002: [wasm] Add support and unittests for decoding signed LEB128. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/unittests/unittests.gyp ('k') | test/unittests/wasm/decoder-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static byte code[] = {__VA_ARGS__}; \ 54 static byte code[] = {__VA_ARGS__}; \
55 Verify(kError, env, code, code + arraysize(code)); \ 55 Verify(kError, env, code, code + arraysize(code)); \
56 } while (false) 56 } while (false)
57 57
58 #define VERIFY(...) \ 58 #define VERIFY(...) \
59 do { \ 59 do { \
60 static const byte code[] = {__VA_ARGS__}; \ 60 static const byte code[] = {__VA_ARGS__}; \
61 Verify(kSuccess, &env_v_i, code, code + sizeof(code)); \ 61 Verify(kSuccess, &env_v_i, code, code + sizeof(code)); \
62 } while (false) 62 } while (false)
63 63
64 64 class AstDecoderTest : public TestWithZone {
65 class WasmDecoderTest : public TestWithZone {
66 public: 65 public:
67 WasmDecoderTest() : TestWithZone(), sigs() { 66 AstDecoderTest() : TestWithZone(), sigs() {
68 init_env(&env_i_i, sigs.i_i()); 67 init_env(&env_i_i, sigs.i_i());
69 init_env(&env_v_v, sigs.v_v()); 68 init_env(&env_v_v, sigs.v_v());
70 init_env(&env_v_i, sigs.v_i()); 69 init_env(&env_v_i, sigs.v_i());
71 init_env(&env_i_f, sigs.i_f()); 70 init_env(&env_i_f, sigs.i_f());
72 init_env(&env_i_d, sigs.i_d()); 71 init_env(&env_i_d, sigs.i_d());
73 init_env(&env_l_l, sigs.l_l()); 72 init_env(&env_l_l, sigs.l_l());
74 init_env(&env_f_ff, sigs.f_ff()); 73 init_env(&env_f_ff, sigs.f_ff());
75 init_env(&env_d_dd, sigs.d_dd()); 74 init_env(&env_d_dd, sigs.d_dd());
76 } 75 }
77 76
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 FunctionEnv env; 180 FunctionEnv env;
182 env.module = nullptr; 181 env.module = nullptr;
183 env.sig = sig; 182 env.sig = sig;
184 env.local_i32_count = count; 183 env.local_i32_count = count;
185 env.local_f64_count = 0; 184 env.local_f64_count = 0;
186 env.local_f32_count = 0; 185 env.local_f32_count = 0;
187 env.total_locals = static_cast<unsigned>(count + sig->parameter_count()); 186 env.total_locals = static_cast<unsigned>(count + sig->parameter_count());
188 return env; 187 return env;
189 } 188 }
190 189
191 190 TEST_F(AstDecoderTest, Int8Const) {
192 TEST_F(WasmDecoderTest, Int8Const) {
193 byte code[] = {kExprI8Const, 0}; 191 byte code[] = {kExprI8Const, 0};
194 for (int i = -128; i < 128; i++) { 192 for (int i = -128; i < 128; i++) {
195 code[1] = static_cast<byte>(i); 193 code[1] = static_cast<byte>(i);
196 EXPECT_VERIFIES(&env_i_i, code); 194 EXPECT_VERIFIES(&env_i_i, code);
197 } 195 }
198 } 196 }
199 197
200 198 TEST_F(AstDecoderTest, EmptyFunction) {
201 TEST_F(WasmDecoderTest, EmptyFunction) {
202 byte code[] = {0}; 199 byte code[] = {0};
203 Verify(kSuccess, &env_v_v, code, code); 200 Verify(kSuccess, &env_v_v, code, code);
204 Verify(kError, &env_i_i, code, code); 201 Verify(kError, &env_i_i, code, code);
205 } 202 }
206 203
207 204 TEST_F(AstDecoderTest, IncompleteIf1) {
208 TEST_F(WasmDecoderTest, IncompleteIf1) {
209 byte code[] = {kExprIf}; 205 byte code[] = {kExprIf};
210 EXPECT_FAILURE(&env_v_v, code); 206 EXPECT_FAILURE(&env_v_v, code);
211 EXPECT_FAILURE(&env_i_i, code); 207 EXPECT_FAILURE(&env_i_i, code);
212 } 208 }
213 209
214 210 TEST_F(AstDecoderTest, IncompleteIf2) {
215 TEST_F(WasmDecoderTest, IncompleteIf2) {
216 byte code[] = {kExprIf, kExprI8Const, 0}; 211 byte code[] = {kExprIf, kExprI8Const, 0};
217 EXPECT_FAILURE(&env_v_v, code); 212 EXPECT_FAILURE(&env_v_v, code);
218 EXPECT_FAILURE(&env_i_i, code); 213 EXPECT_FAILURE(&env_i_i, code);
219 } 214 }
220 215
221 216 TEST_F(AstDecoderTest, Int8Const_fallthru) {
222 TEST_F(WasmDecoderTest, Int8Const_fallthru) {
223 byte code[] = {kExprI8Const, 0, kExprI8Const, 1}; 217 byte code[] = {kExprI8Const, 0, kExprI8Const, 1};
224 EXPECT_VERIFIES(&env_i_i, code); 218 EXPECT_VERIFIES(&env_i_i, code);
225 } 219 }
226 220
227 221 TEST_F(AstDecoderTest, Int32Const) {
228 TEST_F(WasmDecoderTest, Int32Const) {
229 byte code[] = {kExprI32Const, 0, 0, 0, 0}; 222 byte code[] = {kExprI32Const, 0, 0, 0, 0};
230 int32_t* ptr = reinterpret_cast<int32_t*>(code + 1); 223 int32_t* ptr = reinterpret_cast<int32_t*>(code + 1);
231 const int kInc = 4498211; 224 const int kInc = 4498211;
232 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { 225 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
233 *ptr = i; 226 *ptr = i;
234 EXPECT_VERIFIES(&env_i_i, code); 227 EXPECT_VERIFIES(&env_i_i, code);
235 } 228 }
236 } 229 }
237 230
238 231 TEST_F(AstDecoderTest, Int8Const_fallthru2) {
239 TEST_F(WasmDecoderTest, Int8Const_fallthru2) {
240 byte code[] = {kExprI8Const, 0, kExprI32Const, 1, 2, 3, 4}; 232 byte code[] = {kExprI8Const, 0, kExprI32Const, 1, 2, 3, 4};
241 EXPECT_VERIFIES(&env_i_i, code); 233 EXPECT_VERIFIES(&env_i_i, code);
242 } 234 }
243 235
244 236 TEST_F(AstDecoderTest, Int64Const) {
245 TEST_F(WasmDecoderTest, Int64Const) {
246 byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0}; 237 byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0};
247 int64_t* ptr = reinterpret_cast<int64_t*>(code + 1); 238 int64_t* ptr = reinterpret_cast<int64_t*>(code + 1);
248 const int kInc = 4498211; 239 const int kInc = 4498211;
249 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { 240 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
250 *ptr = (static_cast<int64_t>(i) << 32) | i; 241 *ptr = (static_cast<int64_t>(i) << 32) | i;
251 EXPECT_VERIFIES(&env_l_l, code); 242 EXPECT_VERIFIES(&env_l_l, code);
252 } 243 }
253 } 244 }
254 245
255 246 TEST_F(AstDecoderTest, Float32Const) {
256 TEST_F(WasmDecoderTest, Float32Const) {
257 byte code[] = {kExprF32Const, 0, 0, 0, 0}; 247 byte code[] = {kExprF32Const, 0, 0, 0, 0};
258 float* ptr = reinterpret_cast<float*>(code + 1); 248 float* ptr = reinterpret_cast<float*>(code + 1);
259 for (int i = 0; i < 30; i++) { 249 for (int i = 0; i < 30; i++) {
260 *ptr = i * -7.75f; 250 *ptr = i * -7.75f;
261 EXPECT_VERIFIES(&env_f_ff, code); 251 EXPECT_VERIFIES(&env_f_ff, code);
262 } 252 }
263 } 253 }
264 254
265 255 TEST_F(AstDecoderTest, Float64Const) {
266 TEST_F(WasmDecoderTest, Float64Const) {
267 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; 256 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0};
268 double* ptr = reinterpret_cast<double*>(code + 1); 257 double* ptr = reinterpret_cast<double*>(code + 1);
269 for (int i = 0; i < 30; i++) { 258 for (int i = 0; i < 30; i++) {
270 *ptr = i * 33.45; 259 *ptr = i * 33.45;
271 EXPECT_VERIFIES(&env_d_dd, code); 260 EXPECT_VERIFIES(&env_d_dd, code);
272 } 261 }
273 } 262 }
274 263
275 264 TEST_F(AstDecoderTest, Int32Const_off_end) {
276 TEST_F(WasmDecoderTest, Int32Const_off_end) {
277 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; 265 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44};
278 266
279 for (int size = 1; size <= 4; size++) { 267 for (int size = 1; size <= 4; size++) {
280 Verify(kError, &env_i_i, code, code + size); 268 Verify(kError, &env_i_i, code, code + size);
281 } 269 }
282 } 270 }
283 271
284 272 TEST_F(AstDecoderTest, GetLocal0_param) {
285 TEST_F(WasmDecoderTest, GetLocal0_param) {
286 EXPECT_VERIFIES(&env_i_i, kCodeGetLocal0); 273 EXPECT_VERIFIES(&env_i_i, kCodeGetLocal0);
287 } 274 }
288 275
289 276 TEST_F(AstDecoderTest, GetLocal0_local) {
290 TEST_F(WasmDecoderTest, GetLocal0_local) {
291 FunctionEnv env; 277 FunctionEnv env;
292 init_env(&env, sigs.i_v()); 278 init_env(&env, sigs.i_v());
293 env.AddLocals(kAstI32, 1); 279 env.AddLocals(kAstI32, 1);
294 EXPECT_VERIFIES(&env, kCodeGetLocal0); 280 EXPECT_VERIFIES(&env, kCodeGetLocal0);
295 } 281 }
296 282
297 283 TEST_F(AstDecoderTest, GetLocal0_param_n) {
298 TEST_F(WasmDecoderTest, GetLocal0_param_n) {
299 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; 284 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()};
300 285
301 for (size_t i = 0; i < arraysize(array); i++) { 286 for (size_t i = 0; i < arraysize(array); i++) {
302 FunctionEnv env = CreateInt32FunctionEnv(array[i], 0); 287 FunctionEnv env = CreateInt32FunctionEnv(array[i], 0);
303 EXPECT_VERIFIES(&env, kCodeGetLocal0); 288 EXPECT_VERIFIES(&env, kCodeGetLocal0);
304 } 289 }
305 } 290 }
306 291
307 292 TEST_F(AstDecoderTest, GetLocalN_local) {
308 TEST_F(WasmDecoderTest, GetLocalN_local) {
309 for (byte i = 1; i < 8; i++) { 293 for (byte i = 1; i < 8; i++) {
310 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i); 294 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i);
311 for (byte j = 0; j < i; j++) { 295 for (byte j = 0; j < i; j++) {
312 byte code[] = {kExprGetLocal, j}; 296 byte code[] = {kExprGetLocal, j};
313 EXPECT_VERIFIES(&env, code); 297 EXPECT_VERIFIES(&env, code);
314 } 298 }
315 } 299 }
316 } 300 }
317 301
318 302 TEST_F(AstDecoderTest, GetLocal0_fail_no_params) {
319 TEST_F(WasmDecoderTest, GetLocal0_fail_no_params) {
320 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 0); 303 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 0);
321 304
322 EXPECT_FAILURE(&env, kCodeGetLocal0); 305 EXPECT_FAILURE(&env, kCodeGetLocal0);
323 } 306 }
324 307
325 308 TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) {
326 TEST_F(WasmDecoderTest, GetLocal1_fail_no_locals) {
327 EXPECT_FAILURE(&env_i_i, kCodeGetLocal1); 309 EXPECT_FAILURE(&env_i_i, kCodeGetLocal1);
328 } 310 }
329 311
330 312 TEST_F(AstDecoderTest, GetLocal_off_end) {
331 TEST_F(WasmDecoderTest, GetLocal_off_end) {
332 static const byte code[] = {kExprGetLocal}; 313 static const byte code[] = {kExprGetLocal};
333 EXPECT_FAILURE(&env_i_i, code); 314 EXPECT_FAILURE(&env_i_i, code);
334 } 315 }
335 316
336 317 TEST_F(AstDecoderTest, GetLocal_varint) {
337 TEST_F(WasmDecoderTest, GetLocal_varint) {
338 env_i_i.local_i32_count = 1000000000; 318 env_i_i.local_i32_count = 1000000000;
339 env_i_i.total_locals += 1000000000; 319 env_i_i.total_locals += 1000000000;
340 320
341 { 321 {
342 static const byte code[] = {kExprGetLocal, 0xFF, 0x01}; 322 static const byte code[] = {kExprGetLocal, 0xFF, 0x01};
343 EXPECT_VERIFIES(&env_i_i, code); 323 EXPECT_VERIFIES(&env_i_i, code);
344 EXPECT_FAILURE(&env_i_f, code); 324 EXPECT_FAILURE(&env_i_f, code);
345 } 325 }
346 326
347 { 327 {
348 static const byte code[] = {kExprGetLocal, 0xF0, 0x80, 0x01}; 328 static const byte code[] = {kExprGetLocal, 0xF0, 0x80, 0x01};
349 EXPECT_VERIFIES(&env_i_i, code); 329 EXPECT_VERIFIES(&env_i_i, code);
350 EXPECT_FAILURE(&env_i_f, code); 330 EXPECT_FAILURE(&env_i_f, code);
351 } 331 }
352 332
353 { 333 {
354 static const byte code[] = {kExprGetLocal, 0xF2, 0x81, 0x82, 0x01}; 334 static const byte code[] = {kExprGetLocal, 0xF2, 0x81, 0x82, 0x01};
355 EXPECT_VERIFIES(&env_i_i, code); 335 EXPECT_VERIFIES(&env_i_i, code);
356 EXPECT_FAILURE(&env_i_f, code); 336 EXPECT_FAILURE(&env_i_f, code);
357 } 337 }
358 338
359 { 339 {
360 static const byte code[] = {kExprGetLocal, 0xF3, 0xA1, 0xB1, 0xC1, 0x01}; 340 static const byte code[] = {kExprGetLocal, 0xF3, 0xA1, 0xB1, 0xC1, 0x01};
361 EXPECT_VERIFIES(&env_i_i, code); 341 EXPECT_VERIFIES(&env_i_i, code);
362 EXPECT_FAILURE(&env_i_f, code); 342 EXPECT_FAILURE(&env_i_f, code);
363 } 343 }
364 } 344 }
365 345
366 346 TEST_F(AstDecoderTest, Binops_off_end) {
367 TEST_F(WasmDecoderTest, Binops_off_end) {
368 byte code1[] = {0}; // [opcode] 347 byte code1[] = {0}; // [opcode]
369 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 348 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
370 code1[0] = kInt32BinopOpcodes[i]; 349 code1[0] = kInt32BinopOpcodes[i];
371 EXPECT_FAILURE(&env_i_i, code1); 350 EXPECT_FAILURE(&env_i_i, code1);
372 } 351 }
373 352
374 byte code3[] = {0, kExprGetLocal, 0}; // [opcode] [expr] 353 byte code3[] = {0, kExprGetLocal, 0}; // [opcode] [expr]
375 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 354 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
376 code3[0] = kInt32BinopOpcodes[i]; 355 code3[0] = kInt32BinopOpcodes[i];
377 EXPECT_FAILURE(&env_i_i, code3); 356 EXPECT_FAILURE(&env_i_i, code3);
378 } 357 }
379 358
380 byte code4[] = {0, kExprGetLocal, 0, 0}; // [opcode] [expr] [opcode] 359 byte code4[] = {0, kExprGetLocal, 0, 0}; // [opcode] [expr] [opcode]
381 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 360 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
382 code4[0] = kInt32BinopOpcodes[i]; 361 code4[0] = kInt32BinopOpcodes[i];
383 code4[3] = kInt32BinopOpcodes[i]; 362 code4[3] = kInt32BinopOpcodes[i];
384 EXPECT_FAILURE(&env_i_i, code4); 363 EXPECT_FAILURE(&env_i_i, code4);
385 } 364 }
386 } 365 }
387 366
388 367
389 //=================================================================== 368 //===================================================================
390 //== Statements 369 //== Statements
391 //=================================================================== 370 //===================================================================
392 TEST_F(WasmDecoderTest, Nop) { 371 TEST_F(AstDecoderTest, Nop) {
393 static const byte code[] = {kExprNop}; 372 static const byte code[] = {kExprNop};
394 EXPECT_VERIFIES(&env_v_v, code); 373 EXPECT_VERIFIES(&env_v_v, code);
395 } 374 }
396 375
397 376 TEST_F(AstDecoderTest, SetLocal0_param) {
398 TEST_F(WasmDecoderTest, SetLocal0_param) {
399 static const byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; 377 static const byte code[] = {kExprSetLocal, 0, kExprI8Const, 0};
400 EXPECT_VERIFIES(&env_i_i, code); 378 EXPECT_VERIFIES(&env_i_i, code);
401 } 379 }
402 380
403 381 TEST_F(AstDecoderTest, SetLocal0_local) {
404 TEST_F(WasmDecoderTest, SetLocal0_local) {
405 byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; 382 byte code[] = {kExprSetLocal, 0, kExprI8Const, 0};
406 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 1); 383 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 1);
407 384
408 EXPECT_VERIFIES(&env, code); 385 EXPECT_VERIFIES(&env, code);
409 } 386 }
410 387
411 388 TEST_F(AstDecoderTest, SetLocalN_local) {
412 TEST_F(WasmDecoderTest, SetLocalN_local) {
413 for (byte i = 1; i < 8; i++) { 389 for (byte i = 1; i < 8; i++) {
414 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i); 390 FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i);
415 for (byte j = 0; j < i; j++) { 391 for (byte j = 0; j < i; j++) {
416 byte code[] = {kExprSetLocal, j, kExprI8Const, i}; 392 byte code[] = {kExprSetLocal, j, kExprI8Const, i};
417 EXPECT_VERIFIES(&env, code); 393 EXPECT_VERIFIES(&env, code);
418 } 394 }
419 } 395 }
420 } 396 }
421 397
422 398 TEST_F(AstDecoderTest, Block0) {
423 TEST_F(WasmDecoderTest, Block0) {
424 static const byte code[] = {kExprBlock, 0}; 399 static const byte code[] = {kExprBlock, 0};
425 EXPECT_VERIFIES(&env_v_v, code); 400 EXPECT_VERIFIES(&env_v_v, code);
426 } 401 }
427 402
428 403 TEST_F(AstDecoderTest, Block0_fallthru1) {
429 TEST_F(WasmDecoderTest, Block0_fallthru1) {
430 static const byte code[] = {kExprBlock, 0, kExprBlock, 0}; 404 static const byte code[] = {kExprBlock, 0, kExprBlock, 0};
431 EXPECT_VERIFIES(&env_v_v, code); 405 EXPECT_VERIFIES(&env_v_v, code);
432 } 406 }
433 407
434 408 TEST_F(AstDecoderTest, Block1) {
435 TEST_F(WasmDecoderTest, Block1) {
436 static const byte code[] = {kExprBlock, 1, kExprSetLocal, 0, kExprI8Const, 0}; 409 static const byte code[] = {kExprBlock, 1, kExprSetLocal, 0, kExprI8Const, 0};
437 EXPECT_VERIFIES(&env_i_i, code); 410 EXPECT_VERIFIES(&env_i_i, code);
438 } 411 }
439 412
440 413 TEST_F(AstDecoderTest, Block0_fallthru2) {
441 TEST_F(WasmDecoderTest, Block0_fallthru2) {
442 static const byte code[] = {kExprBlock, 0, kExprSetLocal, 0, kExprI8Const, 0}; 414 static const byte code[] = {kExprBlock, 0, kExprSetLocal, 0, kExprI8Const, 0};
443 EXPECT_VERIFIES(&env_i_i, code); 415 EXPECT_VERIFIES(&env_i_i, code);
444 } 416 }
445 417
446 418 TEST_F(AstDecoderTest, Block2) {
447 TEST_F(WasmDecoderTest, Block2) {
448 static const byte code[] = {kExprBlock, 2, // -- 419 static const byte code[] = {kExprBlock, 2, // --
449 kExprSetLocal, 0, kExprI8Const, 0, // -- 420 kExprSetLocal, 0, kExprI8Const, 0, // --
450 kExprSetLocal, 0, kExprI8Const, 0}; // -- 421 kExprSetLocal, 0, kExprI8Const, 0}; // --
451 EXPECT_VERIFIES(&env_i_i, code); 422 EXPECT_VERIFIES(&env_i_i, code);
452 } 423 }
453 424
454 425 TEST_F(AstDecoderTest, Block2_fallthru) {
455 TEST_F(WasmDecoderTest, Block2_fallthru) {
456 static const byte code[] = {kExprBlock, 2, // -- 426 static const byte code[] = {kExprBlock, 2, // --
457 kExprSetLocal, 0, kExprI8Const, 0, // -- 427 kExprSetLocal, 0, kExprI8Const, 0, // --
458 kExprSetLocal, 0, kExprI8Const, 0, // -- 428 kExprSetLocal, 0, kExprI8Const, 0, // --
459 kExprI8Const, 11}; // -- 429 kExprI8Const, 11}; // --
460 EXPECT_VERIFIES(&env_i_i, code); 430 EXPECT_VERIFIES(&env_i_i, code);
461 } 431 }
462 432
463 433 TEST_F(AstDecoderTest, BlockN) {
464 TEST_F(WasmDecoderTest, BlockN) {
465 byte block[] = {kExprBlock, 2}; 434 byte block[] = {kExprBlock, 2};
466 435
467 for (size_t i = 0; i < 10; i++) { 436 for (size_t i = 0; i < 10; i++) {
468 size_t total = sizeof(block) + sizeof(kCodeSetLocal0) * i; 437 size_t total = sizeof(block) + sizeof(kCodeSetLocal0) * i;
469 byte* code = reinterpret_cast<byte*>(malloc(total)); 438 byte* code = reinterpret_cast<byte*>(malloc(total));
470 memcpy(code, block, sizeof(block)); 439 memcpy(code, block, sizeof(block));
471 code[1] = static_cast<byte>(i); 440 code[1] = static_cast<byte>(i);
472 for (size_t j = 0; j < i; j++) { 441 for (size_t j = 0; j < i; j++) {
473 memcpy(code + sizeof(block) + j * sizeof(kCodeSetLocal0), kCodeSetLocal0, 442 memcpy(code + sizeof(block) + j * sizeof(kCodeSetLocal0), kCodeSetLocal0,
474 sizeof(kCodeSetLocal0)); 443 sizeof(kCodeSetLocal0));
475 } 444 }
476 Verify(kSuccess, &env_v_i, code, code + total); 445 Verify(kSuccess, &env_v_i, code, code + total);
477 free(code); 446 free(code);
478 } 447 }
479 } 448 }
480 449
481 450 TEST_F(AstDecoderTest, BlockN_off_end) {
482 TEST_F(WasmDecoderTest, BlockN_off_end) {
483 for (byte i = 2; i < 10; i++) { 451 for (byte i = 2; i < 10; i++) {
484 byte code[] = {kExprBlock, i, kExprNop}; 452 byte code[] = {kExprBlock, i, kExprNop};
485 EXPECT_FAILURE(&env_v_v, code); 453 EXPECT_FAILURE(&env_v_v, code);
486 } 454 }
487 } 455 }
488 456
489 457 TEST_F(AstDecoderTest, Block1_break) {
490 TEST_F(WasmDecoderTest, Block1_break) {
491 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; 458 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
492 EXPECT_VERIFIES(&env_v_v, code); 459 EXPECT_VERIFIES(&env_v_v, code);
493 } 460 }
494 461
495 462 TEST_F(AstDecoderTest, Block2_break) {
496 TEST_F(WasmDecoderTest, Block2_break) {
497 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 0, kExprNop}; 463 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 0, kExprNop};
498 EXPECT_VERIFIES(&env_v_v, code); 464 EXPECT_VERIFIES(&env_v_v, code);
499 } 465 }
500 466
501 467 TEST_F(AstDecoderTest, Block1_continue) {
502 TEST_F(WasmDecoderTest, Block1_continue) {
503 static const byte code[] = {kExprBlock, 1, kExprBr, 1, kExprNop}; 468 static const byte code[] = {kExprBlock, 1, kExprBr, 1, kExprNop};
504 EXPECT_FAILURE(&env_v_v, code); 469 EXPECT_FAILURE(&env_v_v, code);
505 } 470 }
506 471
507 472 TEST_F(AstDecoderTest, Block2_continue) {
508 TEST_F(WasmDecoderTest, Block2_continue) {
509 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 1, kExprNop}; 473 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 1, kExprNop};
510 EXPECT_FAILURE(&env_v_v, code); 474 EXPECT_FAILURE(&env_v_v, code);
511 } 475 }
512 476
513 477 TEST_F(AstDecoderTest, ExprBlock0) {
514 TEST_F(WasmDecoderTest, ExprBlock0) {
515 static const byte code[] = {kExprBlock, 0}; 478 static const byte code[] = {kExprBlock, 0};
516 EXPECT_VERIFIES(&env_v_v, code); 479 EXPECT_VERIFIES(&env_v_v, code);
517 } 480 }
518 481
519 482 TEST_F(AstDecoderTest, ExprBlock1a) {
520 TEST_F(WasmDecoderTest, ExprBlock1a) {
521 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; 483 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0};
522 EXPECT_VERIFIES(&env_i_i, code); 484 EXPECT_VERIFIES(&env_i_i, code);
523 } 485 }
524 486
525 487 TEST_F(AstDecoderTest, ExprBlock1b) {
526 TEST_F(WasmDecoderTest, ExprBlock1b) {
527 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; 488 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0};
528 EXPECT_FAILURE(&env_f_ff, code); 489 EXPECT_FAILURE(&env_f_ff, code);
529 } 490 }
530 491
531 492 TEST_F(AstDecoderTest, ExprBlock1c) {
532 TEST_F(WasmDecoderTest, ExprBlock1c) {
533 static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0}; 493 static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0};
534 EXPECT_VERIFIES(&env_f_ff, code); 494 EXPECT_VERIFIES(&env_f_ff, code);
535 } 495 }
536 496
537 497 TEST_F(AstDecoderTest, IfEmpty) {
538 TEST_F(WasmDecoderTest, IfEmpty) {
539 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop}; 498 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop};
540 EXPECT_VERIFIES(&env_v_i, code); 499 EXPECT_VERIFIES(&env_v_i, code);
541 } 500 }
542 501
543 502 TEST_F(AstDecoderTest, IfSet) {
544 TEST_F(WasmDecoderTest, IfSet) {
545 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal, 503 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal,
546 0, kExprI8Const, 0, kExprNop}; 504 0, kExprI8Const, 0, kExprNop};
547 EXPECT_VERIFIES(&env_v_i, code); 505 EXPECT_VERIFIES(&env_v_i, code);
548 } 506 }
549 507
550 508 TEST_F(AstDecoderTest, IfBlock1) {
551 TEST_F(WasmDecoderTest, IfBlock1) {
552 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprBlock, 509 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprBlock,
553 1, kExprSetLocal, 0, kExprI8Const, 510 1, kExprSetLocal, 0, kExprI8Const,
554 0, kExprNop}; 511 0, kExprNop};
555 EXPECT_VERIFIES(&env_v_i, code); 512 EXPECT_VERIFIES(&env_v_i, code);
556 } 513 }
557 514
558 515 TEST_F(AstDecoderTest, IfBlock2) {
559 TEST_F(WasmDecoderTest, IfBlock2) {
560 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprBlock, 516 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprBlock,
561 2, kExprSetLocal, 0, kExprI8Const, 517 2, kExprSetLocal, 0, kExprI8Const,
562 0, kExprSetLocal, 0, kExprI8Const, 518 0, kExprSetLocal, 0, kExprI8Const,
563 0}; 519 0};
564 EXPECT_VERIFIES(&env_v_i, code); 520 EXPECT_VERIFIES(&env_v_i, code);
565 } 521 }
566 522
567 523 TEST_F(AstDecoderTest, IfElseEmpty) {
568 TEST_F(WasmDecoderTest, IfElseEmpty) {
569 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprNop, 524 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprNop,
570 kExprNop}; 525 kExprNop};
571 EXPECT_VERIFIES(&env_v_i, code); 526 EXPECT_VERIFIES(&env_v_i, code);
572 } 527 }
573 528
574 529 TEST_F(AstDecoderTest, IfElseSet) {
575 TEST_F(WasmDecoderTest, IfElseSet) {
576 static const byte code[] = {kExprIfElse, 530 static const byte code[] = {kExprIfElse,
577 kExprGetLocal, 531 kExprGetLocal,
578 0, // -- 532 0, // --
579 kExprSetLocal, 533 kExprSetLocal,
580 0, 534 0,
581 kExprI8Const, 535 kExprI8Const,
582 0, // -- 536 0, // --
583 kExprSetLocal, 537 kExprSetLocal,
584 0, 538 0,
585 kExprI8Const, 539 kExprI8Const,
586 1}; // -- 540 1}; // --
587 EXPECT_VERIFIES(&env_v_i, code); 541 EXPECT_VERIFIES(&env_v_i, code);
588 } 542 }
589 543
590 544 TEST_F(AstDecoderTest, IfElseUnreachable) {
591 TEST_F(WasmDecoderTest, IfElseUnreachable) {
592 static const byte code[] = {kExprIfElse, kExprI8Const, 0, 545 static const byte code[] = {kExprIfElse, kExprI8Const, 0,
593 kExprUnreachable, kExprGetLocal, 0}; 546 kExprUnreachable, kExprGetLocal, 0};
594 547
595 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 548 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
596 LocalType types[] = {kAstI32, kLocalTypes[i]}; 549 LocalType types[] = {kAstI32, kLocalTypes[i]};
597 FunctionEnv env; 550 FunctionEnv env;
598 FunctionSig sig(1, 1, types); 551 FunctionSig sig(1, 1, types);
599 init_env(&env, &sig); 552 init_env(&env, &sig);
600 553
601 if (kLocalTypes[i] == kAstI32) { 554 if (kLocalTypes[i] == kAstI32) {
602 EXPECT_VERIFIES(&env, code); 555 EXPECT_VERIFIES(&env, code);
603 } else { 556 } else {
604 EXPECT_FAILURE(&env, code); 557 EXPECT_FAILURE(&env, code);
605 } 558 }
606 } 559 }
607 } 560 }
608 561
609 562 TEST_F(AstDecoderTest, Loop0) {
610 TEST_F(WasmDecoderTest, Loop0) {
611 static const byte code[] = {kExprLoop, 0}; 563 static const byte code[] = {kExprLoop, 0};
612 EXPECT_VERIFIES(&env_v_v, code); 564 EXPECT_VERIFIES(&env_v_v, code);
613 } 565 }
614 566
615 567 TEST_F(AstDecoderTest, Loop1) {
616 TEST_F(WasmDecoderTest, Loop1) {
617 static const byte code[] = {kExprLoop, 1, kExprSetLocal, 0, kExprI8Const, 0}; 568 static const byte code[] = {kExprLoop, 1, kExprSetLocal, 0, kExprI8Const, 0};
618 EXPECT_VERIFIES(&env_v_i, code); 569 EXPECT_VERIFIES(&env_v_i, code);
619 } 570 }
620 571
621 572 TEST_F(AstDecoderTest, Loop2) {
622 TEST_F(WasmDecoderTest, Loop2) {
623 static const byte code[] = {kExprLoop, 2, // -- 573 static const byte code[] = {kExprLoop, 2, // --
624 kExprSetLocal, 0, kExprI8Const, 0, // -- 574 kExprSetLocal, 0, kExprI8Const, 0, // --
625 kExprSetLocal, 0, kExprI8Const, 0}; // -- 575 kExprSetLocal, 0, kExprI8Const, 0}; // --
626 EXPECT_VERIFIES(&env_v_i, code); 576 EXPECT_VERIFIES(&env_v_i, code);
627 } 577 }
628 578
629 579 TEST_F(AstDecoderTest, Loop1_continue) {
630 TEST_F(WasmDecoderTest, Loop1_continue) {
631 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprNop}; 580 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprNop};
632 EXPECT_VERIFIES(&env_v_v, code); 581 EXPECT_VERIFIES(&env_v_v, code);
633 } 582 }
634 583
635 584 TEST_F(AstDecoderTest, Loop1_break) {
636 TEST_F(WasmDecoderTest, Loop1_break) {
637 static const byte code[] = {kExprLoop, 1, kExprBr, 1, kExprNop}; 585 static const byte code[] = {kExprLoop, 1, kExprBr, 1, kExprNop};
638 EXPECT_VERIFIES(&env_v_v, code); 586 EXPECT_VERIFIES(&env_v_v, code);
639 } 587 }
640 588
641 589 TEST_F(AstDecoderTest, Loop2_continue) {
642 TEST_F(WasmDecoderTest, Loop2_continue) {
643 static const byte code[] = {kExprLoop, 2, // -- 590 static const byte code[] = {kExprLoop, 2, // --
644 kExprSetLocal, 0, kExprI8Const, 0, // -- 591 kExprSetLocal, 0, kExprI8Const, 0, // --
645 kExprBr, 0, kExprNop}; // -- 592 kExprBr, 0, kExprNop}; // --
646 EXPECT_VERIFIES(&env_v_i, code); 593 EXPECT_VERIFIES(&env_v_i, code);
647 } 594 }
648 595
649 596 TEST_F(AstDecoderTest, Loop2_break) {
650 TEST_F(WasmDecoderTest, Loop2_break) {
651 static const byte code[] = {kExprLoop, 2, // -- 597 static const byte code[] = {kExprLoop, 2, // --
652 kExprSetLocal, 0, kExprI8Const, 0, // -- 598 kExprSetLocal, 0, kExprI8Const, 0, // --
653 kExprBr, 1, kExprNop}; // -- 599 kExprBr, 1, kExprNop}; // --
654 EXPECT_VERIFIES(&env_v_i, code); 600 EXPECT_VERIFIES(&env_v_i, code);
655 } 601 }
656 602
657 603 TEST_F(AstDecoderTest, ExprLoop0) {
658 TEST_F(WasmDecoderTest, ExprLoop0) {
659 static const byte code[] = {kExprLoop, 0}; 604 static const byte code[] = {kExprLoop, 0};
660 EXPECT_VERIFIES(&env_v_v, code); 605 EXPECT_VERIFIES(&env_v_v, code);
661 } 606 }
662 607
663 608 TEST_F(AstDecoderTest, ExprLoop1a) {
664 TEST_F(WasmDecoderTest, ExprLoop1a) {
665 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; 609 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0};
666 EXPECT_VERIFIES(&env_i_i, code); 610 EXPECT_VERIFIES(&env_i_i, code);
667 } 611 }
668 612
669 613 TEST_F(AstDecoderTest, ExprLoop1b) {
670 TEST_F(WasmDecoderTest, ExprLoop1b) {
671 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; 614 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0};
672 EXPECT_VERIFIES(&env_i_i, code); 615 EXPECT_VERIFIES(&env_i_i, code);
673 } 616 }
674 617
675 618 TEST_F(AstDecoderTest, ExprLoop2_unreachable) {
676 TEST_F(WasmDecoderTest, ExprLoop2_unreachable) {
677 static const byte code[] = {kExprLoop, 2, kExprBr, 0, 619 static const byte code[] = {kExprLoop, 2, kExprBr, 0,
678 kExprI8Const, 0, kExprNop}; 620 kExprI8Const, 0, kExprNop};
679 EXPECT_VERIFIES(&env_i_i, code); 621 EXPECT_VERIFIES(&env_i_i, code);
680 } 622 }
681 623
682 624 TEST_F(AstDecoderTest, ReturnVoid1) {
683 TEST_F(WasmDecoderTest, ReturnVoid1) {
684 static const byte code[] = {kExprNop}; 625 static const byte code[] = {kExprNop};
685 EXPECT_VERIFIES(&env_v_v, code); 626 EXPECT_VERIFIES(&env_v_v, code);
686 EXPECT_FAILURE(&env_i_i, code); 627 EXPECT_FAILURE(&env_i_i, code);
687 EXPECT_FAILURE(&env_i_f, code); 628 EXPECT_FAILURE(&env_i_f, code);
688 } 629 }
689 630
690 631 TEST_F(AstDecoderTest, ReturnVoid2) {
691 TEST_F(WasmDecoderTest, ReturnVoid2) {
692 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; 632 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
693 EXPECT_VERIFIES(&env_v_v, code); 633 EXPECT_VERIFIES(&env_v_v, code);
694 EXPECT_FAILURE(&env_i_i, code); 634 EXPECT_FAILURE(&env_i_i, code);
695 EXPECT_FAILURE(&env_i_f, code); 635 EXPECT_FAILURE(&env_i_f, code);
696 } 636 }
697 637
698 638 TEST_F(AstDecoderTest, ReturnVoid3) {
699 TEST_F(WasmDecoderTest, ReturnVoid3) {
700 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI8Const, 0); 639 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI8Const, 0);
701 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI32Const, 0, 0, 0, 0); 640 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI32Const, 0, 0, 0, 0);
702 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0); 641 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0);
703 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF32Const, 0, 0, 0, 0); 642 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF32Const, 0, 0, 0, 0);
704 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 643 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
705 644
706 EXPECT_VERIFIES_INLINE(&env_v_i, kExprGetLocal, 0); 645 EXPECT_VERIFIES_INLINE(&env_v_i, kExprGetLocal, 0);
707 } 646 }
708 647
709 648 TEST_F(AstDecoderTest, Unreachable1) {
710 TEST_F(WasmDecoderTest, Unreachable1) {
711 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable); 649 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable);
712 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable, kExprUnreachable); 650 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable, kExprUnreachable);
713 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO)); 651 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO));
714 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_BR(0), WASM_ZERO)); 652 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_BR(0), WASM_ZERO));
715 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO)); 653 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO));
716 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_BR(0), WASM_ZERO)); 654 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_BR(0), WASM_ZERO));
717 } 655 }
718 656
719 657 TEST_F(AstDecoderTest, Codeiness) {
720 TEST_F(WasmDecoderTest, Codeiness) {
721 VERIFY(kExprLoop, 2, // -- 658 VERIFY(kExprLoop, 2, // --
722 kExprSetLocal, 0, kExprI8Const, 0, // -- 659 kExprSetLocal, 0, kExprI8Const, 0, // --
723 kExprBr, 0, kExprNop); // -- 660 kExprBr, 0, kExprNop); // --
724 } 661 }
725 662
726 663 TEST_F(AstDecoderTest, ExprIf1) {
727 TEST_F(WasmDecoderTest, ExprIf1) {
728 VERIFY(kExprIf, kExprGetLocal, 0, kExprI8Const, 0, kExprI8Const, 1); 664 VERIFY(kExprIf, kExprGetLocal, 0, kExprI8Const, 0, kExprI8Const, 1);
729 VERIFY(kExprIf, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0); 665 VERIFY(kExprIf, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0);
730 VERIFY(kExprIf, kExprGetLocal, 0, kExprI32Add, kExprGetLocal, 0, 666 VERIFY(kExprIf, kExprGetLocal, 0, kExprI32Add, kExprGetLocal, 0,
731 kExprGetLocal, 0, kExprI8Const, 1); 667 kExprGetLocal, 0, kExprI8Const, 1);
732 } 668 }
733 669
734 670 TEST_F(AstDecoderTest, ExprIf_off_end) {
735 TEST_F(WasmDecoderTest, ExprIf_off_end) {
736 static const byte kCode[] = {kExprIf, kExprGetLocal, 0, kExprGetLocal, 671 static const byte kCode[] = {kExprIf, kExprGetLocal, 0, kExprGetLocal,
737 0, kExprGetLocal, 0}; 672 0, kExprGetLocal, 0};
738 for (size_t len = 1; len < arraysize(kCode); len++) { 673 for (size_t len = 1; len < arraysize(kCode); len++) {
739 Verify(kError, &env_i_i, kCode, kCode + len); 674 Verify(kError, &env_i_i, kCode, kCode + len);
740 } 675 }
741 } 676 }
742 677
743 678 TEST_F(AstDecoderTest, ExprIf_type) {
744 TEST_F(WasmDecoderTest, ExprIf_type) {
745 { 679 {
746 // float|double ? 1 : 2 680 // float|double ? 1 : 2
747 static const byte kCode[] = {kExprIfElse, kExprGetLocal, 0, kExprI8Const, 681 static const byte kCode[] = {kExprIfElse, kExprGetLocal, 0, kExprI8Const,
748 1, kExprI8Const, 2}; 682 1, kExprI8Const, 2};
749 EXPECT_FAILURE(&env_i_f, kCode); 683 EXPECT_FAILURE(&env_i_f, kCode);
750 EXPECT_FAILURE(&env_i_d, kCode); 684 EXPECT_FAILURE(&env_i_d, kCode);
751 } 685 }
752 { 686 {
753 // 1 ? float|double : 2 687 // 1 ? float|double : 2
754 static const byte kCode[] = {kExprIfElse, kExprI8Const, 1, kExprGetLocal, 688 static const byte kCode[] = {kExprIfElse, kExprI8Const, 1, kExprGetLocal,
(...skipping 14 matching lines...) Expand all
769 EXPECT_FAILURE(&env_i_i, kCode); 703 EXPECT_FAILURE(&env_i_i, kCode);
770 } 704 }
771 { 705 {
772 // 0 ? 1 : stmt 706 // 0 ? 1 : stmt
773 static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, kExprI8Const, 1, 707 static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, kExprI8Const, 1,
774 0, kExprBlock}; 708 0, kExprBlock};
775 EXPECT_FAILURE(&env_i_i, kCode); 709 EXPECT_FAILURE(&env_i_i, kCode);
776 } 710 }
777 } 711 }
778 712
779 713 TEST_F(AstDecoderTest, Int64Local_param) {
780 TEST_F(WasmDecoderTest, Int64Local_param) {
781 EXPECT_VERIFIES(&env_l_l, kCodeGetLocal0); 714 EXPECT_VERIFIES(&env_l_l, kCodeGetLocal0);
782 } 715 }
783 716
784 717 TEST_F(AstDecoderTest, Int64Locals) {
785 TEST_F(WasmDecoderTest, Int64Locals) {
786 for (byte i = 1; i < 8; i++) { 718 for (byte i = 1; i < 8; i++) {
787 FunctionEnv env; 719 FunctionEnv env;
788 init_env(&env, sigs.l_v()); 720 init_env(&env, sigs.l_v());
789 env.AddLocals(kAstI64, i); 721 env.AddLocals(kAstI64, i);
790 for (byte j = 0; j < i; j++) { 722 for (byte j = 0; j < i; j++) {
791 byte code[] = {kExprGetLocal, j}; 723 byte code[] = {kExprGetLocal, j};
792 EXPECT_VERIFIES(&env, code); 724 EXPECT_VERIFIES(&env, code);
793 } 725 }
794 } 726 }
795 } 727 }
796 728
797 729 TEST_F(AstDecoderTest, Int32Binops) {
798 TEST_F(WasmDecoderTest, Int32Binops) {
799 TestBinop(kExprI32Add, sigs.i_ii()); 730 TestBinop(kExprI32Add, sigs.i_ii());
800 TestBinop(kExprI32Sub, sigs.i_ii()); 731 TestBinop(kExprI32Sub, sigs.i_ii());
801 TestBinop(kExprI32Mul, sigs.i_ii()); 732 TestBinop(kExprI32Mul, sigs.i_ii());
802 TestBinop(kExprI32DivS, sigs.i_ii()); 733 TestBinop(kExprI32DivS, sigs.i_ii());
803 TestBinop(kExprI32DivU, sigs.i_ii()); 734 TestBinop(kExprI32DivU, sigs.i_ii());
804 TestBinop(kExprI32RemS, sigs.i_ii()); 735 TestBinop(kExprI32RemS, sigs.i_ii());
805 TestBinop(kExprI32RemU, sigs.i_ii()); 736 TestBinop(kExprI32RemU, sigs.i_ii());
806 TestBinop(kExprI32And, sigs.i_ii()); 737 TestBinop(kExprI32And, sigs.i_ii());
807 TestBinop(kExprI32Ior, sigs.i_ii()); 738 TestBinop(kExprI32Ior, sigs.i_ii());
808 TestBinop(kExprI32Xor, sigs.i_ii()); 739 TestBinop(kExprI32Xor, sigs.i_ii());
809 TestBinop(kExprI32Shl, sigs.i_ii()); 740 TestBinop(kExprI32Shl, sigs.i_ii());
810 TestBinop(kExprI32ShrU, sigs.i_ii()); 741 TestBinop(kExprI32ShrU, sigs.i_ii());
811 TestBinop(kExprI32ShrS, sigs.i_ii()); 742 TestBinop(kExprI32ShrS, sigs.i_ii());
812 TestBinop(kExprI32Eq, sigs.i_ii()); 743 TestBinop(kExprI32Eq, sigs.i_ii());
813 TestBinop(kExprI32LtS, sigs.i_ii()); 744 TestBinop(kExprI32LtS, sigs.i_ii());
814 TestBinop(kExprI32LeS, sigs.i_ii()); 745 TestBinop(kExprI32LeS, sigs.i_ii());
815 TestBinop(kExprI32LtU, sigs.i_ii()); 746 TestBinop(kExprI32LtU, sigs.i_ii());
816 TestBinop(kExprI32LeU, sigs.i_ii()); 747 TestBinop(kExprI32LeU, sigs.i_ii());
817 } 748 }
818 749
819 750 TEST_F(AstDecoderTest, DoubleBinops) {
820 TEST_F(WasmDecoderTest, DoubleBinops) {
821 TestBinop(kExprF64Add, sigs.d_dd()); 751 TestBinop(kExprF64Add, sigs.d_dd());
822 TestBinop(kExprF64Sub, sigs.d_dd()); 752 TestBinop(kExprF64Sub, sigs.d_dd());
823 TestBinop(kExprF64Mul, sigs.d_dd()); 753 TestBinop(kExprF64Mul, sigs.d_dd());
824 TestBinop(kExprF64Div, sigs.d_dd()); 754 TestBinop(kExprF64Div, sigs.d_dd());
825 755
826 TestBinop(kExprF64Eq, sigs.i_dd()); 756 TestBinop(kExprF64Eq, sigs.i_dd());
827 TestBinop(kExprF64Lt, sigs.i_dd()); 757 TestBinop(kExprF64Lt, sigs.i_dd());
828 TestBinop(kExprF64Le, sigs.i_dd()); 758 TestBinop(kExprF64Le, sigs.i_dd());
829 } 759 }
830 760
831 761 TEST_F(AstDecoderTest, FloatBinops) {
832 TEST_F(WasmDecoderTest, FloatBinops) {
833 TestBinop(kExprF32Add, sigs.f_ff()); 762 TestBinop(kExprF32Add, sigs.f_ff());
834 TestBinop(kExprF32Sub, sigs.f_ff()); 763 TestBinop(kExprF32Sub, sigs.f_ff());
835 TestBinop(kExprF32Mul, sigs.f_ff()); 764 TestBinop(kExprF32Mul, sigs.f_ff());
836 TestBinop(kExprF32Div, sigs.f_ff()); 765 TestBinop(kExprF32Div, sigs.f_ff());
837 766
838 TestBinop(kExprF32Eq, sigs.i_ff()); 767 TestBinop(kExprF32Eq, sigs.i_ff());
839 TestBinop(kExprF32Lt, sigs.i_ff()); 768 TestBinop(kExprF32Lt, sigs.i_ff());
840 TestBinop(kExprF32Le, sigs.i_ff()); 769 TestBinop(kExprF32Le, sigs.i_ff());
841 } 770 }
842 771
843 772 TEST_F(AstDecoderTest, TypeConversions) {
844 TEST_F(WasmDecoderTest, TypeConversions) {
845 TestUnop(kExprI32SConvertF32, kAstI32, kAstF32); 773 TestUnop(kExprI32SConvertF32, kAstI32, kAstF32);
846 TestUnop(kExprI32SConvertF64, kAstI32, kAstF64); 774 TestUnop(kExprI32SConvertF64, kAstI32, kAstF64);
847 TestUnop(kExprI32UConvertF32, kAstI32, kAstF32); 775 TestUnop(kExprI32UConvertF32, kAstI32, kAstF32);
848 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); 776 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64);
849 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); 777 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32);
850 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); 778 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32);
851 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); 779 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32);
852 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); 780 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32);
853 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); 781 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32);
854 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); 782 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64);
855 } 783 }
856 784
857 785 TEST_F(AstDecoderTest, MacrosStmt) {
858 TEST_F(WasmDecoderTest, MacrosStmt) {
859 VERIFY(WASM_SET_LOCAL(0, WASM_I32(87348))); 786 VERIFY(WASM_SET_LOCAL(0, WASM_I32(87348)));
860 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); 787 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
861 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 788 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
862 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 789 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
863 VERIFY(WASM_NOP); 790 VERIFY(WASM_NOP);
864 VERIFY(WASM_BLOCK(1, WASM_NOP)); 791 VERIFY(WASM_BLOCK(1, WASM_NOP));
865 VERIFY(WASM_LOOP(1, WASM_NOP)); 792 VERIFY(WASM_LOOP(1, WASM_NOP));
866 VERIFY(WASM_LOOP(1, WASM_BREAK(0))); 793 VERIFY(WASM_LOOP(1, WASM_BREAK(0)));
867 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0))); 794 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0)));
868 } 795 }
869 796
870 797 TEST_F(AstDecoderTest, MacrosBreak) {
871 TEST_F(WasmDecoderTest, MacrosBreak) {
872 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0))); 798 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0)));
873 799
874 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO))); 800 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
875 EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0)))); 801 EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0))));
876 EXPECT_VERIFIES_INLINE(&env_f_ff, 802 EXPECT_VERIFIES_INLINE(&env_f_ff,
877 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0)))); 803 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
878 EXPECT_VERIFIES_INLINE(&env_d_dd, 804 EXPECT_VERIFIES_INLINE(&env_d_dd,
879 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0)))); 805 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0))));
880 } 806 }
881 807
882 808 TEST_F(AstDecoderTest, MacrosContinue) {
883 TEST_F(WasmDecoderTest, MacrosContinue) {
884 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_CONTINUE(0))); 809 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_CONTINUE(0)));
885 } 810 }
886 811
887 812 TEST_F(AstDecoderTest, MacrosVariadic) {
888 TEST_F(WasmDecoderTest, MacrosVariadic) {
889 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP)); 813 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP));
890 VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP)); 814 VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP));
891 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP)); 815 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP));
892 VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP)); 816 VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP));
893 } 817 }
894 818
895 819 TEST_F(AstDecoderTest, MacrosNestedBlocks) {
896 TEST_F(WasmDecoderTest, MacrosNestedBlocks) {
897 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_BLOCK(2, WASM_NOP, WASM_NOP))); 820 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_BLOCK(2, WASM_NOP, WASM_NOP)));
898 VERIFY(WASM_BLOCK(3, WASM_NOP, // -- 821 VERIFY(WASM_BLOCK(3, WASM_NOP, // --
899 WASM_BLOCK(2, WASM_NOP, WASM_NOP), // -- 822 WASM_BLOCK(2, WASM_NOP, WASM_NOP), // --
900 WASM_BLOCK(2, WASM_NOP, WASM_NOP))); // -- 823 WASM_BLOCK(2, WASM_NOP, WASM_NOP))); // --
901 VERIFY(WASM_BLOCK(1, WASM_BLOCK(1, WASM_BLOCK(2, WASM_NOP, WASM_NOP)))); 824 VERIFY(WASM_BLOCK(1, WASM_BLOCK(1, WASM_BLOCK(2, WASM_NOP, WASM_NOP))));
902 } 825 }
903 826
904 827 TEST_F(AstDecoderTest, MultipleReturn) {
905 TEST_F(WasmDecoderTest, MultipleReturn) {
906 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; 828 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
907 FunctionSig sig_ii_v(2, 0, kIntTypes5); 829 FunctionSig sig_ii_v(2, 0, kIntTypes5);
908 FunctionEnv env_ii_v; 830 FunctionEnv env_ii_v;
909 init_env(&env_ii_v, &sig_ii_v); 831 init_env(&env_ii_v, &sig_ii_v);
910 EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); 832 EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
911 EXPECT_FAILURE_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO)); 833 EXPECT_FAILURE_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO));
912 834
913 FunctionSig sig_iii_v(3, 0, kIntTypes5); 835 FunctionSig sig_iii_v(3, 0, kIntTypes5);
914 FunctionEnv env_iii_v; 836 FunctionEnv env_iii_v;
915 init_env(&env_iii_v, &sig_iii_v); 837 init_env(&env_iii_v, &sig_iii_v);
916 EXPECT_VERIFIES_INLINE(&env_iii_v, 838 EXPECT_VERIFIES_INLINE(&env_iii_v,
917 WASM_RETURN(WASM_ZERO, WASM_ONE, WASM_I8(44))); 839 WASM_RETURN(WASM_ZERO, WASM_ONE, WASM_I8(44)));
918 EXPECT_FAILURE_INLINE(&env_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); 840 EXPECT_FAILURE_INLINE(&env_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
919 } 841 }
920 842
921 843 TEST_F(AstDecoderTest, MultipleReturn_fallthru) {
922 TEST_F(WasmDecoderTest, MultipleReturn_fallthru) {
923 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; 844 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
924 FunctionSig sig_ii_v(2, 0, kIntTypes5); 845 FunctionSig sig_ii_v(2, 0, kIntTypes5);
925 FunctionEnv env_ii_v; 846 FunctionEnv env_ii_v;
926 init_env(&env_ii_v, &sig_ii_v); 847 init_env(&env_ii_v, &sig_ii_v);
927 848
928 EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_ZERO, WASM_ONE); 849 EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_ZERO, WASM_ONE);
929 EXPECT_FAILURE_INLINE(&env_ii_v, WASM_ZERO); 850 EXPECT_FAILURE_INLINE(&env_ii_v, WASM_ZERO);
930 851
931 FunctionSig sig_iii_v(3, 0, kIntTypes5); 852 FunctionSig sig_iii_v(3, 0, kIntTypes5);
932 FunctionEnv env_iii_v; 853 FunctionEnv env_iii_v;
933 init_env(&env_iii_v, &sig_iii_v); 854 init_env(&env_iii_v, &sig_iii_v);
934 EXPECT_VERIFIES_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); 855 EXPECT_VERIFIES_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44));
935 EXPECT_FAILURE_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE); 856 EXPECT_FAILURE_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE);
936 } 857 }
937 858
938 859 TEST_F(AstDecoderTest, MacrosInt32) {
939 TEST_F(WasmDecoderTest, MacrosInt32) {
940 VERIFY(WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); 860 VERIFY(WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12)));
941 VERIFY(WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); 861 VERIFY(WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13)));
942 VERIFY(WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); 862 VERIFY(WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14)));
943 VERIFY(WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); 863 VERIFY(WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15)));
944 VERIFY(WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); 864 VERIFY(WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16)));
945 VERIFY(WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); 865 VERIFY(WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17)));
946 VERIFY(WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); 866 VERIFY(WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18)));
947 VERIFY(WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); 867 VERIFY(WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19)));
948 VERIFY(WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); 868 VERIFY(WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20)));
949 VERIFY(WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); 869 VERIFY(WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21)));
950 VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); 870 VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22)));
951 VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); 871 VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23)));
952 VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); 872 VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24)));
953 VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); 873 VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25)));
954 VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); 874 VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25)));
955 875
956 VERIFY(WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); 876 VERIFY(WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26)));
957 VERIFY(WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); 877 VERIFY(WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27)));
958 VERIFY(WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); 878 VERIFY(WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28)));
959 VERIFY(WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); 879 VERIFY(WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29)));
960 880
961 VERIFY(WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); 881 VERIFY(WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26)));
962 VERIFY(WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); 882 VERIFY(WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27)));
963 VERIFY(WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); 883 VERIFY(WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28)));
964 VERIFY(WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); 884 VERIFY(WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29)));
965 } 885 }
966 886
967 887 TEST_F(AstDecoderTest, MacrosInt64) {
968 TEST_F(WasmDecoderTest, MacrosInt64) {
969 FunctionEnv env_i_ll; 888 FunctionEnv env_i_ll;
970 FunctionEnv env_l_ll; 889 FunctionEnv env_l_ll;
971 init_env(&env_i_ll, sigs.i_ll()); 890 init_env(&env_i_ll, sigs.i_ll());
972 init_env(&env_l_ll, sigs.l_ll()); 891 init_env(&env_l_ll, sigs.l_ll());
973 892
974 #define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(&env_l_ll, __VA_ARGS__) 893 #define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(&env_l_ll, __VA_ARGS__)
975 #define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(&env_i_ll, __VA_ARGS__) 894 #define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(&env_i_ll, __VA_ARGS__)
976 895
977 VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64(12))); 896 VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64(12)));
978 VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64(13))); 897 VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64(13)));
(...skipping 17 matching lines...) Expand all
996 915
997 VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64(26))); 916 VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64(26)));
998 VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64(27))); 917 VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64(27)));
999 VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64(28))); 918 VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64(28)));
1000 VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64(29))); 919 VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64(29)));
1001 920
1002 VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64(25))); 921 VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64(25)));
1003 VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64(25))); 922 VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64(25)));
1004 } 923 }
1005 924
1006 925 TEST_F(AstDecoderTest, AllSimpleExpressions) {
1007 TEST_F(WasmDecoderTest, AllSimpleExpressions) {
1008 // Test all simple expressions which are described by a signature. 926 // Test all simple expressions which are described by a signature.
1009 #define DECODE_TEST(name, opcode, sig) \ 927 #define DECODE_TEST(name, opcode, sig) \
1010 { \ 928 { \
1011 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \ 929 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \
1012 if (sig->parameter_count() == 1) { \ 930 if (sig->parameter_count() == 1) { \
1013 TestUnop(kExpr##name, sig); \ 931 TestUnop(kExpr##name, sig); \
1014 } else { \ 932 } else { \
1015 TestBinop(kExpr##name, sig); \ 933 TestBinop(kExpr##name, sig); \
1016 } \ 934 } \
1017 } 935 }
1018 936
1019 FOREACH_SIMPLE_OPCODE(DECODE_TEST); 937 FOREACH_SIMPLE_OPCODE(DECODE_TEST);
1020 938
1021 #undef DECODE_TEST 939 #undef DECODE_TEST
1022 } 940 }
1023 941
1024 942 TEST_F(AstDecoderTest, MemorySize) {
1025 TEST_F(WasmDecoderTest, MemorySize) {
1026 byte code[] = {kExprMemorySize}; 943 byte code[] = {kExprMemorySize};
1027 EXPECT_VERIFIES(&env_i_i, code); 944 EXPECT_VERIFIES(&env_i_i, code);
1028 EXPECT_FAILURE(&env_f_ff, code); 945 EXPECT_FAILURE(&env_f_ff, code);
1029 } 946 }
1030 947
1031 948 TEST_F(AstDecoderTest, GrowMemory) {
1032 TEST_F(WasmDecoderTest, GrowMemory) {
1033 byte code[] = {kExprGrowMemory, kExprGetLocal, 0}; 949 byte code[] = {kExprGrowMemory, kExprGetLocal, 0};
1034 EXPECT_VERIFIES(&env_i_i, code); 950 EXPECT_VERIFIES(&env_i_i, code);
1035 EXPECT_FAILURE(&env_i_d, code); 951 EXPECT_FAILURE(&env_i_d, code);
1036 } 952 }
1037 953
1038 954 TEST_F(AstDecoderTest, LoadMemOffset) {
1039 TEST_F(WasmDecoderTest, LoadMemOffset) {
1040 for (int offset = 0; offset < 128; offset += 7) { 955 for (int offset = 0; offset < 128; offset += 7) {
1041 byte code[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), 956 byte code[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true),
1042 static_cast<byte>(offset), kExprI8Const, 0}; 957 static_cast<byte>(offset), kExprI8Const, 0};
1043 EXPECT_VERIFIES(&env_i_i, code); 958 EXPECT_VERIFIES(&env_i_i, code);
1044 } 959 }
1045 } 960 }
1046 961
1047 962 TEST_F(AstDecoderTest, StoreMemOffset) {
1048 TEST_F(WasmDecoderTest, StoreMemOffset) {
1049 for (int offset = 0; offset < 128; offset += 7) { 963 for (int offset = 0; offset < 128; offset += 7) {
1050 byte code[] = {kExprI32StoreMem, 964 byte code[] = {kExprI32StoreMem,
1051 WasmOpcodes::LoadStoreAccessOf(true), 965 WasmOpcodes::LoadStoreAccessOf(true),
1052 static_cast<byte>(offset), 966 static_cast<byte>(offset),
1053 kExprI8Const, 967 kExprI8Const,
1054 0, 968 0,
1055 kExprI8Const, 969 kExprI8Const,
1056 0}; 970 0};
1057 EXPECT_VERIFIES(&env_i_i, code); 971 EXPECT_VERIFIES(&env_i_i, code);
1058 } 972 }
1059 } 973 }
1060 974
1061 975 TEST_F(AstDecoderTest, LoadMemOffset_varint) {
1062 TEST_F(WasmDecoderTest, LoadMemOffset_varint) {
1063 byte code1[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), 0, 976 byte code1[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), 0,
1064 kExprI8Const, 0}; 977 kExprI8Const, 0};
1065 byte code2[] = {kExprI32LoadMem, 978 byte code2[] = {kExprI32LoadMem,
1066 WasmOpcodes::LoadStoreAccessOf(true), 979 WasmOpcodes::LoadStoreAccessOf(true),
1067 0x80, 980 0x80,
1068 1, 981 1,
1069 kExprI8Const, 982 kExprI8Const,
1070 0}; 983 0};
1071 byte code3[] = {kExprI32LoadMem, 984 byte code3[] = {kExprI32LoadMem,
1072 WasmOpcodes::LoadStoreAccessOf(true), 985 WasmOpcodes::LoadStoreAccessOf(true),
(...skipping 10 matching lines...) Expand all
1083 7, 996 7,
1084 kExprI8Const, 997 kExprI8Const,
1085 0}; 998 0};
1086 999
1087 EXPECT_VERIFIES(&env_i_i, code1); 1000 EXPECT_VERIFIES(&env_i_i, code1);
1088 EXPECT_VERIFIES(&env_i_i, code2); 1001 EXPECT_VERIFIES(&env_i_i, code2);
1089 EXPECT_VERIFIES(&env_i_i, code3); 1002 EXPECT_VERIFIES(&env_i_i, code3);
1090 EXPECT_VERIFIES(&env_i_i, code4); 1003 EXPECT_VERIFIES(&env_i_i, code4);
1091 } 1004 }
1092 1005
1093 1006 TEST_F(AstDecoderTest, StoreMemOffset_varint) {
1094 TEST_F(WasmDecoderTest, StoreMemOffset_varint) {
1095 byte code1[] = {kExprI32StoreMem, 1007 byte code1[] = {kExprI32StoreMem,
1096 WasmOpcodes::LoadStoreAccessOf(true), 1008 WasmOpcodes::LoadStoreAccessOf(true),
1097 0, 1009 0,
1098 kExprI8Const, 1010 kExprI8Const,
1099 0, 1011 0,
1100 kExprI8Const, 1012 kExprI8Const,
1101 0}; 1013 0};
1102 byte code2[] = {kExprI32StoreMem, 1014 byte code2[] = {kExprI32StoreMem,
1103 WasmOpcodes::LoadStoreAccessOf(true), 1015 WasmOpcodes::LoadStoreAccessOf(true),
1104 0x80, 1016 0x80,
(...skipping 21 matching lines...) Expand all
1126 0, 1038 0,
1127 kExprI8Const, 1039 kExprI8Const,
1128 0}; 1040 0};
1129 1041
1130 EXPECT_VERIFIES(&env_i_i, code1); 1042 EXPECT_VERIFIES(&env_i_i, code1);
1131 EXPECT_VERIFIES(&env_i_i, code2); 1043 EXPECT_VERIFIES(&env_i_i, code2);
1132 EXPECT_VERIFIES(&env_i_i, code3); 1044 EXPECT_VERIFIES(&env_i_i, code3);
1133 EXPECT_VERIFIES(&env_i_i, code4); 1045 EXPECT_VERIFIES(&env_i_i, code4);
1134 } 1046 }
1135 1047
1136 1048 TEST_F(AstDecoderTest, AllLoadMemCombinations) {
1137 TEST_F(WasmDecoderTest, AllLoadMemCombinations) {
1138 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1049 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1139 LocalType local_type = kLocalTypes[i]; 1050 LocalType local_type = kLocalTypes[i];
1140 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1051 for (size_t j = 0; j < arraysize(machineTypes); j++) {
1141 MachineType mem_type = machineTypes[j]; 1052 MachineType mem_type = machineTypes[j];
1142 byte code[] = { 1053 byte code[] = {
1143 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)), 1054 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)),
1144 WasmOpcodes::LoadStoreAccessOf(false), kExprI8Const, 0}; 1055 WasmOpcodes::LoadStoreAccessOf(false), kExprI8Const, 0};
1145 FunctionEnv env; 1056 FunctionEnv env;
1146 FunctionSig sig(1, 0, &local_type); 1057 FunctionSig sig(1, 0, &local_type);
1147 init_env(&env, &sig); 1058 init_env(&env, &sig);
1148 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1059 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
1149 EXPECT_VERIFIES(&env, code); 1060 EXPECT_VERIFIES(&env, code);
1150 } else { 1061 } else {
1151 EXPECT_FAILURE(&env, code); 1062 EXPECT_FAILURE(&env, code);
1152 } 1063 }
1153 } 1064 }
1154 } 1065 }
1155 } 1066 }
1156 1067
1157 1068 TEST_F(AstDecoderTest, AllStoreMemCombinations) {
1158 TEST_F(WasmDecoderTest, AllStoreMemCombinations) {
1159 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1069 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1160 LocalType local_type = kLocalTypes[i]; 1070 LocalType local_type = kLocalTypes[i];
1161 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1071 for (size_t j = 0; j < arraysize(machineTypes); j++) {
1162 MachineType mem_type = machineTypes[j]; 1072 MachineType mem_type = machineTypes[j];
1163 byte code[] = { 1073 byte code[] = {
1164 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)), 1074 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)),
1165 WasmOpcodes::LoadStoreAccessOf(false), 1075 WasmOpcodes::LoadStoreAccessOf(false),
1166 kExprI8Const, 1076 kExprI8Const,
1167 0, 1077 0,
1168 kExprGetLocal, 1078 kExprGetLocal,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 mod.import_table.push_back({sig, 0, 0}); 1119 mod.import_table.push_back({sig, 0, 0});
1210 CHECK(mod.import_table.size() <= 127); 1120 CHECK(mod.import_table.size() <= 127);
1211 return static_cast<byte>(mod.import_table.size() - 1); 1121 return static_cast<byte>(mod.import_table.size() - 1);
1212 } 1122 }
1213 1123
1214 private: 1124 private:
1215 WasmModule mod; 1125 WasmModule mod;
1216 }; 1126 };
1217 } // namespace 1127 } // namespace
1218 1128
1219 1129 TEST_F(AstDecoderTest, SimpleCalls) {
1220 TEST_F(WasmDecoderTest, SimpleCalls) {
1221 FunctionEnv* env = &env_i_i; 1130 FunctionEnv* env = &env_i_i;
1222 TestModuleEnv module_env; 1131 TestModuleEnv module_env;
1223 env->module = &module_env; 1132 env->module = &module_env;
1224 1133
1225 module_env.AddFunction(sigs.i_v()); 1134 module_env.AddFunction(sigs.i_v());
1226 module_env.AddFunction(sigs.i_i()); 1135 module_env.AddFunction(sigs.i_i());
1227 module_env.AddFunction(sigs.i_ii()); 1136 module_env.AddFunction(sigs.i_ii());
1228 1137
1229 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(0)); 1138 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(0));
1230 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(27))); 1139 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(27)));
1231 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); 1140 EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77)));
1232 } 1141 }
1233 1142
1234 1143 TEST_F(AstDecoderTest, CallsWithTooFewArguments) {
1235 TEST_F(WasmDecoderTest, CallsWithTooFewArguments) {
1236 FunctionEnv* env = &env_i_i; 1144 FunctionEnv* env = &env_i_i;
1237 TestModuleEnv module_env; 1145 TestModuleEnv module_env;
1238 env->module = &module_env; 1146 env->module = &module_env;
1239 1147
1240 module_env.AddFunction(sigs.i_i()); 1148 module_env.AddFunction(sigs.i_i());
1241 module_env.AddFunction(sigs.i_ii()); 1149 module_env.AddFunction(sigs.i_ii());
1242 module_env.AddFunction(sigs.f_ff()); 1150 module_env.AddFunction(sigs.f_ff());
1243 1151
1244 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION0(0)); 1152 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION0(0));
1245 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_ZERO)); 1153 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_ZERO));
1246 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); 1154 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0)));
1247 } 1155 }
1248 1156
1249 1157 TEST_F(AstDecoderTest, CallsWithSpilloverArgs) {
1250 TEST_F(WasmDecoderTest, CallsWithSpilloverArgs) {
1251 static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32}; 1158 static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32};
1252 FunctionSig sig_i_ff(1, 2, a_i_ff); 1159 FunctionSig sig_i_ff(1, 2, a_i_ff);
1253 FunctionEnv env_i_ff; 1160 FunctionEnv env_i_ff;
1254 init_env(&env_i_ff, &sig_i_ff); 1161 init_env(&env_i_ff, &sig_i_ff);
1255 1162
1256 TestModuleEnv module_env; 1163 TestModuleEnv module_env;
1257 env_i_ff.module = &module_env; 1164 env_i_ff.module = &module_env;
1258 env_i_i.module = &module_env; 1165 env_i_i.module = &module_env;
1259 env_f_ff.module = &module_env; 1166 env_f_ff.module = &module_env;
1260 1167
(...skipping 10 matching lines...) Expand all
1271 1178
1272 EXPECT_FAILURE_INLINE( 1179 EXPECT_FAILURE_INLINE(
1273 &env_i_i, 1180 &env_i_i,
1274 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(0.2))); 1181 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(0.2)));
1275 1182
1276 EXPECT_VERIFIES_INLINE( 1183 EXPECT_VERIFIES_INLINE(
1277 &env_f_ff, 1184 &env_f_ff,
1278 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(11))); 1185 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(11)));
1279 } 1186 }
1280 1187
1281 1188 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) {
1282 TEST_F(WasmDecoderTest, CallsWithMismatchedSigs2) {
1283 FunctionEnv* env = &env_i_i; 1189 FunctionEnv* env = &env_i_i;
1284 TestModuleEnv module_env; 1190 TestModuleEnv module_env;
1285 env->module = &module_env; 1191 env->module = &module_env;
1286 1192
1287 module_env.AddFunction(sigs.i_i()); 1193 module_env.AddFunction(sigs.i_i());
1288 1194
1289 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(17))); 1195 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(17)));
1290 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); 1196 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F32(17.1)));
1291 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); 1197 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
1292 } 1198 }
1293 1199
1294 1200 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) {
1295 TEST_F(WasmDecoderTest, CallsWithMismatchedSigs3) {
1296 FunctionEnv* env = &env_i_i; 1201 FunctionEnv* env = &env_i_i;
1297 TestModuleEnv module_env; 1202 TestModuleEnv module_env;
1298 env->module = &module_env; 1203 env->module = &module_env;
1299 1204
1300 module_env.AddFunction(sigs.i_f()); 1205 module_env.AddFunction(sigs.i_f());
1301 1206
1302 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I8(17))); 1207 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I8(17)));
1303 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27))); 1208 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27)));
1304 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); 1209 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
1305 1210
1306 module_env.AddFunction(sigs.i_d()); 1211 module_env.AddFunction(sigs.i_d());
1307 1212
1308 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16))); 1213 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16)));
1309 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16))); 1214 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16)));
1310 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); 1215 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
1311 } 1216 }
1312 1217
1313 1218 TEST_F(AstDecoderTest, SimpleIndirectCalls) {
1314 TEST_F(WasmDecoderTest, SimpleIndirectCalls) {
1315 FunctionEnv* env = &env_i_i; 1219 FunctionEnv* env = &env_i_i;
1316 TestModuleEnv module_env; 1220 TestModuleEnv module_env;
1317 env->module = &module_env; 1221 env->module = &module_env;
1318 1222
1319 byte f0 = module_env.AddSignature(sigs.i_v()); 1223 byte f0 = module_env.AddSignature(sigs.i_v());
1320 byte f1 = module_env.AddSignature(sigs.i_i()); 1224 byte f1 = module_env.AddSignature(sigs.i_i());
1321 byte f2 = module_env.AddSignature(sigs.i_ii()); 1225 byte f2 = module_env.AddSignature(sigs.i_ii());
1322 1226
1323 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); 1227 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
1324 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22))); 1228 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22)));
1325 EXPECT_VERIFIES_INLINE( 1229 EXPECT_VERIFIES_INLINE(
1326 env, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); 1230 env, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
1327 } 1231 }
1328 1232
1329 1233 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) {
1330 TEST_F(WasmDecoderTest, IndirectCallsOutOfBounds) {
1331 FunctionEnv* env = &env_i_i; 1234 FunctionEnv* env = &env_i_i;
1332 TestModuleEnv module_env; 1235 TestModuleEnv module_env;
1333 env->module = &module_env; 1236 env->module = &module_env;
1334 1237
1335 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1238 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1336 module_env.AddSignature(sigs.i_v()); 1239 module_env.AddSignature(sigs.i_v());
1337 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1240 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1338 1241
1339 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22))); 1242 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22)));
1340 module_env.AddSignature(sigs.i_i()); 1243 module_env.AddSignature(sigs.i_i());
1341 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27))); 1244 EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27)));
1342 1245
1343 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27))); 1246 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27)));
1344 } 1247 }
1345 1248
1346 1249 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) {
1347 TEST_F(WasmDecoderTest, IndirectCallsWithMismatchedSigs3) {
1348 FunctionEnv* env = &env_i_i; 1250 FunctionEnv* env = &env_i_i;
1349 TestModuleEnv module_env; 1251 TestModuleEnv module_env;
1350 env->module = &module_env; 1252 env->module = &module_env;
1351 1253
1352 byte f0 = module_env.AddFunction(sigs.i_f()); 1254 byte f0 = module_env.AddFunction(sigs.i_f());
1353 1255
1354 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17))); 1256 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17)));
1355 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64(27))); 1257 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64(27)));
1356 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2))); 1258 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2)));
1357 1259
1358 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); 1260 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
1359 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27))); 1261 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27)));
1360 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); 1262 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
1361 1263
1362 byte f1 = module_env.AddFunction(sigs.i_d()); 1264 byte f1 = module_env.AddFunction(sigs.i_d());
1363 1265
1364 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16))); 1266 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16)));
1365 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16))); 1267 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16)));
1366 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6))); 1268 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6)));
1367 } 1269 }
1368 1270
1369 TEST_F(WasmDecoderTest, SimpleImportCalls) { 1271 TEST_F(AstDecoderTest, SimpleImportCalls) {
1370 FunctionEnv* env = &env_i_i; 1272 FunctionEnv* env = &env_i_i;
1371 TestModuleEnv module_env; 1273 TestModuleEnv module_env;
1372 env->module = &module_env; 1274 env->module = &module_env;
1373 1275
1374 byte f0 = module_env.AddImport(sigs.i_v()); 1276 byte f0 = module_env.AddImport(sigs.i_v());
1375 byte f1 = module_env.AddImport(sigs.i_i()); 1277 byte f1 = module_env.AddImport(sigs.i_i());
1376 byte f2 = module_env.AddImport(sigs.i_ii()); 1278 byte f2 = module_env.AddImport(sigs.i_ii());
1377 1279
1378 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT0(f0)); 1280 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT0(f0));
1379 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(22))); 1281 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(22)));
1380 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72))); 1282 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72)));
1381 } 1283 }
1382 1284
1383 TEST_F(WasmDecoderTest, ImportCallsWithMismatchedSigs3) { 1285 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) {
1384 FunctionEnv* env = &env_i_i; 1286 FunctionEnv* env = &env_i_i;
1385 TestModuleEnv module_env; 1287 TestModuleEnv module_env;
1386 env->module = &module_env; 1288 env->module = &module_env;
1387 1289
1388 byte f0 = module_env.AddImport(sigs.i_f()); 1290 byte f0 = module_env.AddImport(sigs.i_f());
1389 1291
1390 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f0)); 1292 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f0));
1391 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I8(17))); 1293 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I8(17)));
1392 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64(27))); 1294 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64(27)));
1393 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_F64(37.2))); 1295 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_F64(37.2)));
1394 1296
1395 byte f1 = module_env.AddImport(sigs.i_d()); 1297 byte f1 = module_env.AddImport(sigs.i_d());
1396 1298
1397 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f1)); 1299 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f1));
1398 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(16))); 1300 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(16)));
1399 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64(16))); 1301 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64(16)));
1400 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_F32(17.6))); 1302 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_F32(17.6)));
1401 } 1303 }
1402 1304
1403 TEST_F(WasmDecoderTest, Int32Globals) { 1305 TEST_F(AstDecoderTest, Int32Globals) {
1404 FunctionEnv* env = &env_i_i; 1306 FunctionEnv* env = &env_i_i;
1405 TestModuleEnv module_env; 1307 TestModuleEnv module_env;
1406 env->module = &module_env; 1308 env->module = &module_env;
1407 1309
1408 module_env.AddGlobal(MachineType::Int8()); 1310 module_env.AddGlobal(MachineType::Int8());
1409 module_env.AddGlobal(MachineType::Uint8()); 1311 module_env.AddGlobal(MachineType::Uint8());
1410 module_env.AddGlobal(MachineType::Int16()); 1312 module_env.AddGlobal(MachineType::Int16());
1411 module_env.AddGlobal(MachineType::Uint16()); 1313 module_env.AddGlobal(MachineType::Uint16());
1412 module_env.AddGlobal(MachineType::Int32()); 1314 module_env.AddGlobal(MachineType::Int32());
1413 module_env.AddGlobal(MachineType::Uint32()); 1315 module_env.AddGlobal(MachineType::Uint32());
1414 1316
1415 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0)); 1317 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
1416 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1)); 1318 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1));
1417 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(2)); 1319 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(2));
1418 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(3)); 1320 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(3));
1419 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(4)); 1321 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(4));
1420 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(5)); 1322 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(5));
1421 1323
1422 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1324 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1423 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); 1325 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
1424 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); 1326 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
1425 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); 1327 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
1426 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0))); 1328 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0)));
1427 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0))); 1329 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0)));
1428 } 1330 }
1429 1331
1430 1332 TEST_F(AstDecoderTest, Int32Globals_fail) {
1431 TEST_F(WasmDecoderTest, Int32Globals_fail) {
1432 FunctionEnv* env = &env_i_i; 1333 FunctionEnv* env = &env_i_i;
1433 TestModuleEnv module_env; 1334 TestModuleEnv module_env;
1434 env->module = &module_env; 1335 env->module = &module_env;
1435 1336
1436 module_env.AddGlobal(MachineType::Int64()); 1337 module_env.AddGlobal(MachineType::Int64());
1437 module_env.AddGlobal(MachineType::Uint64()); 1338 module_env.AddGlobal(MachineType::Uint64());
1438 module_env.AddGlobal(MachineType::Float32()); 1339 module_env.AddGlobal(MachineType::Float32());
1439 module_env.AddGlobal(MachineType::Float64()); 1340 module_env.AddGlobal(MachineType::Float64());
1440 1341
1441 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(0)); 1342 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(0));
1442 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(1)); 1343 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(1));
1443 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(2)); 1344 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(2));
1444 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(3)); 1345 EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(3));
1445 1346
1446 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1347 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1447 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); 1348 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
1448 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); 1349 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
1449 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); 1350 EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
1450 } 1351 }
1451 1352
1452 1353 TEST_F(AstDecoderTest, Int64Globals) {
1453 TEST_F(WasmDecoderTest, Int64Globals) {
1454 FunctionEnv* env = &env_l_l; 1354 FunctionEnv* env = &env_l_l;
1455 TestModuleEnv module_env; 1355 TestModuleEnv module_env;
1456 env->module = &module_env; 1356 env->module = &module_env;
1457 1357
1458 module_env.AddGlobal(MachineType::Int64()); 1358 module_env.AddGlobal(MachineType::Int64());
1459 module_env.AddGlobal(MachineType::Uint64()); 1359 module_env.AddGlobal(MachineType::Uint64());
1460 1360
1461 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0)); 1361 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
1462 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1)); 1362 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1));
1463 1363
1464 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1364 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1465 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); 1365 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
1466 } 1366 }
1467 1367
1468 1368 TEST_F(AstDecoderTest, Float32Globals) {
1469 TEST_F(WasmDecoderTest, Float32Globals) {
1470 FunctionEnv env_f_ff; 1369 FunctionEnv env_f_ff;
1471 FunctionEnv* env = &env_f_ff; 1370 FunctionEnv* env = &env_f_ff;
1472 init_env(env, sigs.f_ff()); 1371 init_env(env, sigs.f_ff());
1473 TestModuleEnv module_env; 1372 TestModuleEnv module_env;
1474 env->module = &module_env; 1373 env->module = &module_env;
1475 1374
1476 module_env.AddGlobal(MachineType::Float32()); 1375 module_env.AddGlobal(MachineType::Float32());
1477 1376
1478 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0)); 1377 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
1479 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1378 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1480 } 1379 }
1481 1380
1482 1381 TEST_F(AstDecoderTest, Float64Globals) {
1483 TEST_F(WasmDecoderTest, Float64Globals) {
1484 FunctionEnv env_d_dd; 1382 FunctionEnv env_d_dd;
1485 FunctionEnv* env = &env_d_dd; 1383 FunctionEnv* env = &env_d_dd;
1486 init_env(env, sigs.d_dd()); 1384 init_env(env, sigs.d_dd());
1487 TestModuleEnv module_env; 1385 TestModuleEnv module_env;
1488 env->module = &module_env; 1386 env->module = &module_env;
1489 1387
1490 module_env.AddGlobal(MachineType::Float64()); 1388 module_env.AddGlobal(MachineType::Float64());
1491 1389
1492 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0)); 1390 EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
1493 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1391 EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1494 } 1392 }
1495 1393
1496 1394 TEST_F(AstDecoderTest, AllLoadGlobalCombinations) {
1497 TEST_F(WasmDecoderTest, AllLoadGlobalCombinations) {
1498 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1395 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1499 LocalType local_type = kLocalTypes[i]; 1396 LocalType local_type = kLocalTypes[i];
1500 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1397 for (size_t j = 0; j < arraysize(machineTypes); j++) {
1501 MachineType mem_type = machineTypes[j]; 1398 MachineType mem_type = machineTypes[j];
1502 FunctionEnv env; 1399 FunctionEnv env;
1503 FunctionSig sig(1, 0, &local_type); 1400 FunctionSig sig(1, 0, &local_type);
1504 TestModuleEnv module_env; 1401 TestModuleEnv module_env;
1505 init_env(&env, &sig); 1402 init_env(&env, &sig);
1506 env.module = &module_env; 1403 env.module = &module_env;
1507 module_env.AddGlobal(mem_type); 1404 module_env.AddGlobal(mem_type);
1508 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1405 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
1509 EXPECT_VERIFIES_INLINE(&env, WASM_LOAD_GLOBAL(0)); 1406 EXPECT_VERIFIES_INLINE(&env, WASM_LOAD_GLOBAL(0));
1510 } else { 1407 } else {
1511 EXPECT_FAILURE_INLINE(&env, WASM_LOAD_GLOBAL(0)); 1408 EXPECT_FAILURE_INLINE(&env, WASM_LOAD_GLOBAL(0));
1512 } 1409 }
1513 } 1410 }
1514 } 1411 }
1515 } 1412 }
1516 1413
1517 1414 TEST_F(AstDecoderTest, AllStoreGlobalCombinations) {
1518 TEST_F(WasmDecoderTest, AllStoreGlobalCombinations) {
1519 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1415 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1520 LocalType local_type = kLocalTypes[i]; 1416 LocalType local_type = kLocalTypes[i];
1521 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1417 for (size_t j = 0; j < arraysize(machineTypes); j++) {
1522 MachineType mem_type = machineTypes[j]; 1418 MachineType mem_type = machineTypes[j];
1523 FunctionEnv env; 1419 FunctionEnv env;
1524 FunctionSig sig(0, 1, &local_type); 1420 FunctionSig sig(0, 1, &local_type);
1525 TestModuleEnv module_env; 1421 TestModuleEnv module_env;
1526 init_env(&env, &sig); 1422 init_env(&env, &sig);
1527 env.module = &module_env; 1423 env.module = &module_env;
1528 module_env.AddGlobal(mem_type); 1424 module_env.AddGlobal(mem_type);
1529 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1425 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
1530 EXPECT_VERIFIES_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1426 EXPECT_VERIFIES_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1531 } else { 1427 } else {
1532 EXPECT_FAILURE_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1428 EXPECT_FAILURE_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1533 } 1429 }
1534 } 1430 }
1535 } 1431 }
1536 } 1432 }
1537 1433
1538 1434 TEST_F(AstDecoderTest, BreakNesting1) {
1539 TEST_F(WasmDecoderTest, BreakNesting1) {
1540 for (int i = 0; i < 5; i++) { 1435 for (int i = 0; i < 5; i++) {
1541 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) 1436 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
1542 byte code[] = {WASM_BLOCK( 1437 byte code[] = {WASM_BLOCK(
1543 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i, WASM_ZERO)), 1438 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i, WASM_ZERO)),
1544 WASM_SET_LOCAL(0, WASM_I8(1))), 1439 WASM_SET_LOCAL(0, WASM_I8(1))),
1545 WASM_GET_LOCAL(0))}; 1440 WASM_GET_LOCAL(0))};
1546 if (i < 3) { 1441 if (i < 3) {
1547 EXPECT_VERIFIES(&env_i_i, code); 1442 EXPECT_VERIFIES(&env_i_i, code);
1548 } else { 1443 } else {
1549 EXPECT_FAILURE(&env_i_i, code); 1444 EXPECT_FAILURE(&env_i_i, code);
1550 } 1445 }
1551 } 1446 }
1552 } 1447 }
1553 1448
1554 1449 TEST_F(AstDecoderTest, BreakNesting2) {
1555 TEST_F(WasmDecoderTest, BreakNesting2) {
1556 env_v_v.AddLocals(kAstI32, 1); 1450 env_v_v.AddLocals(kAstI32, 1);
1557 for (int i = 0; i < 5; i++) { 1451 for (int i = 0; i < 5; i++) {
1558 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) (return p)) (11) 1452 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) (return p)) (11)
1559 byte code[] = { 1453 byte code[] = {
1560 WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)), 1454 WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)),
1561 WASM_SET_LOCAL(0, WASM_I8(1)))), 1455 WASM_SET_LOCAL(0, WASM_I8(1)))),
1562 WASM_I8(11)}; 1456 WASM_I8(11)};
1563 if (i < 2) { 1457 if (i < 2) {
1564 EXPECT_VERIFIES(&env_v_v, code); 1458 EXPECT_VERIFIES(&env_v_v, code);
1565 } else { 1459 } else {
1566 EXPECT_FAILURE(&env_v_v, code); 1460 EXPECT_FAILURE(&env_v_v, code);
1567 } 1461 }
1568 } 1462 }
1569 } 1463 }
1570 1464
1571 1465 TEST_F(AstDecoderTest, BreakNesting3) {
1572 TEST_F(WasmDecoderTest, BreakNesting3) {
1573 env_v_v.AddLocals(kAstI32, 1); 1466 env_v_v.AddLocals(kAstI32, 1);
1574 for (int i = 0; i < 5; i++) { 1467 for (int i = 0; i < 5; i++) {
1575 // (block[1] (loop[1] (block[1] (if (get p) break[N]) 1468 // (block[1] (loop[1] (block[1] (if (get p) break[N])
1576 byte code[] = {WASM_BLOCK( 1469 byte code[] = {WASM_BLOCK(
1577 1, WASM_LOOP( 1470 1, WASM_LOOP(
1578 1, WASM_BLOCK(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)))))}; 1471 1, WASM_BLOCK(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)))))};
1579 if (i < 3) { 1472 if (i < 3) {
1580 EXPECT_VERIFIES(&env_v_v, code); 1473 EXPECT_VERIFIES(&env_v_v, code);
1581 } else { 1474 } else {
1582 EXPECT_FAILURE(&env_v_v, code); 1475 EXPECT_FAILURE(&env_v_v, code);
1583 } 1476 }
1584 } 1477 }
1585 } 1478 }
1586 1479
1587 1480 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) {
1588 TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) {
1589 EXPECT_FAILURE_INLINE( 1481 EXPECT_FAILURE_INLINE(
1590 &env_i_i, WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); 1482 &env_i_i, WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
1591 1483
1592 EXPECT_FAILURE_INLINE(&env_i_i, 1484 EXPECT_FAILURE_INLINE(&env_i_i,
1593 WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), 1485 WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)),
1594 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1486 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1595 EXPECT_FAILURE_INLINE(&env_i_i, 1487 EXPECT_FAILURE_INLINE(&env_i_i,
1596 WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)), 1488 WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)),
1597 WASM_BRV_IF_ZERO(0, WASM_I8(0)), 1489 WASM_BRV_IF_ZERO(0, WASM_I8(0)),
1598 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1490 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1599 EXPECT_FAILURE_INLINE(&env_i_i, WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)), 1491 EXPECT_FAILURE_INLINE(&env_i_i, WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)),
1600 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), 1492 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
1601 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); 1493 WASM_BRV_IF_ZERO(0, WASM_I8(11))));
1602 } 1494 }
1603 1495
1604 1496 TEST_F(AstDecoderTest, BreakNesting_6_levels) {
1605 TEST_F(WasmDecoderTest, BreakNesting_6_levels) {
1606 for (int mask = 0; mask < 64; mask++) { 1497 for (int mask = 0; mask < 64; mask++) {
1607 for (int i = 0; i < 14; i++) { 1498 for (int i = 0; i < 14; i++) {
1608 byte code[] = { 1499 byte code[] = {
1609 kExprBlock, 1, // -- 1500 kExprBlock, 1, // --
1610 kExprBlock, 1, // -- 1501 kExprBlock, 1, // --
1611 kExprBlock, 1, // -- 1502 kExprBlock, 1, // --
1612 kExprBlock, 1, // -- 1503 kExprBlock, 1, // --
1613 kExprBlock, 1, // -- 1504 kExprBlock, 1, // --
1614 kExprBlock, 1, // -- 1505 kExprBlock, 1, // --
1615 kExprBr, static_cast<byte>(i), 1506 kExprBr, static_cast<byte>(i),
(...skipping 10 matching lines...) Expand all
1626 1517
1627 if (i < depth) { 1518 if (i < depth) {
1628 EXPECT_VERIFIES(&env_v_v, code); 1519 EXPECT_VERIFIES(&env_v_v, code);
1629 } else { 1520 } else {
1630 EXPECT_FAILURE(&env_v_v, code); 1521 EXPECT_FAILURE(&env_v_v, code);
1631 } 1522 }
1632 } 1523 }
1633 } 1524 }
1634 } 1525 }
1635 1526
1636 1527 TEST_F(AstDecoderTest, ExprBreak_TypeCheck) {
1637 TEST_F(WasmDecoderTest, ExprBreak_TypeCheck) {
1638 FunctionEnv* envs[] = {&env_i_i, &env_l_l, &env_f_ff, &env_d_dd}; 1528 FunctionEnv* envs[] = {&env_i_i, &env_l_l, &env_f_ff, &env_d_dd};
1639 for (size_t i = 0; i < arraysize(envs); i++) { 1529 for (size_t i = 0; i < arraysize(envs); i++) {
1640 FunctionEnv* env = envs[i]; 1530 FunctionEnv* env = envs[i];
1641 // unify X and X => OK 1531 // unify X and X => OK
1642 EXPECT_VERIFIES_INLINE( 1532 EXPECT_VERIFIES_INLINE(
1643 env, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1533 env, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1644 WASM_GET_LOCAL(0))); 1534 WASM_GET_LOCAL(0)));
1645 } 1535 }
1646 1536
1647 // unify i32 and f32 => fail 1537 // unify i32 and f32 => fail
1648 EXPECT_FAILURE_INLINE( 1538 EXPECT_FAILURE_INLINE(
1649 &env_i_i, 1539 &env_i_i,
1650 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); 1540 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2)));
1651 1541
1652 // unify f64 and f64 => OK 1542 // unify f64 and f64 => OK
1653 EXPECT_VERIFIES_INLINE( 1543 EXPECT_VERIFIES_INLINE(
1654 &env_d_dd, 1544 &env_d_dd,
1655 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1545 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1656 WASM_F64(1.2))); 1546 WASM_F64(1.2)));
1657 } 1547 }
1658 1548
1659 1549 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) {
1660 TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) {
1661 byte code1[] = {WASM_BLOCK(2, 1550 byte code1[] = {WASM_BLOCK(2,
1662 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1551 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1663 WASM_GET_LOCAL(1))}; 1552 WASM_GET_LOCAL(1))};
1664 byte code2[] = { 1553 byte code2[] = {
1665 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), 1554 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))),
1666 WASM_GET_LOCAL(1))}; 1555 WASM_GET_LOCAL(1))};
1667 1556
1668 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1557 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1669 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1558 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1670 FunctionEnv env; 1559 FunctionEnv env;
1671 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; 1560 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]};
1672 FunctionSig sig(1, 2, storage); 1561 FunctionSig sig(1, 2, storage);
1673 init_env(&env, &sig); 1562 init_env(&env, &sig);
1674 1563
1675 if (i == j) { 1564 if (i == j) {
1676 EXPECT_VERIFIES(&env, code1); 1565 EXPECT_VERIFIES(&env, code1);
1677 EXPECT_VERIFIES(&env, code2); 1566 EXPECT_VERIFIES(&env, code2);
1678 } else { 1567 } else {
1679 EXPECT_FAILURE(&env, code1); 1568 EXPECT_FAILURE(&env, code1);
1680 EXPECT_FAILURE(&env, code2); 1569 EXPECT_FAILURE(&env, code2);
1681 } 1570 }
1682 } 1571 }
1683 } 1572 }
1684 } 1573 }
1685 1574
1686 1575 TEST_F(AstDecoderTest, ExprBr_Unify) {
1687 TEST_F(WasmDecoderTest, ExprBr_Unify) {
1688 FunctionEnv env; 1576 FunctionEnv env;
1689 1577
1690 for (int which = 0; which < 2; which++) { 1578 for (int which = 0; which < 2; which++) {
1691 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1579 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1692 LocalType type = kLocalTypes[i]; 1580 LocalType type = kLocalTypes[i];
1693 LocalType storage[] = {kAstI32, kAstI32, type}; 1581 LocalType storage[] = {kAstI32, kAstI32, type};
1694 FunctionSig sig(1, 2, storage); 1582 FunctionSig sig(1, 2, storage);
1695 init_env(&env, &sig); // (i32, X) -> i32 1583 init_env(&env, &sig); // (i32, X) -> i32
1696 1584
1697 byte code1[] = { 1585 byte code1[] = {
1698 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(which))), 1586 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(which))),
1699 WASM_GET_LOCAL(which ^ 1))}; 1587 WASM_GET_LOCAL(which ^ 1))};
1700 byte code2[] = { 1588 byte code2[] = {
1701 WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), 1589 WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))),
1702 WASM_GET_LOCAL(which ^ 1))}; 1590 WASM_GET_LOCAL(which ^ 1))};
1703 1591
1704 1592
1705 if (type == kAstI32) { 1593 if (type == kAstI32) {
1706 EXPECT_VERIFIES(&env, code1); 1594 EXPECT_VERIFIES(&env, code1);
1707 EXPECT_VERIFIES(&env, code2); 1595 EXPECT_VERIFIES(&env, code2);
1708 } else { 1596 } else {
1709 EXPECT_FAILURE(&env, code1); 1597 EXPECT_FAILURE(&env, code1);
1710 EXPECT_FAILURE(&env, code2); 1598 EXPECT_FAILURE(&env, code2);
1711 } 1599 }
1712 } 1600 }
1713 } 1601 }
1714 } 1602 }
1715 1603
1716 TEST_F(WasmDecoderTest, ExprBrIf_cond_type) { 1604 TEST_F(AstDecoderTest, ExprBrIf_cond_type) {
1717 FunctionEnv env; 1605 FunctionEnv env;
1718 byte code[] = { 1606 byte code[] = {
1719 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; 1607 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
1720 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1608 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1721 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1609 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1722 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; 1610 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]};
1723 FunctionSig sig(0, 2, types); 1611 FunctionSig sig(0, 2, types);
1724 init_env(&env, &sig); 1612 init_env(&env, &sig);
1725 1613
1726 if (types[1] == kAstI32) { 1614 if (types[1] == kAstI32) {
1727 EXPECT_VERIFIES(&env, code); 1615 EXPECT_VERIFIES(&env, code);
1728 } else { 1616 } else {
1729 EXPECT_FAILURE(&env, code); 1617 EXPECT_FAILURE(&env, code);
1730 } 1618 }
1731 } 1619 }
1732 } 1620 }
1733 } 1621 }
1734 1622
1735 TEST_F(WasmDecoderTest, ExprBrIf_val_type) { 1623 TEST_F(AstDecoderTest, ExprBrIf_val_type) {
1736 FunctionEnv env; 1624 FunctionEnv env;
1737 byte code[] = { 1625 byte code[] = {
1738 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), 1626 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)),
1739 WASM_GET_LOCAL(0))}; 1627 WASM_GET_LOCAL(0))};
1740 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1628 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1741 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1629 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1742 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], 1630 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j],
1743 kAstI32}; 1631 kAstI32};
1744 FunctionSig sig(1, 3, types); 1632 FunctionSig sig(1, 3, types);
1745 init_env(&env, &sig); 1633 init_env(&env, &sig);
1746 1634
1747 if (i == j) { 1635 if (i == j) {
1748 EXPECT_VERIFIES(&env, code); 1636 EXPECT_VERIFIES(&env, code);
1749 } else { 1637 } else {
1750 EXPECT_FAILURE(&env, code); 1638 EXPECT_FAILURE(&env, code);
1751 } 1639 }
1752 } 1640 }
1753 } 1641 }
1754 } 1642 }
1755 1643
1756 1644 TEST_F(AstDecoderTest, ExprBrIf_Unify) {
1757 TEST_F(WasmDecoderTest, ExprBrIf_Unify) {
1758 FunctionEnv env; 1645 FunctionEnv env;
1759 1646
1760 for (int which = 0; which < 2; which++) { 1647 for (int which = 0; which < 2; which++) {
1761 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1648 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1762 LocalType type = kLocalTypes[i]; 1649 LocalType type = kLocalTypes[i];
1763 LocalType storage[] = {kAstI32, kAstI32, type}; 1650 LocalType storage[] = {kAstI32, kAstI32, type};
1764 FunctionSig sig(1, 2, storage); 1651 FunctionSig sig(1, 2, storage);
1765 init_env(&env, &sig); // (i32, X) -> i32 1652 init_env(&env, &sig); // (i32, X) -> i32
1766 1653
1767 byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), 1654 byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
1768 WASM_GET_LOCAL(which ^ 1))}; 1655 WASM_GET_LOCAL(which ^ 1))};
1769 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), 1656 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)),
1770 WASM_GET_LOCAL(which ^ 1))}; 1657 WASM_GET_LOCAL(which ^ 1))};
1771 1658
1772 if (type == kAstI32) { 1659 if (type == kAstI32) {
1773 EXPECT_VERIFIES(&env, code1); 1660 EXPECT_VERIFIES(&env, code1);
1774 EXPECT_VERIFIES(&env, code2); 1661 EXPECT_VERIFIES(&env, code2);
1775 } else { 1662 } else {
1776 EXPECT_FAILURE(&env, code1); 1663 EXPECT_FAILURE(&env, code1);
1777 EXPECT_FAILURE(&env, code2); 1664 EXPECT_FAILURE(&env, code2);
1778 } 1665 }
1779 } 1666 }
1780 } 1667 }
1781 } 1668 }
1782 1669
1783 1670 TEST_F(AstDecoderTest, TableSwitch0) {
1784 TEST_F(WasmDecoderTest, TableSwitch0) {
1785 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0}; 1671 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0};
1786 EXPECT_FAILURE(&env_v_v, code); 1672 EXPECT_FAILURE(&env_v_v, code);
1787 } 1673 }
1788 1674
1789 1675 TEST_F(AstDecoderTest, TableSwitch0b) {
1790 TEST_F(WasmDecoderTest, TableSwitch0b) {
1791 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0, kExprI8Const, 11}; 1676 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0, kExprI8Const, 11};
1792 EXPECT_FAILURE(&env_v_v, code); 1677 EXPECT_FAILURE(&env_v_v, code);
1793 EXPECT_FAILURE(&env_i_i, code); 1678 EXPECT_FAILURE(&env_i_i, code);
1794 } 1679 }
1795 1680
1796 1681 TEST_F(AstDecoderTest, TableSwitch0c) {
1797 TEST_F(WasmDecoderTest, TableSwitch0c) {
1798 static byte code[] = { 1682 static byte code[] = {
1799 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)), WASM_I8(67))}; 1683 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)), WASM_I8(67))};
1800 EXPECT_VERIFIES(&env_v_v, code); 1684 EXPECT_VERIFIES(&env_v_v, code);
1801 } 1685 }
1802 1686
1803 TEST_F(WasmDecoderTest, TableSwitch0d) { 1687 TEST_F(AstDecoderTest, TableSwitch0d) {
1804 static byte code[] = { 1688 static byte code[] = {
1805 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(1)), 1689 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(1)),
1806 WASM_I8(67))}; 1690 WASM_I8(67))};
1807 EXPECT_VERIFIES(&env_v_v, code); 1691 EXPECT_VERIFIES(&env_v_v, code);
1808 } 1692 }
1809 1693
1810 TEST_F(WasmDecoderTest, TableSwitch1) { 1694 TEST_F(AstDecoderTest, TableSwitch1) {
1811 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1695 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1812 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))}; 1696 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))};
1813 EXPECT_VERIFIES(&env_i_i, code); 1697 EXPECT_VERIFIES(&env_i_i, code);
1814 EXPECT_VERIFIES(&env_v_v, code); 1698 EXPECT_VERIFIES(&env_v_v, code);
1815 EXPECT_FAILURE(&env_f_ff, code); 1699 EXPECT_FAILURE(&env_f_ff, code);
1816 EXPECT_FAILURE(&env_d_dd, code); 1700 EXPECT_FAILURE(&env_d_dd, code);
1817 } 1701 }
1818 1702
1819 1703 TEST_F(AstDecoderTest, TableSwitch_off_end) {
1820 TEST_F(WasmDecoderTest, TableSwitch_off_end) {
1821 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1704 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1822 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))}; 1705 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))};
1823 for (size_t len = arraysize(code) - 1; len > 0; len--) { 1706 for (size_t len = arraysize(code) - 1; len > 0; len--) {
1824 Verify(kError, &env_v_v, code, code + len); 1707 Verify(kError, &env_v_v, code, code + len);
1825 } 1708 }
1826 } 1709 }
1827 1710
1828 1711 TEST_F(AstDecoderTest, TableSwitch2) {
1829 TEST_F(WasmDecoderTest, TableSwitch2) {
1830 static byte code[] = { 1712 static byte code[] = {
1831 WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1713 WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1832 WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))}; 1714 WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))};
1833 EXPECT_VERIFIES(&env_i_i, code); 1715 EXPECT_VERIFIES(&env_i_i, code);
1834 EXPECT_VERIFIES(&env_v_v, code); 1716 EXPECT_VERIFIES(&env_v_v, code);
1835 EXPECT_FAILURE(&env_f_ff, code); 1717 EXPECT_FAILURE(&env_f_ff, code);
1836 EXPECT_FAILURE(&env_d_dd, code); 1718 EXPECT_FAILURE(&env_d_dd, code);
1837 } 1719 }
1838 1720
1839 1721 TEST_F(AstDecoderTest, TableSwitch1b) {
1840 TEST_F(WasmDecoderTest, TableSwitch1b) {
1841 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1722 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1842 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO)); 1723 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1843 1724
1844 EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1725 EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1845 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0))); 1726 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0)));
1846 1727
1847 EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1728 EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1848 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0))); 1729 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0)));
1849 } 1730 }
1850 1731
1851 TEST_F(WasmDecoderTest, TableSwitch_br1) { 1732 TEST_F(AstDecoderTest, TableSwitch_br1) {
1852 for (int depth = 0; depth < 2; depth++) { 1733 for (int depth = 0; depth < 2; depth++) {
1853 byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)), 1734 byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
1854 WASM_GET_LOCAL(0))}; 1735 WASM_GET_LOCAL(0))};
1855 EXPECT_VERIFIES(&env_v_i, code); 1736 EXPECT_VERIFIES(&env_v_i, code);
1856 EXPECT_FAILURE(&env_i_i, code); 1737 EXPECT_FAILURE(&env_i_i, code);
1857 } 1738 }
1858 } 1739 }
1859 1740
1860 1741 TEST_F(AstDecoderTest, TableSwitch_invalid_br) {
1861 TEST_F(WasmDecoderTest, TableSwitch_invalid_br) {
1862 for (int depth = 1; depth < 4; depth++) { 1742 for (int depth = 1; depth < 4; depth++) {
1863 EXPECT_FAILURE_INLINE(&env_v_i, 1743 EXPECT_FAILURE_INLINE(&env_v_i,
1864 WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)), 1744 WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
1865 WASM_GET_LOCAL(0)); 1745 WASM_GET_LOCAL(0));
1866 EXPECT_FAILURE_INLINE( 1746 EXPECT_FAILURE_INLINE(
1867 &env_v_i, 1747 &env_v_i,
1868 WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(depth), WASM_CASE_BR(depth)), 1748 WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(depth), WASM_CASE_BR(depth)),
1869 WASM_GET_LOCAL(0)); 1749 WASM_GET_LOCAL(0));
1870 } 1750 }
1871 } 1751 }
1872 1752
1873 1753 TEST_F(AstDecoderTest, TableSwitch_invalid_case_ref) {
1874 TEST_F(WasmDecoderTest, TableSwitch_invalid_case_ref) {
1875 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)), 1754 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)),
1876 WASM_GET_LOCAL(0)); 1755 WASM_GET_LOCAL(0));
1877 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)), 1756 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)),
1878 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO)); 1757 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1879 } 1758 }
1880 1759
1881 1760 TEST_F(AstDecoderTest, TableSwitch1_br) {
1882 TEST_F(WasmDecoderTest, TableSwitch1_br) {
1883 EXPECT_VERIFIES_INLINE( 1761 EXPECT_VERIFIES_INLINE(
1884 &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1762 &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1885 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO))); 1763 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO)));
1886 } 1764 }
1887 1765
1888 1766 TEST_F(AstDecoderTest, TableSwitch2_br) {
1889 TEST_F(WasmDecoderTest, TableSwitch2_br) {
1890 EXPECT_VERIFIES_INLINE( 1767 EXPECT_VERIFIES_INLINE(
1891 &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1768 &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1892 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)), 1769 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)),
1893 WASM_BRV(0, WASM_I8(1)))); 1770 WASM_BRV(0, WASM_I8(1))));
1894 1771
1895 EXPECT_FAILURE_INLINE( 1772 EXPECT_FAILURE_INLINE(
1896 &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1773 &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1897 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)), 1774 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)),
1898 WASM_BRV(0, WASM_I8(4)))); 1775 WASM_BRV(0, WASM_I8(4))));
1899 } 1776 }
1900 1777
1901 1778 TEST_F(AstDecoderTest, TableSwitch2x2) {
1902 TEST_F(WasmDecoderTest, TableSwitch2x2) {
1903 EXPECT_VERIFIES_INLINE( 1779 EXPECT_VERIFIES_INLINE(
1904 &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1), 1780 &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1),
1905 WASM_CASE(0), WASM_CASE(1)), 1781 WASM_CASE(0), WASM_CASE(1)),
1906 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)), 1782 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)),
1907 WASM_BRV(0, WASM_I8(4)))); 1783 WASM_BRV(0, WASM_I8(4))));
1908 } 1784 }
1909 1785
1910 1786 TEST_F(AstDecoderTest, ExprBreakNesting1) {
1911 TEST_F(WasmDecoderTest, ExprBreakNesting1) {
1912 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO))); 1787 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO)));
1913 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0))); 1788 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0)));
1914 EXPECT_VERIFIES_INLINE(&env_v_v, 1789 EXPECT_VERIFIES_INLINE(&env_v_v,
1915 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1790 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1916 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO))); 1791 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
1917 1792
1918 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 1793 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
1919 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0))); 1794 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0)));
1920 EXPECT_VERIFIES_INLINE(&env_v_v, 1795 EXPECT_VERIFIES_INLINE(&env_v_v,
1921 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1796 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1922 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO))); 1797 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO)));
1923 1798
1924 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 1799 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
1925 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(1))); 1800 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(1)));
1926 } 1801 }
1927 1802
1928 1803 TEST_F(AstDecoderTest, Select) {
1929 TEST_F(WasmDecoderTest, Select) {
1930 EXPECT_VERIFIES_INLINE( 1804 EXPECT_VERIFIES_INLINE(
1931 &env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); 1805 &env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO));
1932 EXPECT_VERIFIES_INLINE(&env_f_ff, 1806 EXPECT_VERIFIES_INLINE(&env_f_ff,
1933 WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); 1807 WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO));
1934 EXPECT_VERIFIES_INLINE(&env_d_dd, 1808 EXPECT_VERIFIES_INLINE(&env_d_dd,
1935 WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); 1809 WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO));
1936 EXPECT_VERIFIES_INLINE(&env_l_l, 1810 EXPECT_VERIFIES_INLINE(&env_l_l,
1937 WASM_SELECT(WASM_I64(0), WASM_I64(0), WASM_ZERO)); 1811 WASM_SELECT(WASM_I64(0), WASM_I64(0), WASM_ZERO));
1938 } 1812 }
1939 1813
1940 TEST_F(WasmDecoderTest, Select_fail1) { 1814 TEST_F(AstDecoderTest, Select_fail1) {
1941 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), 1815 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0),
1942 WASM_GET_LOCAL(0))); 1816 WASM_GET_LOCAL(0)));
1943 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), 1817 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0),
1944 WASM_GET_LOCAL(0))); 1818 WASM_GET_LOCAL(0)));
1945 EXPECT_FAILURE_INLINE( 1819 EXPECT_FAILURE_INLINE(
1946 &env_i_i, 1820 &env_i_i,
1947 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); 1821 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0)));
1948 } 1822 }
1949 1823
1950 TEST_F(WasmDecoderTest, Select_fail2) { 1824 TEST_F(AstDecoderTest, Select_fail2) {
1951 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1825 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1952 LocalType type = kLocalTypes[i]; 1826 LocalType type = kLocalTypes[i];
1953 if (type == kAstI32) continue; 1827 if (type == kAstI32) continue;
1954 1828
1955 LocalType types[] = {type, kAstI32, type}; 1829 LocalType types[] = {type, kAstI32, type};
1956 FunctionSig sig(1, 2, types); 1830 FunctionSig sig(1, 2, types);
1957 FunctionEnv env; 1831 FunctionEnv env;
1958 init_env(&env, &sig); 1832 init_env(&env, &sig);
1959 1833
1960 EXPECT_VERIFIES_INLINE( 1834 EXPECT_VERIFIES_INLINE(
1961 &env, 1835 &env,
1962 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); 1836 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)));
1963 1837
1964 EXPECT_FAILURE_INLINE( 1838 EXPECT_FAILURE_INLINE(
1965 &env, 1839 &env,
1966 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 1840 WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
1967 1841
1968 EXPECT_FAILURE_INLINE( 1842 EXPECT_FAILURE_INLINE(
1969 &env, 1843 &env,
1970 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); 1844 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)));
1971 1845
1972 EXPECT_FAILURE_INLINE( 1846 EXPECT_FAILURE_INLINE(
1973 &env, 1847 &env,
1974 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 1848 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
1975 } 1849 }
1976 } 1850 }
1977 1851
1978 1852 TEST_F(AstDecoderTest, Select_TypeCheck) {
1979 TEST_F(WasmDecoderTest, Select_TypeCheck) {
1980 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), 1853 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0),
1981 WASM_GET_LOCAL(0))); 1854 WASM_GET_LOCAL(0)));
1982 1855
1983 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), 1856 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25),
1984 WASM_GET_LOCAL(0))); 1857 WASM_GET_LOCAL(0)));
1985 1858
1986 EXPECT_FAILURE_INLINE( 1859 EXPECT_FAILURE_INLINE(
1987 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0))); 1860 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0)));
1988 } 1861 }
1989 1862
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 EXPECT_ARITY(2, kExprIf); 2107 EXPECT_ARITY(2, kExprIf);
2235 EXPECT_ARITY(3, kExprIfElse); 2108 EXPECT_ARITY(3, kExprIfElse);
2236 EXPECT_ARITY(3, kExprSelect); 2109 EXPECT_ARITY(3, kExprSelect);
2237 2110
2238 EXPECT_ARITY(1, kExprBr); 2111 EXPECT_ARITY(1, kExprBr);
2239 EXPECT_ARITY(2, kExprBrIf); 2112 EXPECT_ARITY(2, kExprBrIf);
2240 2113
2241 { 2114 {
2242 TestSignatures sigs; 2115 TestSignatures sigs;
2243 FunctionEnv env; 2116 FunctionEnv env;
2244 WasmDecoderTest::init_env(&env, sigs.v_v()); 2117 AstDecoderTest::init_env(&env, sigs.v_v());
2245 EXPECT_ARITY(0, kExprReturn); 2118 EXPECT_ARITY(0, kExprReturn);
2246 WasmDecoderTest::init_env(&env, sigs.i_i()); 2119 AstDecoderTest::init_env(&env, sigs.i_i());
2247 EXPECT_ARITY(1, kExprReturn); 2120 EXPECT_ARITY(1, kExprReturn);
2248 } 2121 }
2249 } 2122 }
2250 2123
2251 2124
2252 TEST_F(WasmOpcodeArityTest, Misc) { 2125 TEST_F(WasmOpcodeArityTest, Misc) {
2253 FunctionEnv env; 2126 FunctionEnv env;
2254 2127
2255 EXPECT_ARITY(0, kExprI8Const); 2128 EXPECT_ARITY(0, kExprI8Const);
2256 EXPECT_ARITY(0, kExprI32Const); 2129 EXPECT_ARITY(0, kExprI32Const);
(...skipping 14 matching lines...) Expand all
2271 module.AddFunction(sigs.i_i()); 2144 module.AddFunction(sigs.i_i());
2272 2145
2273 module.AddSignature(sigs.f_ff()); 2146 module.AddSignature(sigs.f_ff());
2274 module.AddSignature(sigs.i_d()); 2147 module.AddSignature(sigs.i_d());
2275 2148
2276 module.AddImport(sigs.f_ff()); 2149 module.AddImport(sigs.f_ff());
2277 module.AddImport(sigs.i_d()); 2150 module.AddImport(sigs.i_d());
2278 2151
2279 { 2152 {
2280 FunctionEnv env; 2153 FunctionEnv env;
2281 WasmDecoderTest::init_env(&env, sigs.i_ii()); 2154 AstDecoderTest::init_env(&env, sigs.i_ii());
2282 env.module = &module; 2155 env.module = &module;
2283 2156
2284 EXPECT_ARITY(2, kExprCallFunction, 0); 2157 EXPECT_ARITY(2, kExprCallFunction, 0);
2285 EXPECT_ARITY(2, kExprCallImport, 0); 2158 EXPECT_ARITY(2, kExprCallImport, 0);
2286 EXPECT_ARITY(3, kExprCallIndirect, 0); 2159 EXPECT_ARITY(3, kExprCallIndirect, 0);
2287 EXPECT_ARITY(1, kExprBr); 2160 EXPECT_ARITY(1, kExprBr);
2288 EXPECT_ARITY(2, kExprBrIf); 2161 EXPECT_ARITY(2, kExprBrIf);
2289 } 2162 }
2290 2163
2291 { 2164 {
2292 FunctionEnv env; 2165 FunctionEnv env;
2293 WasmDecoderTest::init_env(&env, sigs.v_v()); 2166 AstDecoderTest::init_env(&env, sigs.v_v());
2294 env.module = &module; 2167 env.module = &module;
2295 2168
2296 EXPECT_ARITY(1, kExprCallFunction, 1); 2169 EXPECT_ARITY(1, kExprCallFunction, 1);
2297 EXPECT_ARITY(1, kExprCallImport, 1); 2170 EXPECT_ARITY(1, kExprCallImport, 1);
2298 EXPECT_ARITY(2, kExprCallIndirect, 1); 2171 EXPECT_ARITY(2, kExprCallIndirect, 1);
2299 EXPECT_ARITY(1, kExprBr); 2172 EXPECT_ARITY(1, kExprBr);
2300 EXPECT_ARITY(2, kExprBrIf); 2173 EXPECT_ARITY(2, kExprBrIf);
2301 } 2174 }
2302 } 2175 }
2303 2176
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 EXPECT_ARITY(1, kExprF64SConvertI64); 2332 EXPECT_ARITY(1, kExprF64SConvertI64);
2460 EXPECT_ARITY(1, kExprF64UConvertI64); 2333 EXPECT_ARITY(1, kExprF64UConvertI64);
2461 EXPECT_ARITY(1, kExprF64ConvertF32); 2334 EXPECT_ARITY(1, kExprF64ConvertF32);
2462 EXPECT_ARITY(1, kExprF64ReinterpretI64); 2335 EXPECT_ARITY(1, kExprF64ReinterpretI64);
2463 EXPECT_ARITY(1, kExprI32ReinterpretF32); 2336 EXPECT_ARITY(1, kExprI32ReinterpretF32);
2464 EXPECT_ARITY(1, kExprI64ReinterpretF64); 2337 EXPECT_ARITY(1, kExprI64ReinterpretF64);
2465 } 2338 }
2466 } // namespace wasm 2339 } // namespace wasm
2467 } // namespace internal 2340 } // namespace internal
2468 } // namespace v8 2341 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/unittests.gyp ('k') | test/unittests/wasm/decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698