Update DebugInfo interface to use metadata, instead of special named llvm.dbg......
[oota-llvm.git] / include / llvm / Support / DebugLoc.h
1 //===---- llvm/DebugLoc.h - Debug Location Information ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a number of light weight data structures used
11 // to describe and track debug location information.
12 // 
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_DEBUGLOC_H
16 #define LLVM_DEBUGLOC_H
17
18 #include "llvm/ADT/DenseMap.h"
19 #include <vector>
20
21 namespace llvm {
22   class MDNode;
23
24   /// DebugLocTuple - Debug location tuple of filename id, line and column.
25   ///
26   struct DebugLocTuple {
27     MDNode *CompileUnit;
28     unsigned Line, Col;
29
30     DebugLocTuple()
31       : CompileUnit(0), Line(~0U), Col(~0U) {};
32
33     DebugLocTuple(MDNode *n, unsigned l, unsigned c)
34       : CompileUnit(n), Line(l), Col(c) {};
35
36     bool operator==(const DebugLocTuple &DLT) const {
37       return CompileUnit == DLT.CompileUnit &&
38              Line == DLT.Line && Col == DLT.Col;
39     }
40     bool operator!=(const DebugLocTuple &DLT) const {
41       return !(*this == DLT);
42     }
43   };
44
45   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
46   /// to index into a vector of unique debug location tuples.
47   class DebugLoc {
48     unsigned Idx;
49
50   public:
51     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
52
53     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
54     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
55
56     unsigned getIndex() const { return Idx; }
57
58     /// isUnknown - Return true if there is no debug info for the SDNode /
59     /// MachineInstr.
60     bool isUnknown() const { return Idx == ~0U; }
61
62     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
63     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
64   };
65
66   // Partially specialize DenseMapInfo for DebugLocTyple.
67   template<>  struct DenseMapInfo<DebugLocTuple> {
68     static inline DebugLocTuple getEmptyKey() {
69       return DebugLocTuple(0, ~0U, ~0U);
70     }
71     static inline DebugLocTuple getTombstoneKey() {
72       return DebugLocTuple((MDNode*)~1U, ~1U, ~1U);
73     }
74     static unsigned getHashValue(const DebugLocTuple &Val) {
75       return DenseMapInfo<MDNode*>::getHashValue(Val.CompileUnit) ^
76              DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
77              DenseMapInfo<unsigned>::getHashValue(Val.Col);
78     }
79     static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
80       return LHS.CompileUnit == RHS.CompileUnit &&
81              LHS.Line        == RHS.Line &&
82              LHS.Col         == RHS.Col;
83     }
84
85     static bool isPod() { return true; }
86   };
87
88   /// DebugLocTracker - This class tracks debug location information.
89   ///
90   struct DebugLocTracker {
91     /// DebugLocations - A vector of unique DebugLocTuple's.
92     ///
93     std::vector<DebugLocTuple> DebugLocations;
94
95     /// DebugIdMap - This maps DebugLocTuple's to indices into the
96     /// DebugLocations vector.
97     DenseMap<DebugLocTuple, unsigned> DebugIdMap;
98
99     DebugLocTracker() {}
100   };
101   
102 } // end namespace llvm
103
104 #endif /* LLVM_DEBUGLOC_H */