3b8365efceeb6571f84e4f3f8a8a48c6b685730e
[oota-llvm.git] / include / llvm / Support / DebugLoc.h
1 //===---- llvm/Support/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   class LLVMContext;
24   
25   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
26   /// and MachineInstr to compactly encode file/line/scope information for an
27   /// operation.
28   class NewDebugLoc {
29     /// LineCol - This 32-bit value encodes the line and column number for the
30     /// location, encoded as 24-bits for line and 8 bits for col.  A value of 0
31     /// for either means unknown.
32     unsigned LineCol;
33     
34     /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
35     /// decoded by LLVMContext.  0 is unknown.
36     int ScopeIdx;
37   public:
38     NewDebugLoc() : LineCol(0), ScopeIdx(0) {}  // Defaults to unknown.
39     
40     static NewDebugLoc get(unsigned Line, unsigned Col,
41                            MDNode *Scope, MDNode *InlinedAt);
42     
43     /// isUnknown - Return true if this is an unknown location.
44     bool isUnknown() const { return ScopeIdx == 0; }
45     
46     unsigned getLine() const {
47       return (LineCol << 8) >> 8;  // Mask out column.
48     }
49     
50     unsigned getCol() const {
51       return LineCol >> 24;
52     }
53     
54     /// getScope - This returns the scope pointer for this DebugLoc, or null if
55     /// invalid.
56     MDNode *getScope(const LLVMContext &Ctx) const;
57     
58     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
59     /// null if invalid or not present.
60     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
61     
62     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
63     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
64                               const LLVMContext &Ctx) const;
65     
66     
67     /// getAsMDNode - This method converts the compressed DebugLoc node into a
68     /// DILocation compatible MDNode.
69     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
70     
71     bool operator==(const NewDebugLoc &DL) const {
72       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
73     }
74     bool operator!=(const NewDebugLoc &DL) const { return !(*this == DL); }
75   };
76   
77   
78
79   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
80   /// to index into a vector of unique debug location tuples.
81   class DebugLoc {
82     unsigned Idx;
83   public:
84     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
85
86     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
87     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
88
89     unsigned getIndex() const { return Idx; }
90
91     /// isUnknown - Return true if there is no debug info for the SDNode /
92     /// MachineInstr.
93     bool isUnknown() const { return Idx == ~0U; }
94
95     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
96     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
97   };
98
99     /// DebugLocTracker - This class tracks debug location information.
100   ///
101   struct DebugLocTracker {
102     /// DebugLocations - A vector of unique DebugLocTuple's.
103     ///
104     std::vector<MDNode *> DebugLocations;
105
106     /// DebugIdMap - This maps DebugLocTuple's to indices into the
107     /// DebugLocations vector.
108     DenseMap<MDNode *, unsigned> DebugIdMap;
109
110     DebugLocTracker() {}
111   };
112   
113 } // end namespace llvm
114
115 #endif /* LLVM_DEBUGLOC_H */