OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/interpreter/bytecode-pipeline.h" | 7 #include "src/interpreter/bytecode-pipeline.h" |
8 #include "src/interpreter/bytecode-register-allocator.h" | 8 #include "src/interpreter/bytecode-register-allocator.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 namespace interpreter { | 14 namespace interpreter { |
15 | 15 |
16 using BytecodeNodeTest = TestWithIsolateAndZone; | 16 using BytecodeNodeTest = TestWithIsolateAndZone; |
17 | 17 |
18 TEST(BytecodeSourceInfo, Operations) { | 18 TEST(BytecodeSourceInfo, Operations) { |
19 BytecodeSourceInfo x(0, true); | 19 BytecodeSourceInfo x(0, true); |
20 CHECK_EQ(x.source_position(), 0); | 20 CHECK_EQ(x.source_position(), 0); |
21 CHECK_EQ(x.is_statement(), true); | 21 CHECK_EQ(x.is_statement(), true); |
22 CHECK_EQ(x.is_valid(), true); | 22 CHECK_EQ(x.is_valid(), true); |
23 x.set_invalid(); | 23 x.set_invalid(); |
24 CHECK_EQ(x.is_statement(), false); | 24 CHECK_EQ(x.is_statement(), false); |
25 CHECK_EQ(x.is_valid(), false); | 25 CHECK_EQ(x.is_valid(), false); |
26 | 26 |
27 x.Update({1, true}); | 27 x.MakeStatementPosition(1); |
28 BytecodeSourceInfo y(1, true); | 28 BytecodeSourceInfo y(1, true); |
29 CHECK(x == y); | 29 CHECK(x == y); |
30 CHECK(!(x != y)); | 30 CHECK(!(x != y)); |
31 | 31 |
32 x.set_invalid(); | 32 x.set_invalid(); |
33 CHECK(!(x == y)); | 33 CHECK(!(x == y)); |
34 CHECK(x != y); | 34 CHECK(x != y); |
35 | 35 |
36 y.Update({2, false}); | 36 y.MakeStatementPosition(1); |
37 CHECK_EQ(y.source_position(), 1); | 37 CHECK_EQ(y.source_position(), 1); |
38 CHECK_EQ(y.is_statement(), true); | 38 CHECK_EQ(y.is_statement(), true); |
39 | 39 |
40 y.Update({2, true}); | 40 y.MakeStatementPosition(2); |
41 CHECK_EQ(y.source_position(), 2); | 41 CHECK_EQ(y.source_position(), 2); |
42 CHECK_EQ(y.is_statement(), true); | 42 CHECK_EQ(y.is_statement(), true); |
43 | 43 |
44 y.set_invalid(); | 44 y.set_invalid(); |
45 y.Update({3, false}); | 45 y.MakeExpressionPosition(3); |
46 CHECK_EQ(y.source_position(), 3); | 46 CHECK_EQ(y.source_position(), 3); |
47 CHECK_EQ(y.is_statement(), false); | 47 CHECK_EQ(y.is_statement(), false); |
48 | 48 |
49 y.Update({3, true}); | 49 y.MakeStatementPosition(3); |
50 CHECK_EQ(y.source_position(), 3); | 50 CHECK_EQ(y.source_position(), 3); |
51 CHECK_EQ(y.is_statement(), true); | 51 CHECK_EQ(y.is_statement(), true); |
52 } | 52 } |
53 | 53 |
54 TEST_F(BytecodeNodeTest, Constructor0) { | 54 TEST_F(BytecodeNodeTest, Constructor0) { |
55 BytecodeNode node; | 55 BytecodeNode node; |
56 CHECK_EQ(node.bytecode(), Bytecode::kIllegal); | 56 CHECK_EQ(node.bytecode(), Bytecode::kIllegal); |
57 CHECK(!node.source_info().is_valid()); | 57 CHECK(!node.source_info().is_valid()); |
58 } | 58 } |
59 | 59 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 CHECK_EQ(node, node); | 115 CHECK_EQ(node, node); |
116 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 116 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
117 operands[2], operands[3]); | 117 operands[2], operands[3]); |
118 CHECK_EQ(node, other); | 118 CHECK_EQ(node, other); |
119 } | 119 } |
120 | 120 |
121 TEST_F(BytecodeNodeTest, EqualityWithSourceInfo) { | 121 TEST_F(BytecodeNodeTest, EqualityWithSourceInfo) { |
122 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 122 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
123 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 123 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
124 operands[3]); | 124 operands[3]); |
125 node.source_info().Update({3, true}); | 125 node.source_info().MakeStatementPosition(3); |
126 CHECK_EQ(node, node); | 126 CHECK_EQ(node, node); |
127 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 127 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
128 operands[2], operands[3]); | 128 operands[2], operands[3]); |
129 other.source_info().Update({3, true}); | 129 other.source_info().MakeStatementPosition(3); |
130 CHECK_EQ(node, other); | 130 CHECK_EQ(node, other); |
131 } | 131 } |
132 | 132 |
133 TEST_F(BytecodeNodeTest, NoEqualityWithDifferentSourceInfo) { | 133 TEST_F(BytecodeNodeTest, NoEqualityWithDifferentSourceInfo) { |
134 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 134 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
135 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 135 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
136 operands[3]); | 136 operands[3]); |
137 node.source_info().Update({3, true}); | 137 node.source_info().MakeStatementPosition(3); |
138 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], | 138 BytecodeNode other(Bytecode::kForInNext, operands[0], operands[1], |
139 operands[2], operands[3]); | 139 operands[2], operands[3]); |
140 CHECK_NE(node, other); | 140 CHECK_NE(node, other); |
141 } | 141 } |
142 | 142 |
143 TEST_F(BytecodeNodeTest, Clone) { | 143 TEST_F(BytecodeNodeTest, Clone) { |
144 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 144 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
145 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 145 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
146 operands[3]); | 146 operands[3]); |
147 BytecodeNode clone; | 147 BytecodeNode clone; |
148 clone.Clone(&node); | 148 clone.Clone(&node); |
149 CHECK_EQ(clone, node); | 149 CHECK_EQ(clone, node); |
150 } | 150 } |
151 | 151 |
152 TEST_F(BytecodeNodeTest, SetBytecode0) { | 152 TEST_F(BytecodeNodeTest, SetBytecode0) { |
153 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 153 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
154 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 154 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
155 operands[3]); | 155 operands[3]); |
156 BytecodeSourceInfo source_info(77, false); | 156 BytecodeSourceInfo source_info(77, false); |
157 node.source_info().Update(source_info); | 157 node.source_info().Clone(source_info); |
| 158 CHECK_EQ(node.source_info(), source_info); |
158 | 159 |
159 BytecodeNode clone; | 160 BytecodeNode clone; |
160 clone.Clone(&node); | 161 clone.Clone(&node); |
161 clone.set_bytecode(Bytecode::kNop); | 162 clone.set_bytecode(Bytecode::kNop); |
162 CHECK_EQ(clone.bytecode(), Bytecode::kNop); | 163 CHECK_EQ(clone.bytecode(), Bytecode::kNop); |
163 CHECK_EQ(clone.operand_count(), 0); | 164 CHECK_EQ(clone.operand_count(), 0); |
164 CHECK_EQ(clone.source_info(), source_info); | 165 CHECK_EQ(clone.source_info(), source_info); |
165 } | 166 } |
166 | 167 |
167 TEST_F(BytecodeNodeTest, SetBytecode1) { | 168 TEST_F(BytecodeNodeTest, SetBytecode1) { |
168 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; | 169 uint32_t operands[] = {0x71, 0xa5, 0x5a, 0xfc}; |
169 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], | 170 BytecodeNode node(Bytecode::kForInNext, operands[0], operands[1], operands[2], |
170 operands[3]); | 171 operands[3]); |
171 BytecodeSourceInfo source_info(77, false); | 172 BytecodeSourceInfo source_info(77, false); |
172 node.source_info().Update(source_info); | 173 node.source_info().Clone(source_info); |
173 | 174 |
174 BytecodeNode clone; | 175 BytecodeNode clone; |
175 clone.Clone(&node); | 176 clone.Clone(&node); |
176 clone.set_bytecode(Bytecode::kJump, 0x01aabbcc); | 177 clone.set_bytecode(Bytecode::kJump, 0x01aabbcc); |
177 CHECK_EQ(clone.bytecode(), Bytecode::kJump); | 178 CHECK_EQ(clone.bytecode(), Bytecode::kJump); |
178 CHECK_EQ(clone.operand_count(), 1); | 179 CHECK_EQ(clone.operand_count(), 1); |
179 CHECK_EQ(clone.operand(0), 0x01aabbcc); | 180 CHECK_EQ(clone.operand(0), 0x01aabbcc); |
180 CHECK_EQ(clone.source_info(), source_info); | 181 CHECK_EQ(clone.source_info(), source_info); |
181 } | 182 } |
182 | 183 |
183 } // namespace interpreter | 184 } // namespace interpreter |
184 } // namespace internal | 185 } // namespace internal |
185 } // namespace v8 | 186 } // namespace v8 |
OLD | NEW |