blob: fd4fa6d4aff229afb00a4aefbed1b2ca41d7d111 [file] [log] [blame]
Devang Patel8b9df622011-04-12 17:40:32 +00001//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- 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 contains support for writing dwarf compile unit.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15#define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
16
17#include "DIE.h"
Devang Patel3cbee302011-04-12 22:53:02 +000018#include "llvm/Analysis/DebugInfo.h"
Devang Patel8b9df622011-04-12 17:40:32 +000019#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/OwningPtr.h"
22
23namespace llvm {
24
Devang Patel3cbee302011-04-12 22:53:02 +000025class DwarfDebug;
26class MachineLocation;
27class MachineOperand;
28class ConstantInt;
29class DbgVariable;
30
Devang Patel8b9df622011-04-12 17:40:32 +000031//===----------------------------------------------------------------------===//
32/// CompileUnit - This dwarf writer support class manages information associate
33/// with a source file.
34class CompileUnit {
35 /// ID - File identifier for source.
36 ///
37 unsigned ID;
38
39 /// Die - Compile unit debug information entry.
40 ///
41 const OwningPtr<DIE> CUDie;
42
Devang Patel3cbee302011-04-12 22:53:02 +000043 /// Asm - Target of Dwarf emission.
44 AsmPrinter *Asm;
45
46 DwarfDebug *DD;
47
Devang Patel8b9df622011-04-12 17:40:32 +000048 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
49 DIE *IndexTyDie;
50
51 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
52 /// variables to debug information entries.
53 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
54
55 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton
56 /// descriptors to debug information entries using a DIEEntry proxy.
57 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
58
59 /// Globals - A map of globally visible named entities for this unit.
60 ///
61 StringMap<DIE*> Globals;
62
63 /// GlobalTypes - A map of globally visible types for this unit.
64 ///
65 StringMap<DIE*> GlobalTypes;
66
Devang Patel3cbee302011-04-12 22:53:02 +000067 /// DIEBlocks - A list of all the DIEBlocks in use.
68 std::vector<DIEBlock *> DIEBlocks;
69
Devang Patel8b9df622011-04-12 17:40:32 +000070public:
Devang Patel5d607632011-04-12 23:09:06 +000071 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
Devang Patel3cbee302011-04-12 22:53:02 +000072 ~CompileUnit();
Devang Patel8b9df622011-04-12 17:40:32 +000073
74 // Accessors.
75 unsigned getID() const { return ID; }
76 DIE* getCUDie() const { return CUDie.get(); }
77 const StringMap<DIE*> &getGlobals() const { return Globals; }
78 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
79
80 /// hasContent - Return true if this compile unit has something to write out.
81 ///
82 bool hasContent() const { return !CUDie->getChildren().empty(); }
83
84 /// addGlobal - Add a new global entity to the compile unit.
85 ///
86 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
87
88 /// addGlobalType - Add a new global type to the compile unit.
89 ///
90 void addGlobalType(StringRef Name, DIE *Die) {
91 GlobalTypes[Name] = Die;
92 }
93
94 /// getDIE - Returns the debug information entry map slot for the
95 /// specified debug variable.
96 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
97
Devang Patel3cbee302011-04-12 22:53:02 +000098 DIEBlock *getDIEBlock() {
99 return new (DIEValueAllocator) DIEBlock();
100 }
101
Devang Patel8b9df622011-04-12 17:40:32 +0000102 /// insertDIE - Insert DIE into the map.
103 void insertDIE(const MDNode *N, DIE *D) {
104 MDNodeToDieMap.insert(std::make_pair(N, D));
105 }
106
107 /// getDIEEntry - Returns the debug information entry for the speciefied
108 /// debug variable.
109 DIEEntry *getDIEEntry(const MDNode *N) {
110 DenseMap<const MDNode *, DIEEntry *>::iterator I =
111 MDNodeToDIEEntryMap.find(N);
112 if (I == MDNodeToDIEEntryMap.end())
113 return NULL;
114 return I->second;
115 }
116
117 /// insertDIEEntry - Insert debug information entry into the map.
118 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
119 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
120 }
121
122 /// addDie - Adds or interns the DIE to the compile unit.
123 ///
124 void addDie(DIE *Buffer) {
125 this->CUDie->addChild(Buffer);
126 }
127
128 // getIndexTyDie - Get an anonymous type for index type.
129 DIE *getIndexTyDie() {
130 return IndexTyDie;
131 }
132
133 // setIndexTyDie - Set D as anonymous type for index which can be reused
134 // later.
135 void setIndexTyDie(DIE *D) {
136 IndexTyDie = D;
137 }
Devang Patel3cbee302011-04-12 22:53:02 +0000138public:
Devang Patel8b9df622011-04-12 17:40:32 +0000139
Devang Patel3cbee302011-04-12 22:53:02 +0000140 /// addUInt - Add an unsigned integer attribute data and value.
141 ///
142 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
143
144 /// addSInt - Add an signed integer attribute data and value.
145 ///
146 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
147
148 /// addString - Add a string attribute data and value.
149 ///
150 void addString(DIE *Die, unsigned Attribute, unsigned Form,
151 const StringRef Str);
152
153 /// addLabel - Add a Dwarf label attribute data and value.
154 ///
155 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
156 const MCSymbol *Label);
157
158 /// addDelta - Add a label delta attribute data and value.
159 ///
160 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
161 const MCSymbol *Hi, const MCSymbol *Lo);
162
163 /// addDIEEntry - Add a DIE attribute data and value.
164 ///
165 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
166
167 /// addBlock - Add block data.
168 ///
169 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
170
171 /// addSourceLine - Add location information to specified debug information
172 /// entry.
173 void addSourceLine(DIE *Die, DIVariable V);
174 void addSourceLine(DIE *Die, DIGlobalVariable G);
175 void addSourceLine(DIE *Die, DISubprogram SP);
176 void addSourceLine(DIE *Die, DIType Ty);
177 void addSourceLine(DIE *Die, DINameSpace NS);
178
179 /// addAddress - Add an address attribute to a die based on the location
180 /// provided.
181 void addAddress(DIE *Die, unsigned Attribute,
182 const MachineLocation &Location);
183
184 /// addRegisterAddress - Add register location entry in variable DIE.
185 bool addRegisterAddress(DIE *Die, const MachineOperand &MO);
186
187 /// addConstantValue - Add constant value entry in variable DIE.
188 bool addConstantValue(DIE *Die, const MachineOperand &MO);
189 bool addConstantValue(DIE *Die, ConstantInt *CI, bool Unsigned);
190
191 /// addConstantFPValue - Add constant value entry in variable DIE.
192 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
193
194 /// addTemplateParams - Add template parameters in buffer.
195 void addTemplateParams(DIE &Buffer, DIArray TParams);
196
Devang Patel116da2f2011-04-26 19:06:18 +0000197 /// addRegisterOp - Add register operand.
198 void addRegisterOp(DIE *TheDie, unsigned Reg);
199
200 /// addRegisterOffset - Add register offset.
201 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
202
Devang Patel3cbee302011-04-12 22:53:02 +0000203 /// addComplexAddress - Start with the address based on the location provided,
204 /// and generate the DWARF information necessary to find the actual variable
205 /// (navigating the extra location information encoded in the type) based on
206 /// the starting location. Add the DWARF information to the die.
207 ///
208 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
209 const MachineLocation &Location);
210
211 // FIXME: Should be reformulated in terms of addComplexAddress.
212 /// addBlockByrefAddress - Start with the address based on the location
213 /// provided, and generate the DWARF information necessary to find the
214 /// actual Block variable (navigating the Block struct) based on the
215 /// starting location. Add the DWARF information to the die. Obsolete,
216 /// please use addComplexAddress instead.
217 ///
218 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
219 const MachineLocation &Location);
220
Devang Patelb865d462011-04-25 23:02:17 +0000221 /// addFrameVariableAddress - Add DW_AT_location attribute for a DbgVariable
222 /// based on provided frame index.
223 void addFrameVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI);
Devang Patel3cbee302011-04-12 22:53:02 +0000224
225 /// addToContextOwner - Add Die into the list of its context owner's children.
226 void addToContextOwner(DIE *Die, DIDescriptor Context);
227
228 /// addType - Add a new type attribute to the specified entity.
229 void addType(DIE *Entity, DIType Ty);
230
231 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
232 DIE *getOrCreateNameSpace(DINameSpace NS);
233
234 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
235 /// given DIType.
236 DIE *getOrCreateTypeDIE(DIType Ty);
237
238 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
239 /// for the given DITemplateTypeParameter.
240 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
241
242 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
243 /// for the given DITemplateValueParameter.
244 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
245
246 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
247 /// information entry.
248 DIEEntry *createDIEEntry(DIE *Entry);
249
250 void addPubTypes(DISubprogram SP);
251
252 /// constructTypeDIE - Construct basic type die from DIBasicType.
253 void constructTypeDIE(DIE &Buffer,
254 DIBasicType BTy);
255
256 /// constructTypeDIE - Construct derived type die from DIDerivedType.
257 void constructTypeDIE(DIE &Buffer,
258 DIDerivedType DTy);
259
260 /// constructTypeDIE - Construct type DIE from DICompositeType.
261 void constructTypeDIE(DIE &Buffer,
262 DICompositeType CTy);
263
264 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
265 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
266
267 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
268 void constructArrayTypeDIE(DIE &Buffer,
269 DICompositeType *CTy);
270
271 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
272 DIE *constructEnumTypeDIE(DIEnumerator ETy);
273
274 /// createMemberDIE - Create new member DIE.
275 DIE *createMemberDIE(DIDerivedType DT);
276
277private:
278
279 // DIEValueAllocator - All DIEValues are allocated through this allocator.
280 BumpPtrAllocator DIEValueAllocator;
281 DIEInteger *DIEIntegerOne;
Devang Patel8b9df622011-04-12 17:40:32 +0000282};
283
284} // end llvm namespace
285#endif