]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/include/llvm/Support/DebugLoc.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / 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_SUPPORT_DEBUGLOC_H
16 #define LLVM_SUPPORT_DEBUGLOC_H
17
18 #include "llvm/ADT/DenseMapInfo.h"
19
20 namespace llvm {
21   class MDNode;
22   class LLVMContext;
23   
24   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
25   /// and MachineInstr to compactly encode file/line/scope information for an
26   /// operation.
27   class DebugLoc {
28     friend struct DenseMapInfo<DebugLoc>;
29
30     /// getEmptyKey() - A private constructor that returns an unknown that is
31     /// not equal to the tombstone key or DebugLoc().
32     static DebugLoc getEmptyKey() {
33       DebugLoc DL;
34       DL.LineCol = 1;
35       return DL;
36     }
37
38     /// getTombstoneKey() - A private constructor that returns an unknown that
39     /// is not equal to the empty key or DebugLoc().
40     static DebugLoc getTombstoneKey() {
41       DebugLoc DL;
42       DL.LineCol = 2;
43       return DL;
44     }
45
46     /// LineCol - This 32-bit value encodes the line and column number for the
47     /// location, encoded as 24-bits for line and 8 bits for col.  A value of 0
48     /// for either means unknown.
49     unsigned LineCol;
50     
51     /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
52     /// decoded by LLVMContext.  0 is unknown.
53     int ScopeIdx;
54   public:
55     DebugLoc() : LineCol(0), ScopeIdx(0) {}  // Defaults to unknown.
56     
57     /// get - Get a new DebugLoc that corresponds to the specified line/col
58     /// scope/inline location.
59     static DebugLoc get(unsigned Line, unsigned Col,
60                         MDNode *Scope, MDNode *InlinedAt = 0);
61     
62     /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
63     static DebugLoc getFromDILocation(MDNode *N);
64
65     /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
66     static DebugLoc getFromDILexicalBlock(MDNode *N);
67
68     /// isUnknown - Return true if this is an unknown location.
69     bool isUnknown() const { return ScopeIdx == 0; }
70     
71     unsigned getLine() const {
72       return (LineCol << 8) >> 8;  // Mask out column.
73     }
74     
75     unsigned getCol() const {
76       return LineCol >> 24;
77     }
78     
79     /// getScope - This returns the scope pointer for this DebugLoc, or null if
80     /// invalid.
81     MDNode *getScope(const LLVMContext &Ctx) const;
82     
83     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
84     /// null if invalid or not present.
85     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
86     
87     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
88     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
89                               const LLVMContext &Ctx) const;
90     
91     
92     /// getAsMDNode - This method converts the compressed DebugLoc node into a
93     /// DILocation compatible MDNode.
94     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
95     
96     bool operator==(const DebugLoc &DL) const {
97       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
98     }
99     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
100
101     void dump(const LLVMContext &Ctx) const;
102   };
103
104   template <>
105   struct DenseMapInfo<DebugLoc> {
106     static DebugLoc getEmptyKey();
107     static DebugLoc getTombstoneKey();
108     static unsigned getHashValue(const DebugLoc &Key);
109     static bool isEqual(const DebugLoc &LHS, const DebugLoc &RHS);
110   };
111 } // end namespace llvm
112
113 #endif /* LLVM_DEBUGLOC_H */