LLVM API Documentation
00001 //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a number of light weight data structures used 00011 // to describe and track debug location information. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_IR_DEBUGLOC_H 00016 #define LLVM_IR_DEBUGLOC_H 00017 00018 #include "llvm/Support/DataTypes.h" 00019 00020 namespace llvm { 00021 template <typename T> struct DenseMapInfo; 00022 class MDNode; 00023 class LLVMContext; 00024 class raw_ostream; 00025 00026 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode, 00027 /// and MachineInstr to compactly encode file/line/scope information for an 00028 /// operation. 00029 class DebugLoc { 00030 friend struct DenseMapInfo<DebugLoc>; 00031 00032 /// getEmptyKey() - A private constructor that returns an unknown that is 00033 /// not equal to the tombstone key or DebugLoc(). 00034 static DebugLoc getEmptyKey() { 00035 DebugLoc DL; 00036 DL.LineCol = 1; 00037 return DL; 00038 } 00039 00040 /// getTombstoneKey() - A private constructor that returns an unknown that 00041 /// is not equal to the empty key or DebugLoc(). 00042 static DebugLoc getTombstoneKey() { 00043 DebugLoc DL; 00044 DL.LineCol = 2; 00045 return DL; 00046 } 00047 00048 /// LineCol - This 32-bit value encodes the line and column number for the 00049 /// location, encoded as 24-bits for line and 8 bits for col. A value of 0 00050 /// for either means unknown. 00051 uint32_t LineCol; 00052 00053 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information, 00054 /// decoded by LLVMContext. 0 is unknown. 00055 int ScopeIdx; 00056 public: 00057 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown. 00058 00059 /// get - Get a new DebugLoc that corresponds to the specified line/col 00060 /// scope/inline location. 00061 static DebugLoc get(unsigned Line, unsigned Col, 00062 MDNode *Scope, MDNode *InlinedAt = nullptr); 00063 00064 /// getFromDILocation - Translate the DILocation quad into a DebugLoc. 00065 static DebugLoc getFromDILocation(MDNode *N); 00066 00067 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc. 00068 static DebugLoc getFromDILexicalBlock(MDNode *N); 00069 00070 /// isUnknown - Return true if this is an unknown location. 00071 bool isUnknown() const { return ScopeIdx == 0; } 00072 00073 unsigned getLine() const { 00074 return (LineCol << 8) >> 8; // Mask out column. 00075 } 00076 00077 unsigned getCol() const { 00078 return LineCol >> 24; 00079 } 00080 00081 /// getScope - This returns the scope pointer for this DebugLoc, or null if 00082 /// invalid. 00083 MDNode *getScope(const LLVMContext &Ctx) const; 00084 00085 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or 00086 /// null if invalid or not present. 00087 MDNode *getInlinedAt(const LLVMContext &Ctx) const; 00088 00089 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values. 00090 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA, 00091 const LLVMContext &Ctx) const; 00092 00093 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid. 00094 MDNode *getScopeNode(const LLVMContext &Ctx) const; 00095 00096 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line 00097 // number info for the function. 00098 DebugLoc getFnDebugLoc(const LLVMContext &Ctx) const; 00099 00100 /// getAsMDNode - This method converts the compressed DebugLoc node into a 00101 /// DILocation compatible MDNode. 00102 MDNode *getAsMDNode(const LLVMContext &Ctx) const; 00103 00104 bool operator==(const DebugLoc &DL) const { 00105 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx; 00106 } 00107 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } 00108 00109 void dump(const LLVMContext &Ctx) const; 00110 /// \brief prints source location /path/to/file.exe:line:col @[inlined at] 00111 void print(const LLVMContext &Ctx, raw_ostream &OS) const; 00112 }; 00113 00114 template <> 00115 struct DenseMapInfo<DebugLoc> { 00116 static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); } 00117 static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); } 00118 static unsigned getHashValue(const DebugLoc &Key); 00119 static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; } 00120 }; 00121 } // end namespace llvm 00122 00123 #endif /* LLVM_SUPPORT_DEBUGLOC_H */