[AArch64] Crypto requires FP.
[llvm-core.git] / lib / IR / DebugLoc.cpp
blobf31074a7ad44251ee87fe9023cbb28ace2e5a5d6
1 //===-- DebugLoc.cpp - Implement DebugLoc class ---------------------------===//
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 //===----------------------------------------------------------------------===//
10 #include "llvm/IR/DebugLoc.h"
11 #include "LLVMContextImpl.h"
12 #include "llvm/IR/DebugInfo.h"
13 using namespace llvm;
15 //===----------------------------------------------------------------------===//
16 // DebugLoc Implementation
17 //===----------------------------------------------------------------------===//
18 DebugLoc::DebugLoc(const DILocation *L) : Loc(const_cast<DILocation *>(L)) {}
19 DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast<MDNode *>(L)) {}
21 DILocation *DebugLoc::get() const {
22 return cast_or_null<DILocation>(Loc.get());
25 unsigned DebugLoc::getLine() const {
26 assert(get() && "Expected valid DebugLoc");
27 return get()->getLine();
30 unsigned DebugLoc::getCol() const {
31 assert(get() && "Expected valid DebugLoc");
32 return get()->getColumn();
35 MDNode *DebugLoc::getScope() const {
36 assert(get() && "Expected valid DebugLoc");
37 return get()->getScope();
40 DILocation *DebugLoc::getInlinedAt() const {
41 assert(get() && "Expected valid DebugLoc");
42 return get()->getInlinedAt();
45 MDNode *DebugLoc::getInlinedAtScope() const {
46 return cast<DILocation>(Loc)->getInlinedAtScope();
49 DebugLoc DebugLoc::getFnDebugLoc() const {
50 // FIXME: Add a method on \a DILocation that does this work.
51 const MDNode *Scope = getInlinedAtScope();
52 if (auto *SP = getDISubprogram(Scope))
53 return DebugLoc::get(SP->getScopeLine(), 0, SP);
55 return DebugLoc();
58 DebugLoc DebugLoc::get(unsigned Line, unsigned Col, const MDNode *Scope,
59 const MDNode *InlinedAt) {
60 // If no scope is available, this is an unknown location.
61 if (!Scope)
62 return DebugLoc();
64 return DILocation::get(Scope->getContext(), Line, Col,
65 const_cast<MDNode *>(Scope),
66 const_cast<MDNode *>(InlinedAt));
69 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
70 LLVM_DUMP_METHOD void DebugLoc::dump() const {
71 if (!Loc)
72 return;
74 dbgs() << getLine();
75 if (getCol() != 0)
76 dbgs() << ',' << getCol();
77 if (DebugLoc InlinedAtDL = DebugLoc(getInlinedAt())) {
78 dbgs() << " @ ";
79 InlinedAtDL.dump();
80 } else
81 dbgs() << "\n";
83 #endif
85 void DebugLoc::print(raw_ostream &OS) const {
86 if (!Loc)
87 return;
89 // Print source line info.
90 auto *Scope = cast<DIScope>(getScope());
91 OS << Scope->getFilename();
92 OS << ':' << getLine();
93 if (getCol() != 0)
94 OS << ':' << getCol();
96 if (DebugLoc InlinedAtDL = getInlinedAt()) {
97 OS << " @[ ";
98 InlinedAtDL.print(OS);
99 OS << " ]";