LLVM API Documentation

DebugLoc.h
Go to the documentation of this file.
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 #include "llvm/IR/TrackingMDRef.h"
00020 
00021 namespace llvm {
00022 
00023   class LLVMContext;
00024   class raw_ostream;
00025   class MDNode;
00026 
00027   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
00028   /// and MachineInstr to compactly encode file/line/scope information for an
00029   /// operation.
00030   class DebugLoc {
00031     TrackingMDNodeRef Loc;
00032 
00033   public:
00034     DebugLoc() {}
00035     DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
00036     DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
00037     DebugLoc &operator=(DebugLoc &&X) {
00038       Loc = std::move(X.Loc);
00039       return *this;
00040     }
00041     DebugLoc &operator=(const DebugLoc &X) {
00042       Loc = X.Loc;
00043       return *this;
00044     }
00045 
00046     /// \brief Check whether this has a trivial destructor.
00047     bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
00048 
00049     /// get - Get a new DebugLoc that corresponds to the specified line/col
00050     /// scope/inline location.
00051     static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope,
00052                         MDNode *InlinedAt = nullptr);
00053 
00054     /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
00055     static DebugLoc getFromDILocation(MDNode *N);
00056 
00057     /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
00058     static DebugLoc getFromDILexicalBlock(MDNode *N);
00059 
00060     /// isUnknown - Return true if this is an unknown location.
00061     bool isUnknown() const { return !Loc; }
00062 
00063     unsigned getLine() const;
00064     unsigned getCol() const;
00065 
00066     /// getScope - This returns the scope pointer for this DebugLoc, or null if
00067     /// invalid.
00068     MDNode *getScope() const;
00069     MDNode *getScope(const LLVMContext &) const { return getScope(); }
00070 
00071     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
00072     /// null if invalid or not present.
00073     MDNode *getInlinedAt() const;
00074     MDNode *getInlinedAt(const LLVMContext &) const { return getInlinedAt(); }
00075 
00076     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
00077     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const;
00078     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
00079                               const LLVMContext &) const {
00080       return getScopeAndInlinedAt(Scope, IA);
00081     }
00082 
00083     /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
00084     MDNode *getScopeNode() const;
00085     MDNode *getScopeNode(const LLVMContext &) const { return getScopeNode(); }
00086 
00087     // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
00088     // number info for the function.
00089     DebugLoc getFnDebugLoc() const;
00090     DebugLoc getFnDebugLoc(const LLVMContext &) const {
00091       return getFnDebugLoc();
00092     }
00093 
00094     /// getAsMDNode - This method converts the compressed DebugLoc node into a
00095     /// DILocation compatible MDNode.
00096     MDNode *getAsMDNode() const;
00097     MDNode *getAsMDNode(LLVMContext &) const { return getAsMDNode(); }
00098 
00099     bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
00100     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
00101 
00102     void dump() const;
00103     void dump(const LLVMContext &) const { dump(); }
00104     /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
00105     void print(raw_ostream &OS) const;
00106     void print(const LLVMContext &, raw_ostream &OS) const { print(OS); }
00107   };
00108 
00109 } // end namespace llvm
00110 
00111 #endif /* LLVM_SUPPORT_DEBUGLOC_H */