1 //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a number of light weight data structures used
11 // to describe and track debug location information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
18 #include "llvm/IR/TrackingMDRef.h"
19 #include "llvm/Support/DataTypes.h"
27 /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
28 /// and MachineInstr to compactly encode file/line/scope information for an
31 TrackingMDNodeRef Loc;
35 DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
36 DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
37 DebugLoc &operator=(DebugLoc &&X) {
38 Loc = std::move(X.Loc);
41 DebugLoc &operator=(const DebugLoc &X) {
46 /// \brief Check whether this has a trivial destructor.
47 bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
49 /// get - Get a new DebugLoc that corresponds to the specified line/col
50 /// scope/inline location.
51 static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope,
52 MDNode *InlinedAt = nullptr);
54 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
55 static DebugLoc getFromDILocation(MDNode *N);
57 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
58 static DebugLoc getFromDILexicalBlock(MDNode *N);
60 /// isUnknown - Return true if this is an unknown location.
61 bool isUnknown() const { return !Loc; }
63 unsigned getLine() const;
64 unsigned getCol() const;
66 /// getScope - This returns the scope pointer for this DebugLoc, or null if
68 MDNode *getScope() const;
69 MDNode *getScope(const LLVMContext &) const { return getScope(); }
71 /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
72 /// null if invalid or not present.
73 MDNode *getInlinedAt() const;
74 MDNode *getInlinedAt(const LLVMContext &) const { return getInlinedAt(); }
76 /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
77 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const;
78 void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
79 const LLVMContext &) const {
80 return getScopeAndInlinedAt(Scope, IA);
83 /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
84 MDNode *getScopeNode() const;
85 MDNode *getScopeNode(const LLVMContext &) const { return getScopeNode(); }
87 // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
88 // number info for the function.
89 DebugLoc getFnDebugLoc() const;
90 DebugLoc getFnDebugLoc(const LLVMContext &) const {
91 return getFnDebugLoc();
94 /// getAsMDNode - This method converts the compressed DebugLoc node into a
95 /// DILocation compatible MDNode.
96 MDNode *getAsMDNode() const;
97 MDNode *getAsMDNode(LLVMContext &) const { return getAsMDNode(); }
99 bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
100 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
103 void dump(const LLVMContext &) const { dump(); }
104 /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
105 void print(raw_ostream &OS) const;
106 // void print(const LLVMContext &, raw_ostream &OS) const { print(OS); }
109 } // end namespace llvm
111 #endif /* LLVM_SUPPORT_DEBUGLOC_H */