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_(isolate(), zone()), |
26 bytecode_array_writer_(isolate(), zone(), &constant_array_builder_) {} | 26 bytecode_array_writer_( |
| 27 isolate(), zone(), &constant_array_builder_, |
| 28 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {} |
27 ~BytecodeArrayWriterUnittest() override {} | 29 ~BytecodeArrayWriterUnittest() override {} |
28 | 30 |
29 void Write(BytecodeNode* node, const BytecodeSourceInfo& info); | 31 void Write(BytecodeNode* node, const BytecodeSourceInfo& info); |
30 void Write(Bytecode bytecode, | 32 void Write(Bytecode bytecode, |
31 const BytecodeSourceInfo& info = BytecodeSourceInfo()); | 33 const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
32 void Write(Bytecode bytecode, uint32_t operand0, | 34 void Write(Bytecode bytecode, uint32_t operand0, |
33 const BytecodeSourceInfo& info = BytecodeSourceInfo()); | 35 const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
34 void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 36 void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
35 | 37 |
36 const BytecodeSourceInfo& info = BytecodeSourceInfo()); | 38 const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 CHECK_EQ(bytecodes()->size(), 8); | 130 CHECK_EQ(bytecodes()->size(), 8); |
129 CHECK_EQ(max_register_count(), 201); | 131 CHECK_EQ(max_register_count(), 201); |
130 | 132 |
131 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), |
132 B(Ldar), R16(200), B(Return)}; | 134 B(Ldar), R16(200), B(Return)}; |
133 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); | 135 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); |
134 for (size_t i = 0; i < arraysize(bytes); ++i) { | 136 for (size_t i = 0; i < arraysize(bytes); ++i) { |
135 CHECK_EQ(bytecodes()->at(i), bytes[i]); | 137 CHECK_EQ(bytecodes()->at(i), bytes[i]); |
136 } | 138 } |
137 | 139 |
138 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); | 140 Handle<BytecodeArray> bytecode_array = |
| 141 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); |
139 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); | 142 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); |
140 | 143 |
141 PositionTableEntry expected_positions[] = { | 144 PositionTableEntry expected_positions[] = { |
142 {0, 10, false}, {1, 55, true}, {7, 70, true}}; | 145 {0, 10, false}, {1, 55, true}, {7, 70, true}}; |
143 Handle<ByteArray> source_positions = | 146 SourcePositionTableIterator source_iterator( |
144 source_position_table_builder()->ToSourcePositionTable(); | 147 bytecode_array->source_position_table()); |
145 SourcePositionTableIterator source_iterator(*source_positions); | |
146 for (size_t i = 0; i < arraysize(expected_positions); ++i) { | 148 for (size_t i = 0; i < arraysize(expected_positions); ++i) { |
147 const PositionTableEntry& expected = expected_positions[i]; | 149 const PositionTableEntry& expected = expected_positions[i]; |
148 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); | 150 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); |
149 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 151 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
150 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 152 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
151 source_iterator.Advance(); | 153 source_iterator.Advance(); |
152 } | 154 } |
153 CHECK(source_iterator.done()); | 155 CHECK(source_iterator.done()); |
154 } | 156 } |
155 | 157 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 247 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
246 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 248 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
247 source_iterator.Advance(); | 249 source_iterator.Advance(); |
248 } | 250 } |
249 CHECK(source_iterator.done()); | 251 CHECK(source_iterator.done()); |
250 } | 252 } |
251 | 253 |
252 } // namespace interpreter | 254 } // namespace interpreter |
253 } // namespace internal | 255 } // namespace internal |
254 } // namespace v8 | 256 } // namespace v8 |
OLD | NEW |