Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/compiler/compiler-source-position-table.h"
6 : #include "src/compiler/graph.h"
7 : #include "src/compiler/node-aux-data.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 : namespace compiler {
12 :
13 0 : class SourcePositionTable::Decorator final : public GraphDecorator {
14 : public:
15 : explicit Decorator(SourcePositionTable* source_positions)
16 707121 : : source_positions_(source_positions) {}
17 :
18 103715695 : void Decorate(Node* node) final {
19 : source_positions_->SetSourcePosition(node,
20 103715695 : source_positions_->current_position_);
21 103714640 : }
22 :
23 : private:
24 : SourcePositionTable* source_positions_;
25 : };
26 :
27 4664660 : SourcePositionTable::SourcePositionTable(Graph* graph)
28 : : graph_(graph),
29 : decorator_(nullptr),
30 : current_position_(SourcePosition::Unknown()),
31 4664660 : table_(graph->zone()) {}
32 :
33 707121 : void SourcePositionTable::AddDecorator() {
34 : DCHECK_NULL(decorator_);
35 1414242 : decorator_ = new (graph_->zone()) Decorator(this);
36 707121 : graph_->AddDecorator(decorator_);
37 707122 : }
38 :
39 638227 : void SourcePositionTable::RemoveDecorator() {
40 : DCHECK_NOT_NULL(decorator_);
41 638227 : graph_->RemoveDecorator(decorator_);
42 638230 : decorator_ = nullptr;
43 638230 : }
44 :
45 149795567 : SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const {
46 149795567 : return table_.Get(node);
47 : }
48 :
49 325059 : void SourcePositionTable::SetSourcePosition(Node* node,
50 : SourcePosition position) {
51 104040754 : table_.Set(node, position);
52 325147 : }
53 :
54 1 : void SourcePositionTable::PrintJson(std::ostream& os) const {
55 1 : os << "{";
56 : bool needs_comma = false;
57 71 : for (auto i : table_) {
58 70 : SourcePosition pos = i.second;
59 70 : if (pos.IsKnown()) {
60 56 : if (needs_comma) {
61 55 : os << ",";
62 : }
63 112 : os << "\"" << i.first << "\" : ";
64 56 : pos.PrintJson(os);
65 : needs_comma = true;
66 : }
67 : }
68 1 : os << "}";
69 1 : }
70 :
71 : } // namespace compiler
72 : } // namespace internal
73 178779 : } // namespace v8
|