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