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_SOURCE_POSITION_H_ |
| 6 #define V8_SOURCE_POSITION_H_ |
| 7 |
| 8 #include <ostream> |
| 9 |
| 10 #include "src/assembler.h" |
| 11 #include "src/flags.h" |
| 12 #include "src/utils.h" |
| 13 |
| 14 namespace v8 { |
| 15 namespace internal { |
| 16 |
| 17 // This class encapsulates encoding and decoding of sources positions from |
| 18 // which hydrogen values originated. |
| 19 // When FLAG_track_hydrogen_positions is set this object encodes the |
| 20 // identifier of the inlining and absolute offset from the start of the |
| 21 // inlined function. |
| 22 // When the flag is not set we simply track absolute offset from the |
| 23 // script start. |
| 24 class SourcePosition { |
| 25 public: |
| 26 static SourcePosition Unknown() { |
| 27 return SourcePosition::FromRaw(kNoPosition); |
| 28 } |
| 29 |
| 30 bool IsUnknown() const { return value_ == kNoPosition; } |
| 31 |
| 32 uint32_t position() const { return PositionField::decode(value_); } |
| 33 void set_position(uint32_t position) { |
| 34 if (FLAG_hydrogen_track_positions) { |
| 35 value_ = static_cast<uint32_t>(PositionField::update(value_, position)); |
| 36 } else { |
| 37 value_ = position; |
| 38 } |
| 39 } |
| 40 |
| 41 uint32_t inlining_id() const { return InliningIdField::decode(value_); } |
| 42 void set_inlining_id(uint32_t inlining_id) { |
| 43 if (FLAG_hydrogen_track_positions) { |
| 44 value_ = |
| 45 static_cast<uint32_t>(InliningIdField::update(value_, inlining_id)); |
| 46 } |
| 47 } |
| 48 |
| 49 uint32_t raw() const { return value_; } |
| 50 |
| 51 private: |
| 52 static const uint32_t kNoPosition = |
| 53 static_cast<uint32_t>(RelocInfo::kNoPosition); |
| 54 typedef BitField<uint32_t, 0, 9> InliningIdField; |
| 55 |
| 56 // Offset from the start of the inlined function. |
| 57 typedef BitField<uint32_t, 9, 23> PositionField; |
| 58 |
| 59 friend class HPositionInfo; |
| 60 friend class Deoptimizer; |
| 61 |
| 62 static SourcePosition FromRaw(uint32_t raw_position) { |
| 63 SourcePosition position; |
| 64 position.value_ = raw_position; |
| 65 return position; |
| 66 } |
| 67 |
| 68 // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField |
| 69 // and PositionField. |
| 70 // Otherwise contains absolute offset from the script start. |
| 71 uint32_t value_; |
| 72 }; |
| 73 |
| 74 inline std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { |
| 75 if (p.IsUnknown()) { |
| 76 return os << "<?>"; |
| 77 } else if (FLAG_hydrogen_track_positions) { |
| 78 return os << "<" << p.inlining_id() << ":" << p.position() << ">"; |
| 79 } else { |
| 80 return os << "<0:" << p.raw() << ">"; |
| 81 } |
| 82 } |
| 83 |
| 84 } // namespace internal |
| 85 } // namespace v8 |
| 86 |
| 87 #endif // V8_SOURCE_POSITION_H_ |
OLD | NEW |