compiler-source-position-table.h 2.38 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_COMPILER_SOURCE_POSITION_TABLE_H_
#define V8_COMPILER_COMPILER_SOURCE_POSITION_TABLE_H_
7

8
#include "src/base/compiler-specific.h"
9
#include "src/codegen/source-position.h"
10
#include "src/common/globals.h"
11 12 13 14 15 16
#include "src/compiler/node-aux-data.h"

namespace v8 {
namespace internal {
namespace compiler {

17 18
class V8_EXPORT_PRIVATE SourcePositionTable final
    : public NON_EXPORTED_BASE(ZoneObject) {
19
 public:
20
  class V8_NODISCARD Scope final {
21 22 23 24 25 26 27 28 29 30 31 32
   public:
    Scope(SourcePositionTable* source_positions, SourcePosition position)
        : source_positions_(source_positions),
          prev_position_(source_positions->current_position_) {
      Init(position);
    }
    Scope(SourcePositionTable* source_positions, Node* node)
        : source_positions_(source_positions),
          prev_position_(source_positions->current_position_) {
      Init(source_positions_->GetSourcePosition(node));
    }
    ~Scope() { source_positions_->current_position_ = prev_position_; }
33 34
    Scope(const Scope&) = delete;
    Scope& operator=(const Scope&) = delete;
35 36 37

   private:
    void Init(SourcePosition position) {
38
      if (position.IsKnown()) source_positions_->current_position_ = position;
39 40
    }

41 42
    SourcePositionTable* const source_positions_;
    SourcePosition const prev_position_;
43 44 45
  };

  explicit SourcePositionTable(Graph* graph);
46 47
  SourcePositionTable(const SourcePositionTable&) = delete;
  SourcePositionTable& operator=(const SourcePositionTable&) = delete;
48 49 50 51

  void AddDecorator();
  void RemoveDecorator();

52
  SourcePosition GetSourcePosition(Node* node) const;
53
  void SetSourcePosition(Node* node, SourcePosition position);
54

55 56
  void SetCurrentPosition(const SourcePosition& pos) {
    current_position_ = pos;
57
  }
58
  SourcePosition GetCurrentPosition() const { return current_position_; }
59

60
  void PrintJson(std::ostream& os) const;
61

62 63 64
 private:
  class Decorator;

65 66 67 68
  static SourcePosition UnknownSourcePosition(Zone* zone) {
    return SourcePosition::Unknown();
  }

69
  Graph* const graph_;
70 71
  Decorator* decorator_;
  SourcePosition current_position_;
72
  NodeAuxData<SourcePosition, UnknownSourcePosition> table_;
73 74 75 76 77 78
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

79
#endif  // V8_COMPILER_COMPILER_SOURCE_POSITION_TABLE_H_