OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
10 | 10 |
(...skipping 2419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2430 EXPECT_TRUE(result); | 2430 EXPECT_TRUE(result); |
2431 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); | 2431 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); |
2432 | 2432 |
2433 LocalTypeMap map = Expand(decls); | 2433 LocalTypeMap map = Expand(decls); |
2434 size_t pos = 0; | 2434 size_t pos = 0; |
2435 pos = ExpectRun(map, pos, kAstF32, 5); | 2435 pos = ExpectRun(map, pos, kAstF32, 5); |
2436 pos = ExpectRun(map, pos, kAstI32, 1337); | 2436 pos = ExpectRun(map, pos, kAstI32, 1337); |
2437 pos = ExpectRun(map, pos, kAstI64, 212); | 2437 pos = ExpectRun(map, pos, kAstI64, 212); |
2438 } | 2438 } |
2439 | 2439 |
2440 class BytecodeIteratorTest : public TestWithZone {}; | |
2441 | |
2442 TEST_F(BytecodeIteratorTest, SimpleForeach) { | |
2443 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; | |
2444 BytecodeIterator iter(code, code + sizeof(code)); | |
2445 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, | |
2446 kExprElse, kExprI8Const, kExprEnd}; | |
2447 size_t pos = 0; | |
2448 for (WasmOpcode opcode : iter) { | |
2449 if (pos >= arraysize(expected)) { | |
2450 EXPECT_TRUE(false); | |
ahaas
2016/07/11 12:31:19
why don't you say
EXPECT_TRUE(pos < arraysize(exp
| |
2451 break; | |
2452 } | |
2453 EXPECT_EQ(expected[pos++], opcode); | |
2454 } | |
2455 EXPECT_EQ(arraysize(expected), pos); | |
2456 } | |
2457 | |
2458 TEST_F(BytecodeIteratorTest, ForeachTwice) { | |
2459 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; | |
2460 BytecodeIterator iter(code, code + sizeof(code)); | |
2461 int count = 0; | |
2462 | |
2463 count = 0; | |
2464 for (WasmOpcode opcode : iter) { | |
2465 USE(opcode); | |
2466 count++; | |
2467 } | |
2468 EXPECT_EQ(6, count); | |
2469 | |
2470 count = 0; | |
2471 for (WasmOpcode opcode : iter) { | |
2472 USE(opcode); | |
2473 count++; | |
2474 } | |
2475 EXPECT_EQ(6, count); | |
2476 } | |
2477 | |
2478 TEST_F(BytecodeIteratorTest, WithAstDecls) { | |
2479 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; | |
2480 AstLocalDecls decls(zone()); | |
2481 BytecodeIterator iter(code, code + sizeof(code), &decls); | |
2482 | |
2483 EXPECT_EQ(3, decls.decls_encoded_size); | |
2484 EXPECT_EQ(3, iter.pc_offset()); | |
2485 EXPECT_TRUE(iter.has_next()); | |
2486 EXPECT_EQ(kExprI8Const, iter.current()); | |
2487 iter.next(); | |
2488 EXPECT_TRUE(iter.has_next()); | |
2489 EXPECT_EQ(kExprI8Const, iter.current()); | |
2490 iter.next(); | |
2491 EXPECT_FALSE(iter.has_next()); | |
2492 } | |
2493 | |
2440 } // namespace wasm | 2494 } // namespace wasm |
2441 } // namespace internal | 2495 } // namespace internal |
2442 } // namespace v8 | 2496 } // namespace v8 |
OLD | NEW |