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