1
//===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- 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
// Data structures for DWARF info entries.
12
//===----------------------------------------------------------------------===//
14
#ifndef CODEGEN_ASMPRINTER_DIE_H__
15
#define CODEGEN_ASMPRINTER_DIE_H__
17
#include "DwarfLabel.h"
18
#include "llvm/ADT/FoldingSet.h"
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/Support/Compiler.h"
21
#include "llvm/Support/Dwarf.h"
30
//===--------------------------------------------------------------------===//
31
/// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
32
/// Dwarf abbreviation.
34
/// Attribute - Dwarf attribute code.
38
/// Form - Dwarf form code.
42
DIEAbbrevData(unsigned A, unsigned F) : Attribute(A), Form(F) {}
45
unsigned getAttribute() const { return Attribute; }
46
unsigned getForm() const { return Form; }
48
/// Profile - Used to gather unique data for the abbreviation folding set.
50
void Profile(FoldingSetNodeID &ID) const;
53
//===--------------------------------------------------------------------===//
54
/// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
55
/// information object.
56
class DIEAbbrev : public FoldingSetNode {
57
/// Tag - Dwarf tag code.
61
/// Unique number for node.
65
/// ChildrenFlag - Dwarf children flag.
67
unsigned ChildrenFlag;
69
/// Data - Raw data bytes for abbreviation.
71
SmallVector<DIEAbbrevData, 8> Data;
74
DIEAbbrev(unsigned T, unsigned C) : Tag(T), ChildrenFlag(C), Data() {}
75
virtual ~DIEAbbrev() {}
78
unsigned getTag() const { return Tag; }
79
unsigned getNumber() const { return Number; }
80
unsigned getChildrenFlag() const { return ChildrenFlag; }
81
const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; }
82
void setTag(unsigned T) { Tag = T; }
83
void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
84
void setNumber(unsigned N) { Number = N; }
86
/// AddAttribute - Adds another set of attribute information to the
88
void AddAttribute(unsigned Attribute, unsigned Form) {
89
Data.push_back(DIEAbbrevData(Attribute, Form));
92
/// AddFirstAttribute - Adds a set of attribute information to the front
93
/// of the abbreviation.
94
void AddFirstAttribute(unsigned Attribute, unsigned Form) {
95
Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
98
/// Profile - Used to gather unique data for the abbreviation folding set.
100
void Profile(FoldingSetNodeID &ID) const;
102
/// Emit - Print the abbreviation using the specified asm printer.
104
void Emit(const DwarfPrinter *DP) const;
107
void print(raw_ostream &O);
112
//===--------------------------------------------------------------------===//
113
/// DIE - A structured debug information entry. Has an abbreviation which
114
/// describes it's organization.
120
/// Abbrev - Buffer for constructing abbreviation.
124
/// Offset - Offset in debug info section.
128
/// Size - Size of instance + children.
134
std::vector<DIE *> Children;
138
/// Attributes values.
140
SmallVector<DIEValue*, 32> Values;
142
// Private data for print()
143
mutable unsigned IndentCount;
145
explicit DIE(unsigned Tag)
146
: Abbrev(Tag, dwarf::DW_CHILDREN_no), Offset(0),
147
Size(0), Parent (0), IndentCount(0) {}
151
DIEAbbrev &getAbbrev() { return Abbrev; }
152
unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
153
unsigned getTag() const { return Abbrev.getTag(); }
154
unsigned getOffset() const { return Offset; }
155
unsigned getSize() const { return Size; }
156
const std::vector<DIE *> &getChildren() const { return Children; }
157
SmallVector<DIEValue*, 32> &getValues() { return Values; }
158
DIE *getParent() const { return Parent; }
159
void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
160
void setOffset(unsigned O) { Offset = O; }
161
void setSize(unsigned S) { Size = S; }
162
void setParent(DIE *P) { Parent = P; }
164
/// addValue - Add a value and attributes to a DIE.
166
void addValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
167
Abbrev.AddAttribute(Attribute, Form);
168
Values.push_back(Value);
171
/// SiblingOffset - Return the offset of the debug information entry's
173
unsigned getSiblingOffset() const { return Offset + Size; }
175
/// addSiblingOffset - Add a sibling offset field to the front of the DIE.
177
void addSiblingOffset();
179
/// addChild - Add a child to the DIE.
181
void addChild(DIE *Child) {
182
if (Child->getParent()) {
183
assert (Child->getParent() == this && "Unexpected DIE Parent!");
186
Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
187
Children.push_back(Child);
188
Child->setParent(this);
192
void print(raw_ostream &O, unsigned IncIndent = 0);
197
//===--------------------------------------------------------------------===//
198
/// DIEValue - A debug information entry value.
213
/// Type - Type of data stored in the value.
217
explicit DIEValue(unsigned T) : Type(T) {}
218
virtual ~DIEValue() {}
221
unsigned getType() const { return Type; }
223
/// EmitValue - Emit value via the Dwarf writer.
225
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const = 0;
227
/// SizeOf - Return the size of a value in bytes.
229
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const = 0;
231
// Implement isa/cast/dyncast.
232
static bool classof(const DIEValue *) { return true; }
235
virtual void print(raw_ostream &O) = 0;
240
//===--------------------------------------------------------------------===//
241
/// DIEInteger - An integer value DIE.
243
class DIEInteger : public DIEValue {
246
explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
248
/// BestForm - Choose the best form for integer.
250
static unsigned BestForm(bool IsSigned, uint64_t Int) {
252
if ((char)Int == (signed)Int) return dwarf::DW_FORM_data1;
253
if ((short)Int == (signed)Int) return dwarf::DW_FORM_data2;
254
if ((int)Int == (signed)Int) return dwarf::DW_FORM_data4;
256
if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
257
if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
258
if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
260
return dwarf::DW_FORM_data8;
263
/// EmitValue - Emit integer of appropriate size.
265
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
267
/// SizeOf - Determine size of integer value in bytes.
269
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
272
// Implement isa/cast/dyncast.
273
static bool classof(const DIEInteger *) { return true; }
274
static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
277
virtual void print(raw_ostream &O);
281
//===--------------------------------------------------------------------===//
282
/// DIEString - A string value DIE. This DIE keeps string reference only.
284
class DIEString : public DIEValue {
287
explicit DIEString(const StringRef S) : DIEValue(isString), Str(S) {}
289
/// EmitValue - Emit string value.
291
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
293
/// SizeOf - Determine size of string value in bytes.
295
virtual unsigned SizeOf(const TargetData *, unsigned /*Form*/) const {
296
return Str.size() + sizeof(char); // sizeof('\0');
299
// Implement isa/cast/dyncast.
300
static bool classof(const DIEString *) { return true; }
301
static bool classof(const DIEValue *S) { return S->getType() == isString; }
304
virtual void print(raw_ostream &O);
308
//===--------------------------------------------------------------------===//
309
/// DIEDwarfLabel - A Dwarf internal label expression DIE.
311
class DIEDwarfLabel : public DIEValue {
314
explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
316
/// EmitValue - Emit label value.
318
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
320
/// SizeOf - Determine size of label value in bytes.
322
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
324
// Implement isa/cast/dyncast.
325
static bool classof(const DIEDwarfLabel *) { return true; }
326
static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
329
virtual void print(raw_ostream &O);
333
//===--------------------------------------------------------------------===//
334
/// DIEObjectLabel - A label to an object in code or data.
336
class DIEObjectLabel : public DIEValue {
339
explicit DIEObjectLabel(const MCSymbol *S)
340
: DIEValue(isAsIsLabel), Sym(S) {}
342
/// EmitValue - Emit label value.
344
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
346
/// SizeOf - Determine size of label value in bytes.
348
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
350
// Implement isa/cast/dyncast.
351
static bool classof(const DIEObjectLabel *) { return true; }
352
static bool classof(const DIEValue *L) {
353
return L->getType() == isAsIsLabel;
357
virtual void print(raw_ostream &O);
361
//===--------------------------------------------------------------------===//
362
/// DIESectionOffset - A section offset DIE.
364
class DIESectionOffset : public DIEValue {
366
const DWLabel Section;
370
DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec,
371
bool isEH = false, bool useSet = true)
372
: DIEValue(isSectionOffset), Label(Lab), Section(Sec),
373
IsEH(isEH), UseSet(useSet) {}
375
/// EmitValue - Emit section offset.
377
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
379
/// SizeOf - Determine size of section offset value in bytes.
381
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
383
// Implement isa/cast/dyncast.
384
static bool classof(const DIESectionOffset *) { return true; }
385
static bool classof(const DIEValue *D) {
386
return D->getType() == isSectionOffset;
390
virtual void print(raw_ostream &O);
394
//===--------------------------------------------------------------------===//
395
/// DIEDelta - A simple label difference DIE.
397
class DIEDelta : public DIEValue {
398
const DWLabel LabelHi;
399
const DWLabel LabelLo;
401
DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
402
: DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
404
/// EmitValue - Emit delta value.
406
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
408
/// SizeOf - Determine size of delta value in bytes.
410
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
412
// Implement isa/cast/dyncast.
413
static bool classof(const DIEDelta *) { return true; }
414
static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
417
virtual void print(raw_ostream &O);
421
//===--------------------------------------------------------------------===//
422
/// DIEntry - A pointer to another debug information entry. An instance of
423
/// this class can also be used as a proxy for a debug information entry not
424
/// yet defined (ie. types.)
425
class DIEEntry : public DIEValue {
428
explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
430
DIE *getEntry() const { return Entry; }
431
void setEntry(DIE *E) { Entry = E; }
433
/// EmitValue - Emit debug information entry offset.
435
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
437
/// SizeOf - Determine size of debug information entry in bytes.
439
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const {
440
return sizeof(int32_t);
443
// Implement isa/cast/dyncast.
444
static bool classof(const DIEEntry *) { return true; }
445
static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
448
virtual void print(raw_ostream &O);
452
//===--------------------------------------------------------------------===//
453
/// DIEBlock - A block of values. Primarily used for location expressions.
455
class DIEBlock : public DIEValue, public DIE {
456
unsigned Size; // Size in bytes excluding size header.
459
: DIEValue(isBlock), DIE(0), Size(0) {}
460
virtual ~DIEBlock() {}
462
/// ComputeSize - calculate the size of the block.
464
unsigned ComputeSize(const TargetData *TD);
466
/// BestForm - Choose the best form for data.
468
unsigned BestForm() const {
469
if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
470
if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
471
if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
472
return dwarf::DW_FORM_block;
475
/// EmitValue - Emit block data.
477
virtual void EmitValue(DwarfPrinter *D, unsigned Form) const;
479
/// SizeOf - Determine size of block data in bytes.
481
virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
483
// Implement isa/cast/dyncast.
484
static bool classof(const DIEBlock *) { return true; }
485
static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
488
virtual void print(raw_ostream &O);
492
} // end llvm namespace