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

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

Issue 2587143002: [wasm] Add iterators for opcodes or offsets of one function (Closed)
Patch Set: Created 4 years 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 | « src/wasm/wasm-objects.cc ('k') | no next file » | 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/common/wasm/test-signatures.h" 9 #include "test/common/wasm/test-signatures.h"
10 10
(...skipping 2651 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 } 2662 }
2663 2663
2664 class BytecodeIteratorTest : public TestWithZone {}; 2664 class BytecodeIteratorTest : public TestWithZone {};
2665 2665
2666 TEST_F(BytecodeIteratorTest, SimpleForeach) { 2666 TEST_F(BytecodeIteratorTest, SimpleForeach) {
2667 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; 2667 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
2668 BytecodeIterator iter(code, code + sizeof(code)); 2668 BytecodeIterator iter(code, code + sizeof(code));
2669 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, 2669 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const,
2670 kExprElse, kExprI8Const, kExprEnd}; 2670 kExprElse, kExprI8Const, kExprEnd};
2671 size_t pos = 0; 2671 size_t pos = 0;
2672 for (WasmOpcode opcode : iter) { 2672 for (WasmOpcode opcode : iter.opcodes()) {
2673 if (pos >= arraysize(expected)) { 2673 if (pos >= arraysize(expected)) {
2674 EXPECT_TRUE(false); 2674 EXPECT_TRUE(false);
2675 break; 2675 break;
2676 } 2676 }
2677 EXPECT_EQ(expected[pos++], opcode); 2677 EXPECT_EQ(expected[pos++], opcode);
2678 } 2678 }
2679 EXPECT_EQ(arraysize(expected), pos); 2679 EXPECT_EQ(arraysize(expected), pos);
2680 } 2680 }
2681 2681
2682 TEST_F(BytecodeIteratorTest, ForeachTwice) { 2682 TEST_F(BytecodeIteratorTest, ForeachTwice) {
2683 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; 2683 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
2684 BytecodeIterator iter(code, code + sizeof(code)); 2684 BytecodeIterator iter(code, code + sizeof(code));
2685 int count = 0; 2685 int count = 0;
2686 2686
2687 count = 0; 2687 count = 0;
2688 for (WasmOpcode opcode : iter) { 2688 for (WasmOpcode opcode : iter.opcodes()) {
2689 USE(opcode); 2689 USE(opcode);
2690 count++; 2690 count++;
2691 } 2691 }
2692 EXPECT_EQ(6, count); 2692 EXPECT_EQ(6, count);
2693 2693
2694 count = 0; 2694 count = 0;
2695 for (WasmOpcode opcode : iter) { 2695 for (WasmOpcode opcode : iter.opcodes()) {
2696 USE(opcode); 2696 USE(opcode);
2697 count++; 2697 count++;
2698 } 2698 }
2699 EXPECT_EQ(6, count); 2699 EXPECT_EQ(6, count);
2700 } 2700 }
2701 2701
2702 TEST_F(BytecodeIteratorTest, ForeachOffset) {
2703 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
2704 BytecodeIterator iter(code, code + sizeof(code));
2705 int count = 0;
2706
2707 count = 0;
2708 for (auto offset : iter.offsets()) {
2709 USE(offset);
2710 count++;
2711 }
2712 EXPECT_EQ(6, count);
2713
2714 count = 0;
2715 for (auto offset : iter.offsets()) {
2716 USE(offset);
2717 count++;
2718 }
2719 EXPECT_EQ(6, count);
2720 }
2721
2702 TEST_F(BytecodeIteratorTest, WithAstDecls) { 2722 TEST_F(BytecodeIteratorTest, WithAstDecls) {
2703 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; 2723 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)};
2704 AstLocalDecls decls(zone()); 2724 AstLocalDecls decls(zone());
2705 BytecodeIterator iter(code, code + sizeof(code), &decls); 2725 BytecodeIterator iter(code, code + sizeof(code), &decls);
2706 2726
2707 EXPECT_EQ(3u, decls.decls_encoded_size); 2727 EXPECT_EQ(3u, decls.decls_encoded_size);
2708 EXPECT_EQ(3u, iter.pc_offset()); 2728 EXPECT_EQ(3u, iter.pc_offset());
2709 EXPECT_TRUE(iter.has_next()); 2729 EXPECT_TRUE(iter.has_next());
2710 EXPECT_EQ(kExprI8Const, iter.current()); 2730 EXPECT_EQ(kExprI8Const, iter.current());
2711 iter.next(); 2731 iter.next();
2712 EXPECT_TRUE(iter.has_next()); 2732 EXPECT_TRUE(iter.has_next());
2713 EXPECT_EQ(kExprI8Const, iter.current()); 2733 EXPECT_EQ(kExprI8Const, iter.current());
2714 iter.next(); 2734 iter.next();
2715 EXPECT_FALSE(iter.has_next()); 2735 EXPECT_FALSE(iter.has_next());
2716 } 2736 }
2717 2737
2718 } // namespace wasm 2738 } // namespace wasm
2719 } // namespace internal 2739 } // namespace internal
2720 } // namespace v8 2740 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698