Revert "System: Add SwapByteOrder and update Support/MathExtras.h to use it."
[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 namespace llvm {
19   class MDNode;
20   class LLVMContext;
21   
22   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
23   /// and MachineInstr to compactly encode file/line/scope information for an
24   /// operation.
25   class DebugLoc {
26     /// LineCol - This 32-bit value encodes the line and column number for the
27     /// location, encoded as 24-bits for line and 8 bits for col.  A value of 0
28     /// for either means unknown.
29     unsigned LineCol;
30     
31     /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information,
32     /// decoded by LLVMContext.  0 is unknown.
33     int ScopeIdx;
34   public:
35     DebugLoc() : LineCol(0), ScopeIdx(0) {}  // Defaults to unknown.
36     
37     /// get - Get a new DebugLoc that corresponds to the specified line/col
38     /// scope/inline location.
39     static DebugLoc get(unsigned Line, unsigned Col,
40                         MDNode *Scope, MDNode *InlinedAt = 0);
41     
42     /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
43     static DebugLoc getFromDILocation(MDNode *N);
44     
45     /// isUnknown - Return true if this is an unknown location.
46     bool isUnknown() const { return ScopeIdx == 0; }
47     
48     unsigned getLine() const {
49       return (LineCol << 8) >> 8;  // Mask out column.
50     }
51     
52     unsigned getCol() const {
53       return LineCol >> 24;
54     }
55     
56     /// getScope - This returns the scope pointer for this DebugLoc, or null if
57     /// invalid.
58     MDNode *getScope(const LLVMContext &Ctx) const;
59     
60     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
61     /// null if invalid or not present.
62     MDNode *getInlinedAt(const LLVMContext &Ctx) const;
63     
64     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
65     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
66                               const LLVMContext &Ctx) const;
67     
68     
69     /// getAsMDNode - This method converts the compressed DebugLoc node into a
70     /// DILocation compatible MDNode.
71     MDNode *getAsMDNode(const LLVMContext &Ctx) const;
72     
73     bool operator==(const DebugLoc &DL) const {
74       return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx;
75     }
76     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
77   };
78 } // end namespace llvm
79
80 #endif /* LLVM_DEBUGLOC_H */