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