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