blob: 69444285f4ec4691429c388174260f784187f557 [file] [log] [blame]
Bill Wendling88423ee2009-05-15 00:11:17 +00001//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
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// Data structures for DWARF info entries.
Eric Christopherff348452013-01-07 22:40:45 +000011//
Bill Wendling88423ee2009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
14#include "DIE.h"
Manman Ren0e6783f2013-07-02 23:40:10 +000015#include "DwarfDebug.h"
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +000016#include "llvm/ADT/Twine.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000017#include "llvm/CodeGen/AsmPrinter.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000018#include "llvm/IR/DataLayout.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattnerbcb83e52010-01-20 07:41:15 +000020#include "llvm/MC/MCStreamer.h"
Chris Lattner858431d2010-01-16 18:50:28 +000021#include "llvm/MC/MCSymbol.h"
Benjamin Kramer345ef342010-03-31 19:34:01 +000022#include "llvm/Support/Allocator.h"
David Greene0c8b6e62009-12-24 00:27:55 +000023#include "llvm/Support/Debug.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000025#include "llvm/Support/Format.h"
Chris Lattner0ad9c912010-01-22 22:09:00 +000026#include "llvm/Support/FormattedStream.h"
Eric Christopher3dee5752013-07-26 17:02:41 +000027#include "llvm/Support/MD5.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000028using namespace llvm;
29
30//===----------------------------------------------------------------------===//
31// DIEAbbrevData Implementation
32//===----------------------------------------------------------------------===//
33
34/// Profile - Used to gather unique data for the abbreviation folding set.
35///
36void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
Reid Kleckner82e7eda2013-10-21 19:18:31 +000037 // Explicitly cast to an integer type for which FoldingSetNodeID has
38 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
39 ID.AddInteger(unsigned(Attribute));
40 ID.AddInteger(unsigned(Form));
Bill Wendling88423ee2009-05-15 00:11:17 +000041}
42
43//===----------------------------------------------------------------------===//
44// DIEAbbrev Implementation
45//===----------------------------------------------------------------------===//
46
47/// Profile - Used to gather unique data for the abbreviation folding set.
48///
49void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Kleckner82e7eda2013-10-21 19:18:31 +000050 ID.AddInteger(unsigned(Tag));
Bill Wendling88423ee2009-05-15 00:11:17 +000051 ID.AddInteger(ChildrenFlag);
52
53 // For each attribute description.
54 for (unsigned i = 0, N = Data.size(); i < N; ++i)
55 Data[i].Profile(ID);
56}
57
58/// Emit - Print the abbreviation using the specified asm printer.
59///
Chris Lattnerd38fee82010-04-05 00:13:49 +000060void DIEAbbrev::Emit(AsmPrinter *AP) const {
Bill Wendling88423ee2009-05-15 00:11:17 +000061 // Emit its Dwarf tag type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000062 AP->EmitULEB128(Tag, dwarf::TagString(Tag));
Bill Wendling88423ee2009-05-15 00:11:17 +000063
64 // Emit whether it has children DIEs.
Chris Lattnerd38fee82010-04-05 00:13:49 +000065 AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
Bill Wendling88423ee2009-05-15 00:11:17 +000066
67 // For each attribute description.
68 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
69 const DIEAbbrevData &AttrData = Data[i];
70
71 // Emit attribute type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000072 AP->EmitULEB128(AttrData.getAttribute(),
Nick Lewycky3bbb6f72011-07-29 03:49:23 +000073 dwarf::AttributeString(AttrData.getAttribute()));
Bill Wendling88423ee2009-05-15 00:11:17 +000074
75 // Emit form type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000076 AP->EmitULEB128(AttrData.getForm(),
77 dwarf::FormEncodingString(AttrData.getForm()));
Bill Wendling88423ee2009-05-15 00:11:17 +000078 }
79
80 // Mark end of abbreviation.
Chris Lattnerd38fee82010-04-05 00:13:49 +000081 AP->EmitULEB128(0, "EOM(1)");
82 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling88423ee2009-05-15 00:11:17 +000083}
84
85#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +000086void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling88423ee2009-05-15 00:11:17 +000087 O << "Abbreviation @"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000088 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling88423ee2009-05-15 00:11:17 +000089 << " "
90 << dwarf::TagString(Tag)
91 << " "
92 << dwarf::ChildrenString(ChildrenFlag)
Chris Lattnerb01acfa2009-08-23 01:01:17 +000093 << '\n';
Bill Wendling88423ee2009-05-15 00:11:17 +000094
95 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
96 O << " "
97 << dwarf::AttributeString(Data[i].getAttribute())
98 << " "
99 << dwarf::FormEncodingString(Data[i].getForm())
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000100 << '\n';
Bill Wendling88423ee2009-05-15 00:11:17 +0000101 }
102}
David Greene0c8b6e62009-12-24 00:27:55 +0000103void DIEAbbrev::dump() { print(dbgs()); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000104#endif
105
106//===----------------------------------------------------------------------===//
107// DIE Implementation
108//===----------------------------------------------------------------------===//
109
110DIE::~DIE() {
111 for (unsigned i = 0, N = Children.size(); i < N; ++i)
112 delete Children[i];
113}
114
Manman Ren3eabc2a2013-10-29 22:57:10 +0000115/// Climb up the parent chain to get the compile unit DIE to which this DIE
116/// belongs.
117const DIE *DIE::getCompileUnit() const {
Manman Renb8b70e12013-10-31 17:54:35 +0000118 const DIE *Cu = getCompileUnitOrNull();
119 assert(Cu && "We should not have orphaned DIEs.");
120 return Cu;
121}
122
123/// Climb up the parent chain to get the compile unit DIE this DIE belongs
124/// to. Return NULL if DIE is not added to an owner yet.
125const DIE *DIE::getCompileUnitOrNull() const {
Manman Ren3eabc2a2013-10-29 22:57:10 +0000126 const DIE *p = this;
127 while (p) {
128 if (p->getTag() == dwarf::DW_TAG_compile_unit)
129 return p;
130 p = p->getParent();
131 }
Manman Renb8b70e12013-10-31 17:54:35 +0000132 return NULL;
Manman Ren3eabc2a2013-10-29 22:57:10 +0000133}
134
Eric Christopher31667622013-08-08 01:41:00 +0000135DIEValue *DIE::findAttribute(uint16_t Attribute) {
Eric Christopherb7669132013-08-07 01:18:33 +0000136 const SmallVectorImpl<DIEValue *> &Values = getValues();
137 const DIEAbbrev &Abbrevs = getAbbrev();
138
139 // Iterate through all the attributes until we find the one we're
140 // looking for, if we can't find it return NULL.
141 for (size_t i = 0; i < Values.size(); ++i)
142 if (Abbrevs.getData()[i].getAttribute() == Attribute)
143 return Values[i];
144 return NULL;
145}
146
Bill Wendling88423ee2009-05-15 00:11:17 +0000147#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000148void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000149 const std::string Indent(IndentCount, ' ');
150 bool isBlock = Abbrev.getTag() == 0;
151
152 if (!isBlock) {
153 O << Indent
154 << "Die: "
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000155 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling88423ee2009-05-15 00:11:17 +0000156 << ", Offset: " << Offset
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000157 << ", Size: " << Size << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000158
159 O << Indent
160 << dwarf::TagString(Abbrev.getTag())
161 << " "
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000162 << dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000163 } else {
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000164 O << "Size: " << Size << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000165 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000166
Eric Christopherf7cef702013-03-29 23:34:06 +0000167 const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
Bill Wendling88423ee2009-05-15 00:11:17 +0000168
169 IndentCount += 2;
170 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
171 O << Indent;
172
173 if (!isBlock)
174 O << dwarf::AttributeString(Data[i].getAttribute());
175 else
176 O << "Blk[" << i << "]";
177
178 O << " "
179 << dwarf::FormEncodingString(Data[i].getForm())
180 << " ";
181 Values[i]->print(O);
182 O << "\n";
183 }
184 IndentCount -= 2;
185
186 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Eric Christopher30cb8362013-05-06 17:50:50 +0000187 Children[j]->print(O, IndentCount+4);
Bill Wendling88423ee2009-05-15 00:11:17 +0000188 }
189
190 if (!isBlock) O << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000191}
192
193void DIE::dump() {
David Greene0c8b6e62009-12-24 00:27:55 +0000194 print(dbgs());
Bill Wendling88423ee2009-05-15 00:11:17 +0000195}
196#endif
197
David Blaikie2d24e2a2011-12-20 02:50:00 +0000198void DIEValue::anchor() { }
Bill Wendling88423ee2009-05-15 00:11:17 +0000199
200#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000201void DIEValue::dump() const {
David Greene0c8b6e62009-12-24 00:27:55 +0000202 print(dbgs());
Bill Wendling88423ee2009-05-15 00:11:17 +0000203}
204#endif
205
206//===----------------------------------------------------------------------===//
207// DIEInteger Implementation
208//===----------------------------------------------------------------------===//
209
210/// EmitValue - Emit integer of appropriate size.
211///
David Blaikie770530b2013-10-21 17:28:37 +0000212void DIEInteger::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000213 unsigned Size = ~0U;
Bill Wendling88423ee2009-05-15 00:11:17 +0000214 switch (Form) {
Eric Christopher873cf0a2012-08-24 01:14:27 +0000215 case dwarf::DW_FORM_flag_present:
216 // Emit something to keep the lines and comments in sync.
217 // FIXME: Is there a better way to do this?
218 if (Asm->OutStreamer.hasRawTextSupport())
David Blaikie5759c3a2013-10-24 22:43:10 +0000219 Asm->OutStreamer.EmitRawText("");
Eric Christopher873cf0a2012-08-24 01:14:27 +0000220 return;
Bill Wendling88423ee2009-05-15 00:11:17 +0000221 case dwarf::DW_FORM_flag: // Fall thru
222 case dwarf::DW_FORM_ref1: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000223 case dwarf::DW_FORM_data1: Size = 1; break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000224 case dwarf::DW_FORM_ref2: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000225 case dwarf::DW_FORM_data2: Size = 2; break;
Eric Christopherd96c72a2013-01-17 02:59:59 +0000226 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling88423ee2009-05-15 00:11:17 +0000227 case dwarf::DW_FORM_ref4: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000228 case dwarf::DW_FORM_data4: Size = 4; break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000229 case dwarf::DW_FORM_ref8: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000230 case dwarf::DW_FORM_data8: Size = 8; break;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000231 case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000232 case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000233 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
234 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
Eric Christopher4984e012012-09-10 23:34:03 +0000235 case dwarf::DW_FORM_addr:
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000236 Size = Asm->getDataLayout().getPointerSize(); break;
Torok Edwinc23197a2009-07-14 16:55:14 +0000237 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling88423ee2009-05-15 00:11:17 +0000238 }
Eric Christopherca1dd052013-01-09 01:35:34 +0000239 Asm->OutStreamer.EmitIntValue(Integer, Size);
Bill Wendling88423ee2009-05-15 00:11:17 +0000240}
241
242/// SizeOf - Determine size of integer value in bytes.
243///
David Blaikie770530b2013-10-21 17:28:37 +0000244unsigned DIEInteger::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000245 switch (Form) {
Eric Christopher17dd9a92012-08-29 17:59:32 +0000246 case dwarf::DW_FORM_flag_present: return 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000247 case dwarf::DW_FORM_flag: // Fall thru
248 case dwarf::DW_FORM_ref1: // Fall thru
249 case dwarf::DW_FORM_data1: return sizeof(int8_t);
250 case dwarf::DW_FORM_ref2: // Fall thru
251 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Eric Christopherd96c72a2013-01-17 02:59:59 +0000252 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling88423ee2009-05-15 00:11:17 +0000253 case dwarf::DW_FORM_ref4: // Fall thru
254 case dwarf::DW_FORM_data4: return sizeof(int32_t);
255 case dwarf::DW_FORM_ref8: // Fall thru
256 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000257 case dwarf::DW_FORM_GNU_str_index: return MCAsmInfo::getULEB128Size(Integer);
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000258 case dwarf::DW_FORM_GNU_addr_index: return MCAsmInfo::getULEB128Size(Integer);
Chris Lattneraf76e592009-08-22 20:48:53 +0000259 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
260 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000261 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
David Blaikie4d6ccb52012-01-20 21:51:11 +0000262 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling88423ee2009-05-15 00:11:17 +0000263 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000264}
265
Bill Wendling88423ee2009-05-15 00:11:17 +0000266#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000267void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramer41a96492011-11-05 08:57:40 +0000268 O << "Int: " << (int64_t)Integer << " 0x";
269 O.write_hex(Integer);
Bill Wendling88423ee2009-05-15 00:11:17 +0000270}
271#endif
272
273//===----------------------------------------------------------------------===//
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000274// DIEExpr Implementation
275//===----------------------------------------------------------------------===//
276
277/// EmitValue - Emit expression value.
278///
David Blaikie770530b2013-10-21 17:28:37 +0000279void DIEExpr::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000280 AP->OutStreamer.EmitValue(Expr, SizeOf(AP, Form));
281}
282
283/// SizeOf - Determine size of expression value in bytes.
284///
David Blaikie770530b2013-10-21 17:28:37 +0000285unsigned DIEExpr::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000286 if (Form == dwarf::DW_FORM_data4) return 4;
287 if (Form == dwarf::DW_FORM_sec_offset) return 4;
288 if (Form == dwarf::DW_FORM_strp) return 4;
289 return AP->getDataLayout().getPointerSize();
290}
291
292#ifndef NDEBUG
293void DIEExpr::print(raw_ostream &O) const {
294 O << "Expr: ";
295 Expr->print(O);
296}
297#endif
298
299//===----------------------------------------------------------------------===//
Chris Lattner4faf59a2010-03-08 22:31:46 +0000300// DIELabel Implementation
Bill Wendling88423ee2009-05-15 00:11:17 +0000301//===----------------------------------------------------------------------===//
302
303/// EmitValue - Emit label value.
304///
David Blaikie770530b2013-10-21 17:28:37 +0000305void DIELabel::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
306 AP->EmitLabelReference(Label, SizeOf(AP, Form),
307 Form == dwarf::DW_FORM_strp ||
308 Form == dwarf::DW_FORM_sec_offset ||
309 Form == dwarf::DW_FORM_ref_addr);
Bill Wendling88423ee2009-05-15 00:11:17 +0000310}
311
312/// SizeOf - Determine size of label value in bytes.
313///
David Blaikie770530b2013-10-21 17:28:37 +0000314unsigned DIELabel::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000315 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher446b88f2013-01-17 03:00:04 +0000316 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewycky390c40d2011-10-27 06:44:11 +0000317 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000318 return AP->getDataLayout().getPointerSize();
Bill Wendling88423ee2009-05-15 00:11:17 +0000319}
320
Bill Wendling88423ee2009-05-15 00:11:17 +0000321#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000322void DIELabel::print(raw_ostream &O) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000323 O << "Lbl: " << Label->getName();
Bill Wendling88423ee2009-05-15 00:11:17 +0000324}
325#endif
326
327//===----------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000328// DIEDelta Implementation
329//===----------------------------------------------------------------------===//
330
331/// EmitValue - Emit delta value.
332///
David Blaikie770530b2013-10-21 17:28:37 +0000333void DIEDelta::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattnera37d5382010-04-05 00:18:22 +0000334 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling88423ee2009-05-15 00:11:17 +0000335}
336
337/// SizeOf - Determine size of delta value in bytes.
338///
David Blaikie770530b2013-10-21 17:28:37 +0000339unsigned DIEDelta::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000340 if (Form == dwarf::DW_FORM_data4) return 4;
Nick Lewycky390c40d2011-10-27 06:44:11 +0000341 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000342 return AP->getDataLayout().getPointerSize();
Bill Wendling88423ee2009-05-15 00:11:17 +0000343}
344
Bill Wendling88423ee2009-05-15 00:11:17 +0000345#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000346void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000347 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling88423ee2009-05-15 00:11:17 +0000348}
349#endif
350
351//===----------------------------------------------------------------------===//
Eric Christopher3dee5752013-07-26 17:02:41 +0000352// DIEString Implementation
353//===----------------------------------------------------------------------===//
354
355/// EmitValue - Emit string value.
356///
David Blaikie770530b2013-10-21 17:28:37 +0000357void DIEString::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher3dee5752013-07-26 17:02:41 +0000358 Access->EmitValue(AP, Form);
359}
360
361/// SizeOf - Determine size of delta value in bytes.
362///
David Blaikie770530b2013-10-21 17:28:37 +0000363unsigned DIEString::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher3dee5752013-07-26 17:02:41 +0000364 return Access->SizeOf(AP, Form);
365}
366
367#ifndef NDEBUG
368void DIEString::print(raw_ostream &O) const {
369 O << "String: " << Str << "\tSymbol: ";
370 Access->print(O);
371}
372#endif
373
374//===----------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000375// DIEEntry Implementation
376//===----------------------------------------------------------------------===//
377
378/// EmitValue - Emit debug information entry offset.
379///
David Blaikie770530b2013-10-21 17:28:37 +0000380void DIEEntry::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattnerd38fee82010-04-05 00:13:49 +0000381 AP->EmitInt32(Entry->getOffset());
Bill Wendling88423ee2009-05-15 00:11:17 +0000382}
383
Manman Ren0e6783f2013-07-02 23:40:10 +0000384unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
385 // DWARF4: References that use the attribute form DW_FORM_ref_addr are
386 // specified to be four bytes in the DWARF 32-bit format and eight bytes
387 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
388 // references have the same size as an address on the target system.
389 if (AP->getDwarfDebug()->getDwarfVersion() == 2)
390 return AP->getDataLayout().getPointerSize();
391 return sizeof(int32_t);
392}
393
Bill Wendling88423ee2009-05-15 00:11:17 +0000394#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000395void DIEEntry::print(raw_ostream &O) const {
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000396 O << format("Die: 0x%lx", (long)(intptr_t)Entry);
Bill Wendling88423ee2009-05-15 00:11:17 +0000397}
398#endif
399
400//===----------------------------------------------------------------------===//
401// DIEBlock Implementation
402//===----------------------------------------------------------------------===//
403
404/// ComputeSize - calculate the size of the block.
405///
Chris Lattnera37d5382010-04-05 00:18:22 +0000406unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000407 if (!Size) {
Eric Christopherf7cef702013-03-29 23:34:06 +0000408 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Bill Wendling88423ee2009-05-15 00:11:17 +0000409 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattnera37d5382010-04-05 00:18:22 +0000410 Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
Bill Wendling88423ee2009-05-15 00:11:17 +0000411 }
412
413 return Size;
414}
415
416/// EmitValue - Emit block data.
417///
David Blaikie770530b2013-10-21 17:28:37 +0000418void DIEBlock::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000419 switch (Form) {
Craig Topper5e25ee82012-02-05 08:31:47 +0000420 default: llvm_unreachable("Improper form for block");
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000421 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
422 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
423 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
424 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000425 }
426
Eric Christopherf7cef702013-03-29 23:34:06 +0000427 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000428 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattnerd38fee82010-04-05 00:13:49 +0000429 Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
Bill Wendling88423ee2009-05-15 00:11:17 +0000430}
431
432/// SizeOf - Determine size of block data in bytes.
433///
David Blaikie770530b2013-10-21 17:28:37 +0000434unsigned DIEBlock::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000435 switch (Form) {
436 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
437 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
438 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000439 case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
David Blaikie4d6ccb52012-01-20 21:51:11 +0000440 default: llvm_unreachable("Improper form for block");
Bill Wendling88423ee2009-05-15 00:11:17 +0000441 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000442}
443
Bill Wendling88423ee2009-05-15 00:11:17 +0000444#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000445void DIEBlock::print(raw_ostream &O) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000446 O << "Blk: ";
447 DIE::print(O, 5);
448}
449#endif