| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/compiler/source-position.h" | 5 #include "src/compiler/compiler-source-position-table.h" |
| 6 #include "src/compiler/graph.h" | 6 #include "src/compiler/graph.h" |
| 7 #include "src/compiler/node-aux-data.h" | 7 #include "src/compiler/node-aux-data.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 namespace compiler { | 11 namespace compiler { |
| 12 | 12 |
| 13 class SourcePositionTable::Decorator final : public GraphDecorator { | 13 class SourcePositionTable::Decorator final : public GraphDecorator { |
| 14 public: | 14 public: |
| 15 explicit Decorator(SourcePositionTable* source_positions) | 15 explicit Decorator(SourcePositionTable* source_positions) |
| 16 : source_positions_(source_positions) {} | 16 : source_positions_(source_positions) {} |
| 17 | 17 |
| 18 void Decorate(Node* node) final { | 18 void Decorate(Node* node) final { |
| 19 source_positions_->SetSourcePosition(node, | 19 source_positions_->SetSourcePosition(node, |
| 20 source_positions_->current_position_); | 20 source_positions_->current_position_); |
| 21 } | 21 } |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 SourcePositionTable* source_positions_; | 24 SourcePositionTable* source_positions_; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 | |
| 28 SourcePositionTable::SourcePositionTable(Graph* graph) | 27 SourcePositionTable::SourcePositionTable(Graph* graph) |
| 29 : graph_(graph), | 28 : graph_(graph), |
| 30 decorator_(nullptr), | 29 decorator_(nullptr), |
| 31 current_position_(SourcePosition::Unknown()), | 30 current_position_(SourcePosition::Unknown()), |
| 32 table_(graph->zone()) {} | 31 table_(graph->zone()) {} |
| 33 | 32 |
| 34 | |
| 35 void SourcePositionTable::AddDecorator() { | 33 void SourcePositionTable::AddDecorator() { |
| 36 DCHECK_NULL(decorator_); | 34 DCHECK_NULL(decorator_); |
| 37 decorator_ = new (graph_->zone()) Decorator(this); | 35 decorator_ = new (graph_->zone()) Decorator(this); |
| 38 graph_->AddDecorator(decorator_); | 36 graph_->AddDecorator(decorator_); |
| 39 } | 37 } |
| 40 | 38 |
| 41 | |
| 42 void SourcePositionTable::RemoveDecorator() { | 39 void SourcePositionTable::RemoveDecorator() { |
| 43 DCHECK_NOT_NULL(decorator_); | 40 DCHECK_NOT_NULL(decorator_); |
| 44 graph_->RemoveDecorator(decorator_); | 41 graph_->RemoveDecorator(decorator_); |
| 45 decorator_ = nullptr; | 42 decorator_ = nullptr; |
| 46 } | 43 } |
| 47 | 44 |
| 48 | |
| 49 SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const { | 45 SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const { |
| 50 return table_.Get(node); | 46 return table_.Get(node); |
| 51 } | 47 } |
| 52 | 48 |
| 53 void SourcePositionTable::SetSourcePosition(Node* node, | 49 void SourcePositionTable::SetSourcePosition(Node* node, |
| 54 SourcePosition position) { | 50 SourcePosition position) { |
| 55 table_.Set(node, position); | 51 table_.Set(node, position); |
| 56 } | 52 } |
| 57 | 53 |
| 58 void SourcePositionTable::Print(std::ostream& os) const { | 54 void SourcePositionTable::Print(std::ostream& os) const { |
| 59 os << "{"; | 55 os << "{"; |
| 60 bool needs_comma = false; | 56 bool needs_comma = false; |
| 61 for (auto i : table_) { | 57 for (auto i : table_) { |
| 62 SourcePosition pos = i.second; | 58 SourcePosition pos = i.second; |
| 63 if (pos.IsKnown()) { | 59 if (pos.IsKnown()) { |
| 64 if (needs_comma) { | 60 if (needs_comma) { |
| 65 os << ","; | 61 os << ","; |
| 66 } | 62 } |
| 67 os << "\"" << i.first << "\"" | 63 os << "\"" << i.first << "\"" |
| 68 << ":" << pos.raw(); | 64 << ":" << pos.ScriptOffset(); |
| 69 needs_comma = true; | 65 needs_comma = true; |
| 70 } | 66 } |
| 71 } | 67 } |
| 72 os << "}"; | 68 os << "}"; |
| 73 } | 69 } |
| 74 | 70 |
| 75 } // namespace compiler | 71 } // namespace compiler |
| 76 } // namespace internal | 72 } // namespace internal |
| 77 } // namespace v8 | 73 } // namespace v8 |
| OLD | NEW |