0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===-- DebugLoc.cpp - Implement DebugLoc class ---------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9
|
77
|
10 #include "llvm/IR/DebugLoc.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 #include "LLVMContextImpl.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 #include "llvm/ADT/DenseMapInfo.h"
|
77
|
13 #include "llvm/IR/DebugInfo.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 // DebugLoc Implementation
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19
|
83
|
20 unsigned DebugLoc::getLine() const { return DILocation(Loc).getLineNumber(); }
|
|
21 unsigned DebugLoc::getCol() const { return DILocation(Loc).getColumnNumber(); }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22
|
83
|
23 MDNode *DebugLoc::getScope() const { return DILocation(Loc).getScope(); }
|
|
24
|
|
25 MDNode *DebugLoc::getInlinedAt() const {
|
|
26 return DILocation(Loc).getOrigLocation();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 /// Return both the Scope and the InlinedAt values.
|
83
|
30 void DebugLoc::getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const {
|
|
31 Scope = getScope();
|
|
32 IA = getInlinedAt();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34
|
83
|
35 MDNode *DebugLoc::getScopeNode() const {
|
|
36 if (MDNode *InlinedAt = getInlinedAt())
|
|
37 return DebugLoc::getFromDILocation(InlinedAt).getScopeNode();
|
|
38 return getScope();
|
77
|
39 }
|
|
40
|
83
|
41 DebugLoc DebugLoc::getFnDebugLoc() const {
|
|
42 const MDNode *Scope = getScopeNode();
|
77
|
43 DISubprogram SP = getDISubprogram(Scope);
|
83
|
44 if (SP.isSubprogram())
|
|
45 return DebugLoc::get(SP.getScopeLineNumber(), 0, SP);
|
77
|
46
|
|
47 return DebugLoc();
|
|
48 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 DebugLoc DebugLoc::get(unsigned Line, unsigned Col,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 MDNode *Scope, MDNode *InlinedAt) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 // If no scope is available, this is an unknown location.
|
83
|
53 if (!Scope)
|
|
54 return DebugLoc();
|
77
|
55
|
83
|
56 return getFromDILocation(
|
|
57 MDLocation::get(Scope->getContext(), Line, Col, Scope, InlinedAt));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 /// getAsMDNode - This method converts the compressed DebugLoc node into a
|
77
|
61 /// DILocation-compatible MDNode.
|
83
|
62 MDNode *DebugLoc::getAsMDNode() const { return Loc; }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 DebugLoc DebugLoc::getFromDILocation(MDNode *N) {
|
83
|
66 DebugLoc Loc;
|
|
67 Loc.Loc.reset(N);
|
|
68 return Loc;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 DebugLoc DebugLoc::getFromDILexicalBlock(MDNode *N) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 DILexicalBlock LexBlock(N);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 MDNode *Scope = LexBlock.getContext();
|
77
|
75 if (!Scope) return DebugLoc();
|
|
76 return get(LexBlock.getLineNumber(), LexBlock.getColumnNumber(), Scope,
|
|
77 nullptr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79
|
83
|
80 void DebugLoc::dump() const {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 #ifndef NDEBUG
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 if (!isUnknown()) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 dbgs() << getLine();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 if (getCol() != 0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 dbgs() << ',' << getCol();
|
83
|
86 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 if (!InlinedAtDL.isUnknown()) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 dbgs() << " @ ";
|
83
|
89 InlinedAtDL.dump();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 } else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 dbgs() << "\n";
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 #endif
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95
|
83
|
96 void DebugLoc::print(raw_ostream &OS) const {
|
77
|
97 if (!isUnknown()) {
|
|
98 // Print source line info.
|
83
|
99 DIScope Scope(getScope());
|
77
|
100 assert((!Scope || Scope.isScope()) &&
|
|
101 "Scope of a DebugLoc should be null or a DIScope.");
|
|
102 if (Scope)
|
|
103 OS << Scope.getFilename();
|
|
104 else
|
|
105 OS << "<unknown>";
|
|
106 OS << ':' << getLine();
|
|
107 if (getCol() != 0)
|
|
108 OS << ':' << getCol();
|
83
|
109 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt());
|
77
|
110 if (!InlinedAtDL.isUnknown()) {
|
|
111 OS << " @[ ";
|
83
|
112 InlinedAtDL.print(OS);
|
77
|
113 OS << " ]";
|
|
114 }
|
|
115 }
|
|
116 }
|