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/checks.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 source_position(source), | 29 source_position(source), |
30 is_statement(statement) {} | 30 is_statement(statement) {} |
31 | 31 |
32 int bytecode_offset; | 32 int bytecode_offset; |
33 int source_position; | 33 int source_position; |
34 bool is_statement; | 34 bool is_statement; |
35 }; | 35 }; |
36 | 36 |
37 class SourcePositionTableBuilder : public PositionsRecorder { | 37 class SourcePositionTableBuilder : public PositionsRecorder { |
38 public: | 38 public: |
| 39 enum OnDuplicateCodeOffset { |
| 40 DISCARD_DUPLICATE, |
| 41 OVERWRITE_DUPLICATE, |
| 42 }; |
| 43 |
39 explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone) | 44 explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone) |
40 : isolate_(isolate), | 45 : isolate_(isolate), |
41 bytes_(zone), | 46 bytes_(zone), |
42 #ifdef ENABLE_SLOW_DCHECKS | 47 #ifdef ENABLE_SLOW_DCHECKS |
43 raw_entries_(zone), | 48 raw_entries_(zone), |
44 #endif | 49 #endif |
45 previous_() { | 50 candidate_(kUninitializedCandidateOffset, 0, false) { |
46 } | 51 } |
47 | 52 |
48 void AddStatementPosition(size_t bytecode_offset, int source_position); | 53 void AddStatementPosition( |
| 54 size_t bytecode_offset, int source_position, |
| 55 OnDuplicateCodeOffset on_duplicate = DISCARD_DUPLICATE); |
49 void AddExpressionPosition(size_t bytecode_offset, int source_position); | 56 void AddExpressionPosition(size_t bytecode_offset, int source_position); |
50 Handle<ByteArray> ToSourcePositionTable(); | 57 Handle<ByteArray> ToSourcePositionTable(); |
51 | 58 |
52 private: | 59 private: |
53 void AddEntry(const PositionTableEntry& entry); | 60 static const int kUninitializedCandidateOffset = -1; |
| 61 |
| 62 void AddEntry(const PositionTableEntry& entry, |
| 63 OnDuplicateCodeOffset on_duplicate = DISCARD_DUPLICATE); |
| 64 void CommitEntry(); |
54 | 65 |
55 Isolate* isolate_; | 66 Isolate* isolate_; |
56 ZoneVector<byte> bytes_; | 67 ZoneVector<byte> bytes_; |
57 #ifdef ENABLE_SLOW_DCHECKS | 68 #ifdef ENABLE_SLOW_DCHECKS |
58 ZoneVector<PositionTableEntry> raw_entries_; | 69 ZoneVector<PositionTableEntry> raw_entries_; |
59 #endif | 70 #endif |
60 PositionTableEntry previous_; | 71 PositionTableEntry candidate_; // Next entry to be written, if initialized. |
| 72 PositionTableEntry previous_; // Previously written entry, to compute delta. |
61 }; | 73 }; |
62 | 74 |
63 class SourcePositionTableIterator { | 75 class SourcePositionTableIterator { |
64 public: | 76 public: |
65 explicit SourcePositionTableIterator(ByteArray* byte_array); | 77 explicit SourcePositionTableIterator(ByteArray* byte_array); |
66 | 78 |
67 void Advance(); | 79 void Advance(); |
68 | 80 |
69 int bytecode_offset() const { | 81 int bytecode_offset() const { |
70 DCHECK(!done()); | 82 DCHECK(!done()); |
(...skipping 16 matching lines...) Expand all Loading... |
87 int index_; | 99 int index_; |
88 PositionTableEntry current_; | 100 PositionTableEntry current_; |
89 DisallowHeapAllocation no_gc; | 101 DisallowHeapAllocation no_gc; |
90 }; | 102 }; |
91 | 103 |
92 } // namespace interpreter | 104 } // namespace interpreter |
93 } // namespace internal | 105 } // namespace internal |
94 } // namespace v8 | 106 } // namespace v8 |
95 | 107 |
96 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | 108 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ |
OLD | NEW |