1 //===-- DebugLoc.cpp - Implement DebugLoc class ---------------------------===//
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 #include "llvm/IR/DebugLoc.h"
11 #include "LLVMContextImpl.h"
12 #include "llvm/ADT/DenseMapInfo.h"
13 #include "llvm/IR/DebugInfo.h"
16 //===----------------------------------------------------------------------===//
17 // DebugLoc Implementation
18 //===----------------------------------------------------------------------===//
19 DebugLoc::DebugLoc(const DILocation
*L
) : Loc(const_cast<DILocation
*>(L
)) {}
20 DebugLoc::DebugLoc(const MDNode
*L
) : Loc(const_cast<MDNode
*>(L
)) {}
22 DILocation
*DebugLoc::get() const {
23 return cast_or_null
<DILocation
>(Loc
.get());
26 unsigned DebugLoc::getLine() const {
27 assert(get() && "Expected valid DebugLoc");
28 return get()->getLine();
31 unsigned DebugLoc::getCol() const {
32 assert(get() && "Expected valid DebugLoc");
33 return get()->getColumn();
36 MDNode
*DebugLoc::getScope() const {
37 assert(get() && "Expected valid DebugLoc");
38 return get()->getScope();
41 DILocation
*DebugLoc::getInlinedAt() const {
42 assert(get() && "Expected valid DebugLoc");
43 return get()->getInlinedAt();
46 MDNode
*DebugLoc::getInlinedAtScope() const {
47 return cast
<DILocation
>(Loc
)->getInlinedAtScope();
50 DebugLoc
DebugLoc::getFnDebugLoc() const {
51 // FIXME: Add a method on \a DILocation that does this work.
52 const MDNode
*Scope
= getInlinedAtScope();
53 if (auto *SP
= getDISubprogram(Scope
))
54 return DebugLoc::get(SP
->getScopeLine(), 0, SP
);
59 DebugLoc
DebugLoc::get(unsigned Line
, unsigned Col
, const MDNode
*Scope
,
60 const MDNode
*InlinedAt
) {
61 // If no scope is available, this is an unknown location.
65 return DILocation::get(Scope
->getContext(), Line
, Col
,
66 const_cast<MDNode
*>(Scope
),
67 const_cast<MDNode
*>(InlinedAt
));
70 void DebugLoc::dump() const {
77 dbgs() << ',' << getCol();
78 if (DebugLoc InlinedAtDL
= DebugLoc(getInlinedAt())) {
86 void DebugLoc::print(raw_ostream
&OS
) const {
90 // Print source line info.
91 auto *Scope
= cast
<DIScope
>(getScope());
92 OS
<< Scope
->getFilename();
93 OS
<< ':' << getLine();
95 OS
<< ':' << getCol();
97 if (DebugLoc InlinedAtDL
= getInlinedAt()) {
99 InlinedAtDL
.print(OS
);