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/handles.h" |
| 10 #include "src/zone.h" |
| 11 #include "src/zone-containers.h" |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 |
| 16 class BytecodeArray; |
| 17 class FixedArray; |
| 18 class Isolate; |
| 19 |
| 20 namespace interpreter { |
| 21 |
| 22 class SourcePositionTableBuilder { |
| 23 public: |
| 24 explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone) |
| 25 : isolate_(isolate), entries_(zone) {} |
| 26 |
| 27 void AddStatementPosition(int bytecode_offset, int source_position); |
| 28 void AddExpressionPosition(int bytecode_offset, int source_position); |
| 29 Handle<FixedArray> ToFixedArray(); |
| 30 |
| 31 private: |
| 32 struct Entry { |
| 33 int bytecode_offset; |
| 34 uint32_t source_position_and_type; |
| 35 }; |
| 36 |
| 37 void AssertMonotonic(int bytecode_offset) { |
| 38 DCHECK(entries_.size() == 0 || |
| 39 entries_.back().bytecode_offset < bytecode_offset); |
| 40 } |
| 41 |
| 42 Isolate* isolate_; |
| 43 ZoneVector<Entry> entries_; |
| 44 }; |
| 45 |
| 46 class SourcePositionTableIterator { |
| 47 public: |
| 48 explicit SourcePositionTableIterator(BytecodeArray* bytecode_array); |
| 49 |
| 50 static int PositionFromBytecodeOffset(BytecodeArray* bytecode_array, |
| 51 int bytecode_offset); |
| 52 void Advance(); |
| 53 |
| 54 int bytecode_offset() const { |
| 55 DCHECK(!done()); |
| 56 return bytecode_offset_; |
| 57 } |
| 58 int source_position() const { |
| 59 DCHECK(!done()); |
| 60 return source_position_; |
| 61 } |
| 62 bool is_statement() const { |
| 63 DCHECK(!done()); |
| 64 return is_statement_; |
| 65 } |
| 66 bool done() const { return index_ > length_; } |
| 67 |
| 68 private: |
| 69 FixedArray* table_; |
| 70 int index_; |
| 71 int length_; |
| 72 bool is_statement_; |
| 73 int bytecode_offset_; |
| 74 int source_position_; |
| 75 DisallowHeapAllocation no_gc; |
| 76 }; |
| 77 |
| 78 } // namespace interpreter |
| 79 } // namespace internal |
| 80 } // namespace v8 |
| 81 |
| 82 #endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_ |
OLD | NEW |