OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | |
6 #define V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | |
7 | |
8 #include "src/assert-scope.h" | |
9 #include "src/checks.h" | |
10 #include "src/handles.h" | |
11 #include "src/log.h" | |
12 #include "src/zone-containers.h" | |
13 | |
14 namespace v8 { | |
15 namespace internal { | |
16 | |
17 class BytecodeArray; | |
18 class ByteArray; | |
19 class Isolate; | |
20 class Zone; | |
21 | |
22 namespace interpreter { | |
23 | |
24 struct PositionTableEntry { | |
25 PositionTableEntry() | |
26 : bytecode_offset(0), source_position(0), is_statement(false) {} | |
27 PositionTableEntry(int bytecode, int source, bool statement) | |
28 : bytecode_offset(bytecode), | |
29 source_position(source), | |
30 is_statement(statement) {} | |
31 | |
32 int bytecode_offset; | |
33 int source_position; | |
34 bool is_statement; | |
35 }; | |
36 | |
37 class SourcePositionTableBuilder final : public PositionsRecorder { | |
38 public: | |
39 SourcePositionTableBuilder(Isolate* isolate, Zone* zone) | |
40 : isolate_(isolate), | |
41 bytes_(zone), | |
42 #ifdef ENABLE_SLOW_DCHECKS | |
43 raw_entries_(zone), | |
44 #endif | |
45 previous_() { | |
46 } | |
47 | |
48 void AddPosition(size_t bytecode_offset, int source_position, | |
49 bool is_statement); | |
50 Handle<ByteArray> ToSourcePositionTable(); | |
51 | |
52 private: | |
53 void AddEntry(const PositionTableEntry& entry); | |
54 void CommitEntry(); | |
55 | |
56 Isolate* isolate_; | |
57 ZoneVector<byte> bytes_; | |
58 #ifdef ENABLE_SLOW_DCHECKS | |
59 ZoneVector<PositionTableEntry> raw_entries_; | |
60 #endif | |
61 PositionTableEntry previous_; // Previously written entry, to compute delta. | |
62 }; | |
63 | |
64 class SourcePositionTableIterator { | |
65 public: | |
66 explicit SourcePositionTableIterator(ByteArray* byte_array); | |
67 | |
68 void Advance(); | |
69 | |
70 int bytecode_offset() const { | |
71 DCHECK(!done()); | |
72 return current_.bytecode_offset; | |
73 } | |
74 int source_position() const { | |
75 DCHECK(!done()); | |
76 return current_.source_position; | |
77 } | |
78 bool is_statement() const { | |
79 DCHECK(!done()); | |
80 return current_.is_statement; | |
81 } | |
82 bool done() const { return index_ == kDone; } | |
83 | |
84 private: | |
85 static const int kDone = -1; | |
86 | |
87 ByteArray* table_; | |
88 int index_; | |
89 PositionTableEntry current_; | |
90 DisallowHeapAllocation no_gc; | |
91 }; | |
92 | |
93 } // namespace interpreter | |
94 } // namespace internal | |
95 } // namespace v8 | |
96 | |
97 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ | |
OLD | NEW |