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 #ifndef V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | 5 #ifndef V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ |
6 #define V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | 6 #define V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ |
7 | 7 |
8 #include "src/assert-scope.h" | 8 #include "src/assert-scope.h" |
| 9 #include "src/checks.h" |
9 #include "src/handles.h" | 10 #include "src/handles.h" |
10 #include "src/zone.h" | |
11 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 class BytecodeArray; | 16 class BytecodeArray; |
17 class FixedArray; | 17 class ByteArray; |
18 class Isolate; | 18 class Isolate; |
| 19 class Zone; |
19 | 20 |
20 namespace interpreter { | 21 namespace interpreter { |
21 | 22 |
| 23 struct PositionTableEntry { |
| 24 int bytecode_offset; |
| 25 int source_position; |
| 26 bool is_statement; |
| 27 }; |
| 28 |
22 class SourcePositionTableBuilder { | 29 class SourcePositionTableBuilder { |
23 public: | 30 public: |
24 explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone) | 31 explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone) |
25 : isolate_(isolate), entries_(zone) {} | 32 : isolate_(isolate), |
| 33 bytes_(zone), |
| 34 previous_bytecode_offset_(0), |
| 35 previous_source_position_(0) {} |
26 | 36 |
27 void AddStatementPosition(size_t bytecode_offset, int source_position); | 37 void AddStatementPosition(size_t bytecode_offset, int source_position); |
28 void AddExpressionPosition(size_t bytecode_offset, int source_position); | 38 void AddExpressionPosition(size_t bytecode_offset, int source_position); |
29 void RevertPosition(size_t bytecode_offset); | 39 void RevertPosition(size_t bytecode_offset); |
30 Handle<FixedArray> ToFixedArray(); | 40 Handle<ByteArray> ToSourcePositionTable(); |
31 | 41 |
32 private: | 42 private: |
33 struct Entry { | 43 void AddEntry(const PositionTableEntry& entry); |
34 int bytecode_offset; | |
35 uint32_t source_position_and_type; | |
36 }; | |
37 | |
38 bool CodeOffsetHasPosition(int bytecode_offset) { | 44 bool CodeOffsetHasPosition(int bytecode_offset) { |
39 // Return whether bytecode offset already has a position assigned. | 45 // Return whether bytecode offset already has a position assigned. |
40 return entries_.size() > 0 && | 46 return bytes_.size() > 0 && previous_bytecode_offset_ == bytecode_offset; |
41 entries_.back().bytecode_offset == bytecode_offset; | |
42 } | 47 } |
43 | 48 |
44 Isolate* isolate_; | 49 Isolate* isolate_; |
45 ZoneVector<Entry> entries_; | 50 ZoneVector<byte> bytes_; |
| 51 int previous_bytecode_offset_; |
| 52 int previous_source_position_; |
| 53 |
| 54 #ifdef ENABLE_SLOW_DCHECKS |
| 55 std::vector<PositionTableEntry> raw_entries_; |
| 56 #endif |
46 }; | 57 }; |
47 | 58 |
48 class SourcePositionTableIterator { | 59 class SourcePositionTableIterator { |
49 public: | 60 public: |
50 explicit SourcePositionTableIterator(BytecodeArray* bytecode_array); | 61 explicit SourcePositionTableIterator(ByteArray* byte_array); |
51 | 62 |
52 void Advance(); | 63 void Advance(); |
53 | 64 |
54 int bytecode_offset() const { | 65 int bytecode_offset() const { |
55 DCHECK(!done()); | 66 DCHECK(!done()); |
56 return bytecode_offset_; | 67 return current_.bytecode_offset; |
57 } | 68 } |
58 int source_position() const { | 69 int source_position() const { |
59 DCHECK(!done()); | 70 DCHECK(!done()); |
60 return source_position_; | 71 return current_.source_position; |
61 } | 72 } |
62 bool is_statement() const { | 73 bool is_statement() const { |
63 DCHECK(!done()); | 74 DCHECK(!done()); |
64 return is_statement_; | 75 return current_.is_statement; |
65 } | 76 } |
66 bool done() const { return index_ > length_; } | 77 bool done() const { return index_ == kDone; } |
67 | 78 |
68 private: | 79 private: |
69 FixedArray* table_; | 80 static const int kDone = -1; |
| 81 |
| 82 ByteArray* table_; |
70 int index_; | 83 int index_; |
71 int length_; | 84 int previous_bytecode_offset_; |
72 bool is_statement_; | 85 int previous_source_position_; |
73 int bytecode_offset_; | 86 PositionTableEntry current_; |
74 int source_position_; | |
75 DisallowHeapAllocation no_gc; | 87 DisallowHeapAllocation no_gc; |
76 }; | 88 }; |
77 | 89 |
78 } // namespace interpreter | 90 } // namespace interpreter |
79 } // namespace internal | 91 } // namespace internal |
80 } // namespace v8 | 92 } // namespace v8 |
81 | 93 |
82 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | 94 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ |
OLD | NEW |