1 //===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
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 // This file contains support for writing dwarf compile unit.
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
18 #include "llvm/Analysis/DebugInfo.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/OwningPtr.h"
26 class MachineLocation
;
31 //===----------------------------------------------------------------------===//
32 /// CompileUnit - This dwarf writer support class manages information associate
33 /// with a source file.
35 /// ID - File identifier for source.
39 /// Die - Compile unit debug information entry.
41 const OwningPtr
<DIE
> CUDie
;
43 /// Asm - Target of Dwarf emission.
48 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
51 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
52 /// variables to debug information entries.
53 DenseMap
<const MDNode
*, DIE
*> MDNodeToDieMap
;
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
;
59 /// Globals - A map of globally visible named entities for this unit.
61 StringMap
<DIE
*> Globals
;
63 /// GlobalTypes - A map of globally visible types for this unit.
65 StringMap
<DIE
*> GlobalTypes
;
67 /// DIEBlocks - A list of all the DIEBlocks in use.
68 std::vector
<DIEBlock
*> DIEBlocks
;
71 CompileUnit(unsigned I
, DIE
*D
, AsmPrinter
*A
, DwarfDebug
*DW
);
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
; }
80 /// hasContent - Return true if this compile unit has something to write out.
82 bool hasContent() const { return !CUDie
->getChildren().empty(); }
84 /// addGlobal - Add a new global entity to the compile unit.
86 void addGlobal(StringRef Name
, DIE
*Die
) { Globals
[Name
] = Die
; }
88 /// addGlobalType - Add a new global type to the compile unit.
90 void addGlobalType(DIType Ty
);
92 /// getDIE - Returns the debug information entry map slot for the
93 /// specified debug variable.
94 DIE
*getDIE(const MDNode
*N
) { return MDNodeToDieMap
.lookup(N
); }
96 DIEBlock
*getDIEBlock() {
97 return new (DIEValueAllocator
) DIEBlock();
100 /// insertDIE - Insert DIE into the map.
101 void insertDIE(const MDNode
*N
, DIE
*D
) {
102 MDNodeToDieMap
.insert(std::make_pair(N
, D
));
105 /// getDIEEntry - Returns the debug information entry for the specified
107 DIEEntry
*getDIEEntry(const MDNode
*N
) {
108 DenseMap
<const MDNode
*, DIEEntry
*>::iterator I
=
109 MDNodeToDIEEntryMap
.find(N
);
110 if (I
== MDNodeToDIEEntryMap
.end())
115 /// insertDIEEntry - Insert debug information entry into the map.
116 void insertDIEEntry(const MDNode
*N
, DIEEntry
*E
) {
117 MDNodeToDIEEntryMap
.insert(std::make_pair(N
, E
));
120 /// addDie - Adds or interns the DIE to the compile unit.
122 void addDie(DIE
*Buffer
) {
123 this->CUDie
->addChild(Buffer
);
126 // getIndexTyDie - Get an anonymous type for index type.
127 DIE
*getIndexTyDie() {
131 // setIndexTyDie - Set D as anonymous type for index which can be reused
133 void setIndexTyDie(DIE
*D
) {
138 /// addUInt - Add an unsigned integer attribute data and value.
140 void addUInt(DIE
*Die
, unsigned Attribute
, unsigned Form
, uint64_t Integer
);
142 /// addSInt - Add an signed integer attribute data and value.
144 void addSInt(DIE
*Die
, unsigned Attribute
, unsigned Form
, int64_t Integer
);
146 /// addString - Add a string attribute data and value.
148 void addString(DIE
*Die
, unsigned Attribute
, unsigned Form
,
149 const StringRef Str
);
151 /// addLabel - Add a Dwarf label attribute data and value.
153 void addLabel(DIE
*Die
, unsigned Attribute
, unsigned Form
,
154 const MCSymbol
*Label
);
156 /// addDelta - Add a label delta attribute data and value.
158 void addDelta(DIE
*Die
, unsigned Attribute
, unsigned Form
,
159 const MCSymbol
*Hi
, const MCSymbol
*Lo
);
161 /// addDIEEntry - Add a DIE attribute data and value.
163 void addDIEEntry(DIE
*Die
, unsigned Attribute
, unsigned Form
, DIE
*Entry
);
165 /// addBlock - Add block data.
167 void addBlock(DIE
*Die
, unsigned Attribute
, unsigned Form
, DIEBlock
*Block
);
169 /// addSourceLine - Add location information to specified debug information
171 void addSourceLine(DIE
*Die
, DIVariable V
);
172 void addSourceLine(DIE
*Die
, DIGlobalVariable G
);
173 void addSourceLine(DIE
*Die
, DISubprogram SP
);
174 void addSourceLine(DIE
*Die
, DIType Ty
);
175 void addSourceLine(DIE
*Die
, DINameSpace NS
);
177 /// addAddress - Add an address attribute to a die based on the location
179 void addAddress(DIE
*Die
, unsigned Attribute
,
180 const MachineLocation
&Location
);
182 /// addConstantValue - Add constant value entry in variable DIE.
183 bool addConstantValue(DIE
*Die
, const MachineOperand
&MO
, DIType Ty
);
184 bool addConstantValue(DIE
*Die
, const ConstantInt
*CI
, bool Unsigned
);
186 /// addConstantFPValue - Add constant value entry in variable DIE.
187 bool addConstantFPValue(DIE
*Die
, const MachineOperand
&MO
);
189 /// addTemplateParams - Add template parameters in buffer.
190 void addTemplateParams(DIE
&Buffer
, DIArray TParams
);
192 /// addRegisterOp - Add register operand.
193 void addRegisterOp(DIE
*TheDie
, unsigned Reg
);
195 /// addRegisterOffset - Add register offset.
196 void addRegisterOffset(DIE
*TheDie
, unsigned Reg
, int64_t Offset
);
198 /// addComplexAddress - Start with the address based on the location provided,
199 /// and generate the DWARF information necessary to find the actual variable
200 /// (navigating the extra location information encoded in the type) based on
201 /// the starting location. Add the DWARF information to the die.
203 void addComplexAddress(DbgVariable
*&DV
, DIE
*Die
, unsigned Attribute
,
204 const MachineLocation
&Location
);
206 // FIXME: Should be reformulated in terms of addComplexAddress.
207 /// addBlockByrefAddress - Start with the address based on the location
208 /// provided, and generate the DWARF information necessary to find the
209 /// actual Block variable (navigating the Block struct) based on the
210 /// starting location. Add the DWARF information to the die. Obsolete,
211 /// please use addComplexAddress instead.
213 void addBlockByrefAddress(DbgVariable
*&DV
, DIE
*Die
, unsigned Attribute
,
214 const MachineLocation
&Location
);
216 /// addVariableAddress - Add DW_AT_location attribute for a
217 /// DbgVariable based on provided MachineLocation.
218 void addVariableAddress(DbgVariable
*&DV
, DIE
*Die
, MachineLocation Location
);
220 /// addToContextOwner - Add Die into the list of its context owner's children.
221 void addToContextOwner(DIE
*Die
, DIDescriptor Context
);
223 /// addType - Add a new type attribute to the specified entity.
224 void addType(DIE
*Entity
, DIType Ty
);
226 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
227 DIE
*getOrCreateNameSpace(DINameSpace NS
);
229 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
231 DIE
*getOrCreateTypeDIE(DIType Ty
);
233 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
234 /// for the given DITemplateTypeParameter.
235 DIE
*getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP
);
237 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
238 /// for the given DITemplateValueParameter.
239 DIE
*getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP
);
241 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
242 /// information entry.
243 DIEEntry
*createDIEEntry(DIE
*Entry
);
245 void addPubTypes(DISubprogram SP
);
247 /// constructTypeDIE - Construct basic type die from DIBasicType.
248 void constructTypeDIE(DIE
&Buffer
,
251 /// constructTypeDIE - Construct derived type die from DIDerivedType.
252 void constructTypeDIE(DIE
&Buffer
,
255 /// constructTypeDIE - Construct type DIE from DICompositeType.
256 void constructTypeDIE(DIE
&Buffer
,
257 DICompositeType CTy
);
259 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
260 void constructSubrangeDIE(DIE
&Buffer
, DISubrange SR
, DIE
*IndexTy
);
262 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
263 void constructArrayTypeDIE(DIE
&Buffer
,
264 DICompositeType
*CTy
);
266 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
267 DIE
*constructEnumTypeDIE(DIEnumerator ETy
);
269 /// createMemberDIE - Create new member DIE.
270 DIE
*createMemberDIE(DIDerivedType DT
);
274 // DIEValueAllocator - All DIEValues are allocated through this allocator.
275 BumpPtrAllocator DIEValueAllocator
;
276 DIEInteger
*DIEIntegerOne
;
279 } // end llvm namespace