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

Side by Side Diff: test/unittests/interpreter/bytecode-array-iterator-unittest.cc

Issue 1291693004: [Interpreter] Bytecode graph builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments on patch set 8. Created 5 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/interpreter/bytecode-array-builder.h"
8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "test/unittests/test-utils.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace interpreter {
14
15 class BytecodeArrayIteratorTest : public TestWithIsolateAndZone {
16 public:
17 BytecodeArrayIteratorTest() {}
18 ~BytecodeArrayIteratorTest() override {}
19 };
20
21
22 TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
23 // Use a builder to create an array with key features
24 BytecodeArrayBuilder builder(isolate(), zone());
25 builder.set_parameter_count(3);
26 builder.set_locals_count(2);
27
28 Factory* factory = isolate()->factory();
29 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
30 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
31 Smi* zero = Smi::FromInt(0);
32 Smi* smi_0 = Smi::FromInt(64);
33 Smi* smi_1 = Smi::FromInt(-65536);
34 Register reg_0(0);
35 Register reg_1(1);
36 Register reg_2 = Register::FromParameterIndex(2, builder.parameter_count());
37 int feedback_slot = 97;
38
39 builder.LoadLiteral(heap_num_0)
40 .LoadLiteral(heap_num_1)
41 .LoadLiteral(zero)
42 .LoadLiteral(smi_0)
43 .LoadLiteral(smi_1)
44 .LoadAccumulatorWithRegister(reg_0)
45 .LoadNamedProperty(reg_1, feedback_slot, LanguageMode::SLOPPY)
46 .StoreAccumulatorInRegister(reg_2)
47 .Return();
48
49 // Test iterator sees the expected output from the builder.
50 BytecodeArrayIterator iterator(builder.ToBytecodeArray());
51 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
52 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
53 CHECK(iterator.More());
54 iterator.Next();
55
56 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
57 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
58 CHECK(iterator.More());
59 iterator.Next();
60
61 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
62 CHECK(iterator.More());
63 iterator.Next();
64
65 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi8);
66 CHECK_EQ(Smi::FromInt(iterator.GetSmi8Operand(0)), smi_0);
67 CHECK(iterator.More());
68 iterator.Next();
69
70 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
71 CHECK_EQ(*iterator.GetConstantForIndexOperand(0), smi_1);
72 CHECK(iterator.More());
73 iterator.Next();
74
75 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar);
76 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
77 CHECK(iterator.More());
78 iterator.Next();
79
80 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC);
81 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
82 CHECK_EQ(iterator.GetSmi8Operand(1), feedback_slot);
83 CHECK(iterator.More());
84 iterator.Next();
85
86 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar);
87 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_2.index());
88 CHECK(iterator.More());
89 iterator.Next();
90
91 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
92 CHECK(iterator.More());
93 iterator.Next();
94 CHECK(!iterator.More());
95 }
96
97 } // namespace interpreter
98 } // namespace internal
99 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698