LLVM  4.0.0
DebugLoc.h
Go to the documentation of this file.
1 //===- 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_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
17 
18 #include "llvm/IR/TrackingMDRef.h"
19 #include "llvm/Support/DataTypes.h"
20 
21 namespace llvm {
22 
23  class LLVMContext;
24  class raw_ostream;
25  class DILocation;
26 
27  /// \brief A debug info location.
28  ///
29  /// This class is a wrapper around a tracking reference to an \a DILocation
30  /// pointer.
31  ///
32  /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
33  /// one based on relatively opaque \a MDNode pointers.
34  class DebugLoc {
36 
37  public:
38  DebugLoc() = default;
39 
40  /// \brief Construct from an \a DILocation.
41  DebugLoc(const DILocation *L);
42 
43  /// \brief Construct from an \a MDNode.
44  ///
45  /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
46  /// accessors will crash. However, construction from other nodes is
47  /// supported in order to handle forward references when reading textual
48  /// IR.
49  explicit DebugLoc(const MDNode *N);
50 
51  /// \brief Get the underlying \a DILocation.
52  ///
53  /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
54  /// @{
55  DILocation *get() const;
56  operator DILocation *() const { return get(); }
57  DILocation *operator->() const { return get(); }
58  DILocation &operator*() const { return *get(); }
59  /// @}
60 
61  /// \brief Check for null.
62  ///
63  /// Check for null in a way that is safe with broken debug info. Unlike
64  /// the conversion to \c DILocation, this doesn't require that \c Loc is of
65  /// the right type. Important for cases like \a llvm::StripDebugInfo() and
66  /// \a Instruction::hasMetadata().
67  explicit operator bool() const { return Loc; }
68 
69  /// \brief Check whether this has a trivial destructor.
70  bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
71 
72  /// \brief Create a new DebugLoc.
73  ///
74  /// Create a new DebugLoc at the specified line/col and scope/inline. This
75  /// forwards to \a DILocation::get().
76  ///
77  /// If \c !Scope, returns a default-constructed \a DebugLoc.
78  ///
79  /// FIXME: Remove this. Users should use DILocation::get().
80  static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope,
81  const MDNode *InlinedAt = nullptr);
82 
83  unsigned getLine() const;
84  unsigned getCol() const;
85  MDNode *getScope() const;
86  DILocation *getInlinedAt() const;
87 
88  /// \brief Get the fully inlined-at scope for a DebugLoc.
89  ///
90  /// Gets the inlined-at scope for a DebugLoc.
91  MDNode *getInlinedAtScope() const;
92 
93  /// \brief Find the debug info location for the start of the function.
94  ///
95  /// Walk up the scope chain of given debug loc and find line number info
96  /// for the function.
97  ///
98  /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
99  /// find the subprogram, and then DILocation::get().
100  DebugLoc getFnDebugLoc() const;
101 
102  /// \brief Return \c this as a bar \a MDNode.
103  MDNode *getAsMDNode() const { return Loc; }
104 
105  bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
106  bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
107 
108  void dump() const;
109 
110  /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
111  void print(raw_ostream &OS) const;
112  };
113 
114 } // end namespace llvm
115 
116 #endif /* LLVM_SUPPORT_DEBUGLOC_H */
MachineLoop * L
MDNode * getScope() const
Definition: DebugLoc.cpp:35
DILocation * operator->() const
Definition: DebugLoc.h:57
bool operator==(const DebugLoc &DL) const
Definition: DebugLoc.h:105
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:830
DebugLoc getFnDebugLoc() const
Find the debug info location for the start of the function.
Definition: DebugLoc.cpp:49
void print(raw_ostream &OS) const
prints source location /path/to/file.exe:line:col @[inlined at]
Definition: DebugLoc.cpp:85
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: DebugLoc.h:70
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Debug location.
unsigned getLine() const
Definition: DebugLoc.cpp:25
MDNode * getInlinedAtScope() const
Get the fully inlined-at scope for a DebugLoc.
Definition: DebugLoc.cpp:45
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:40
unsigned getCol() const
Definition: DebugLoc.cpp:30
void dump() const
Definition: DebugLoc.cpp:69
bool operator!=(const DebugLoc &DL) const
Definition: DebugLoc.h:106
DebugLoc()=default
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Definition: DebugLoc.h:103
DILocation & operator*() const
Definition: DebugLoc.h:58
#define N
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44