Switch the code generator (except the JIT) onto the new DebugLoc
[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     /// get - Get a new DebugLoc that corresponds to the specified line/col
41     /// scope/inline location.
42     static NewDebugLoc get(unsigned Line, unsigned Col,
43                            MDNode *Scope, MDNode *InlinedAt = 0);
44     
45     /// getFromDILocation - Translate the DILocation quad into a NewDebugLoc.
46     static NewDebugLoc getFromDILocation(MDNode *N);
47     
48     /// isUnknown - Return true if this is an unknown location.
49     bool isUnknown() const { return ScopeIdx == 0; }
50     
51     unsigned getLine() const {
52       return (LineCol << 8) >> 8;  // Mask out column.
53     }
54     
55     unsigned getCol() const {
56       return LineCol >> 24;
57     }
58     
59     /// getScope - This returns the scope pointer for this DebugLoc, or null if
60     /// invalid.
61     MDNode *getScope(const LLVMContext &Ctx) const;
62     
63     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
64     /// null if invalid or not present.
65     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
66     
67     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
68     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
69                               const LLVMContext &Ctx) const;
70     
71     
72     /// getAsMDNode - This method converts the compressed DebugLoc node into a
73     /// DILocation compatible MDNode.
74     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
75     
76     bool operator==(const NewDebugLoc &DL) const {
77       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
78     }
79     bool operator!=(const NewDebugLoc &DL) const { return !(*this == DL); }
80     
81     
82     
83     
84     static NewDebugLoc getUnknownLoc() { NewDebugLoc L; return L; }
85   };
86   
87   
88   typedef NewDebugLoc DebugLoc;
89
90 } // end namespace llvm
91
92 #endif /* LLVM_DEBUGLOC_H */