300d7401cec7052679acdcd63bf41a0ec3be6f0f
[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     /// getFromDILocation - Translate the DILocation quad into a NewDebugLoc.
44     static NewDebugLoc getFromDILocation(MDNode *N);
45     
46     /// isUnknown - Return true if this is an unknown location.
47     bool isUnknown() const { return ScopeIdx == 0; }
48     
49     unsigned getLine() const {
50       return (LineCol << 8) >> 8;  // Mask out column.
51     }
52     
53     unsigned getCol() const {
54       return LineCol >> 24;
55     }
56     
57     /// getScope - This returns the scope pointer for this DebugLoc, or null if
58     /// invalid.
59     MDNode *getScope(const LLVMContext &Ctx) const;
60     
61     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
62     /// null if invalid or not present.
63     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
64     
65     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
66     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
67                               const LLVMContext &Ctx) const;
68     
69     
70     /// getAsMDNode - This method converts the compressed DebugLoc node into a
71     /// DILocation compatible MDNode.
72     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
73     
74     bool operator==(const NewDebugLoc &DL) const {
75       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
76     }
77     bool operator!=(const NewDebugLoc &DL) const { return !(*this == DL); }
78   };
79   
80   
81
82   /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
83   /// to index into a vector of unique debug location tuples.
84   class DebugLoc {
85     unsigned Idx;
86   public:
87     DebugLoc() : Idx(~0U) {}  // Defaults to invalid.
88
89     static DebugLoc getUnknownLoc()   { DebugLoc L; L.Idx = ~0U; return L; }
90     static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
91
92     unsigned getIndex() const { return Idx; }
93
94     /// isUnknown - Return true if there is no debug info for the SDNode /
95     /// MachineInstr.
96     bool isUnknown() const { return Idx == ~0U; }
97
98     bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; }
99     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
100   };
101
102   /// DebugLocTracker - This class tracks debug location information.
103   ///
104   struct DebugLocTracker {
105     /// DebugLocations - A vector of unique DebugLocTuple's.
106     ///
107     std::vector<MDNode *> DebugLocations;
108
109     /// DebugIdMap - This maps DebugLocTuple's to indices into the
110     /// DebugLocations vector.
111     DenseMap<MDNode *, unsigned> DebugIdMap;
112
113     DebugLocTracker() {}
114   };
115   
116 } // end namespace llvm
117
118 #endif /* LLVM_DEBUGLOC_H */