LLVM API Documentation
00001 //===---- llvm/Support/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_SUPPORT_DEBUGLOC_H 00016 #define LLVM_SUPPORT_DEBUGLOC_H 00017 00018 namespace llvm { 00019 template <typename T> struct DenseMapInfo; 00020 class MDNode; 00021 class LLVMContext; 00022 00023 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode, 00024 /// and MachineInstr to compactly encode file/line/scope information for an 00025 /// operation. 00026 class DebugLoc { 00027 friend struct DenseMapInfo<DebugLoc>; 00028 00029 /// getEmptyKey() - A private constructor that returns an unknown that is 00030 /// not equal to the tombstone key or DebugLoc(). 00031 static DebugLoc getEmptyKey() { 00032 DebugLoc DL; 00033 DL.LineCol = 1; 00034 return DL; 00035 } 00036 00037 /// getTombstoneKey() - A private constructor that returns an unknown that 00038 /// is not equal to the empty key or DebugLoc(). 00039 static DebugLoc getTombstoneKey() { 00040 DebugLoc DL; 00041 DL.LineCol = 2; 00042 return DL; 00043 } 00044 00045 /// LineCol - This 32-bit value encodes the line and column number for the 00046 /// location, encoded as 24-bits for line and 8 bits for col. A value of 0 00047 /// for either means unknown. 00048 unsigned LineCol; 00049 00050 /// ScopeIdx - This is an opaque ID# for Scope/InlinedAt information, 00051 /// decoded by LLVMContext. 0 is unknown. 00052 int ScopeIdx; 00053 public: 00054 DebugLoc() : LineCol(0), ScopeIdx(0) {} // Defaults to unknown. 00055 00056 /// get - Get a new DebugLoc that corresponds to the specified line/col 00057 /// scope/inline location. 00058 static DebugLoc get(unsigned Line, unsigned Col, 00059 MDNode *Scope, MDNode *InlinedAt = 0); 00060 00061 /// getFromDILocation - Translate the DILocation quad into a DebugLoc. 00062 static DebugLoc getFromDILocation(MDNode *N); 00063 00064 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc. 00065 static DebugLoc getFromDILexicalBlock(MDNode *N); 00066 00067 /// isUnknown - Return true if this is an unknown location. 00068 bool isUnknown() const { return ScopeIdx == 0; } 00069 00070 unsigned getLine() const { 00071 return (LineCol << 8) >> 8; // Mask out column. 00072 } 00073 00074 unsigned getCol() const { 00075 return LineCol >> 24; 00076 } 00077 00078 /// getScope - This returns the scope pointer for this DebugLoc, or null if 00079 /// invalid. 00080 MDNode *getScope(const LLVMContext &Ctx) const; 00081 00082 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or 00083 /// null if invalid or not present. 00084 MDNode *getInlinedAt(const LLVMContext &Ctx) const; 00085 00086 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values. 00087 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA, 00088 const LLVMContext &Ctx) const; 00089 00090 00091 /// getAsMDNode - This method converts the compressed DebugLoc node into a 00092 /// DILocation compatible MDNode. 00093 MDNode *getAsMDNode(const LLVMContext &Ctx) const; 00094 00095 bool operator==(const DebugLoc &DL) const { 00096 return LineCol == DL.LineCol && ScopeIdx == DL.ScopeIdx; 00097 } 00098 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } 00099 00100 void dump(const LLVMContext &Ctx) const; 00101 }; 00102 00103 template <> 00104 struct DenseMapInfo<DebugLoc> { 00105 static DebugLoc getEmptyKey() { return DebugLoc::getEmptyKey(); } 00106 static DebugLoc getTombstoneKey() { return DebugLoc::getTombstoneKey(); } 00107 static unsigned getHashValue(const DebugLoc &Key); 00108 static bool isEqual(DebugLoc LHS, DebugLoc RHS) { return LHS == RHS; } 00109 }; 00110 } // end namespace llvm 00111 00112 #endif /* LLVM_SUPPORT_DEBUGLOC_H */