blob: 9e21ae415a6eaa512d32a776b3d492597cb25218 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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/source-position.h"
6#include "src/compiler/graph.h"
7#include "src/compiler/node-aux-data-inl.h"
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
Emily Bernierd0a1eb72015-03-24 16:35:39 -040013class SourcePositionTable::Decorator FINAL : public GraphDecorator {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014 public:
15 explicit Decorator(SourcePositionTable* source_positions)
16 : source_positions_(source_positions) {}
17
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018 void Decorate(Node* node) FINAL {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019 DCHECK(!source_positions_->current_position_.IsInvalid());
20 source_positions_->table_.Set(node, source_positions_->current_position_);
21 }
22
23 private:
24 SourcePositionTable* source_positions_;
25};
26
27
28SourcePositionTable::SourcePositionTable(Graph* graph)
29 : graph_(graph),
30 decorator_(NULL),
31 current_position_(SourcePosition::Invalid()),
32 table_(graph->zone()) {}
33
34
35void SourcePositionTable::AddDecorator() {
36 DCHECK(decorator_ == NULL);
37 decorator_ = new (graph_->zone()) Decorator(this);
38 graph_->AddDecorator(decorator_);
39}
40
41
42void SourcePositionTable::RemoveDecorator() {
43 DCHECK(decorator_ != NULL);
44 graph_->RemoveDecorator(decorator_);
45 decorator_ = NULL;
46}
47
48
Emily Bernierd0a1eb72015-03-24 16:35:39 -040049SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 return table_.Get(node);
51}
52
53} // namespace compiler
54} // namespace internal
55} // namespace v8