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/api.h" | 7 #include "src/api.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/interpreter/bytecode-array-writer.h" | 9 #include "src/interpreter/bytecode-array-writer.h" |
10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
11 #include "src/interpreter/constant-array-builder.h" | 11 #include "src/interpreter/constant-array-builder.h" |
12 #include "src/isolate.h" | 12 #include "src/isolate.h" |
13 #include "src/source-position-table.h" | 13 #include "src/source-position-table.h" |
14 #include "src/utils.h" | 14 #include "src/utils.h" |
15 #include "test/unittests/interpreter/bytecode-utils.h" | 15 #include "test/unittests/interpreter/bytecode-utils.h" |
16 #include "test/unittests/test-utils.h" | 16 #include "test/unittests/test-utils.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 namespace interpreter { | 20 namespace interpreter { |
21 | 21 |
22 class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone { | 22 class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone { |
23 public: | 23 public: |
24 BytecodeArrayWriterUnittest() | 24 BytecodeArrayWriterUnittest() |
25 : constant_array_builder_(isolate(), zone()), | 25 : constant_array_builder_(zone(), isolate()->factory()->the_hole_value()), |
26 bytecode_array_writer_( | 26 bytecode_array_writer_( |
27 isolate(), zone(), &constant_array_builder_, | 27 zone(), &constant_array_builder_, |
28 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {} | 28 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {} |
29 ~BytecodeArrayWriterUnittest() override {} | 29 ~BytecodeArrayWriterUnittest() override {} |
30 | 30 |
31 void Write(BytecodeNode* node, const BytecodeSourceInfo& info); | 31 void Write(BytecodeNode* node, const BytecodeSourceInfo& info); |
32 void Write(Bytecode bytecode, | 32 void Write(Bytecode bytecode, |
33 const BytecodeSourceInfo& info = BytecodeSourceInfo()); | 33 const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
34 void Write(Bytecode bytecode, uint32_t operand0, | 34 void Write(Bytecode bytecode, uint32_t operand0, |
35 const BytecodeSourceInfo& info = BytecodeSourceInfo()); | 35 const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
36 void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 36 void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
37 | 37 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 CHECK_EQ(bytecodes()->size(), 8); | 130 CHECK_EQ(bytecodes()->size(), 8); |
131 CHECK_EQ(max_register_count(), 201); | 131 CHECK_EQ(max_register_count(), 201); |
132 | 132 |
133 static const uint8_t bytes[] = {B(StackCheck), B(LdaSmi), U8(127), B(Wide), | 133 static const uint8_t bytes[] = {B(StackCheck), B(LdaSmi), U8(127), B(Wide), |
134 B(Ldar), R16(200), B(Return)}; | 134 B(Ldar), R16(200), B(Return)}; |
135 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); | 135 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); |
136 for (size_t i = 0; i < arraysize(bytes); ++i) { | 136 for (size_t i = 0; i < arraysize(bytes); ++i) { |
137 CHECK_EQ(bytecodes()->at(i), bytes[i]); | 137 CHECK_EQ(bytecodes()->at(i), bytes[i]); |
138 } | 138 } |
139 | 139 |
140 Handle<BytecodeArray> bytecode_array = | 140 Handle<BytecodeArray> bytecode_array = writer()->ToBytecodeArray( |
141 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); | 141 isolate(), 0, 0, factory()->empty_fixed_array()); |
142 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); | 142 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); |
143 | 143 |
144 PositionTableEntry expected_positions[] = { | 144 PositionTableEntry expected_positions[] = { |
145 {0, 10, false}, {1, 55, true}, {7, 70, true}}; | 145 {0, 10, false}, {1, 55, true}, {7, 70, true}}; |
146 SourcePositionTableIterator source_iterator( | 146 SourcePositionTableIterator source_iterator( |
147 bytecode_array->source_position_table()); | 147 bytecode_array->source_position_table()); |
148 for (size_t i = 0; i < arraysize(expected_positions); ++i) { | 148 for (size_t i = 0; i < arraysize(expected_positions); ++i) { |
149 const PositionTableEntry& expected = expected_positions[i]; | 149 const PositionTableEntry& expected = expected_positions[i]; |
150 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); | 150 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); |
151 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 151 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Write(Bytecode::kReturn, {85, true}); | 228 Write(Bytecode::kReturn, {85, true}); |
229 CHECK_EQ(max_register_count(), 8); | 229 CHECK_EQ(max_register_count(), 8); |
230 #undef R | 230 #undef R |
231 | 231 |
232 CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes)); | 232 CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes)); |
233 for (size_t i = 0; i < arraysize(expected_bytes); ++i) { | 233 for (size_t i = 0; i < arraysize(expected_bytes); ++i) { |
234 CHECK_EQ(static_cast<int>(bytecodes()->at(i)), | 234 CHECK_EQ(static_cast<int>(bytecodes()->at(i)), |
235 static_cast<int>(expected_bytes[i])); | 235 static_cast<int>(expected_bytes[i])); |
236 } | 236 } |
237 | 237 |
238 Handle<BytecodeArray> bytecode_array = | 238 Handle<BytecodeArray> bytecode_array = writer()->ToBytecodeArray( |
239 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); | 239 isolate(), 0, 0, factory()->empty_fixed_array()); |
240 SourcePositionTableIterator source_iterator( | 240 SourcePositionTableIterator source_iterator( |
241 bytecode_array->source_position_table()); | 241 bytecode_array->source_position_table()); |
242 for (size_t i = 0; i < arraysize(expected_positions); ++i) { | 242 for (size_t i = 0; i < arraysize(expected_positions); ++i) { |
243 const PositionTableEntry& expected = expected_positions[i]; | 243 const PositionTableEntry& expected = expected_positions[i]; |
244 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); | 244 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); |
245 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 245 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
246 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 246 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
247 source_iterator.Advance(); | 247 source_iterator.Advance(); |
248 } | 248 } |
249 CHECK(source_iterator.done()); | 249 CHECK(source_iterator.done()); |
250 } | 250 } |
251 | 251 |
252 } // namespace interpreter | 252 } // namespace interpreter |
253 } // namespace internal | 253 } // namespace internal |
254 } // namespace v8 | 254 } // namespace v8 |
OLD | NEW |