blob: a22fd6064df5dcd48ac4552f3ba7427f1441a45d [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 {
37 ID.AddInteger(Attribute);
38 ID.AddInteger(Form);
39}
40
41//===----------------------------------------------------------------------===//
42// DIEAbbrev Implementation
43//===----------------------------------------------------------------------===//
44
45/// Profile - Used to gather unique data for the abbreviation folding set.
46///
47void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
48 ID.AddInteger(Tag);
49 ID.AddInteger(ChildrenFlag);
50
51 // For each attribute description.
52 for (unsigned i = 0, N = Data.size(); i < N; ++i)
53 Data[i].Profile(ID);
54}
55
56/// Emit - Print the abbreviation using the specified asm printer.
57///
Chris Lattnerd38fee82010-04-05 00:13:49 +000058void DIEAbbrev::Emit(AsmPrinter *AP) const {
Bill Wendling88423ee2009-05-15 00:11:17 +000059 // Emit its Dwarf tag type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000060 AP->EmitULEB128(Tag, dwarf::TagString(Tag));
Bill Wendling88423ee2009-05-15 00:11:17 +000061
62 // Emit whether it has children DIEs.
Chris Lattnerd38fee82010-04-05 00:13:49 +000063 AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
Bill Wendling88423ee2009-05-15 00:11:17 +000064
65 // For each attribute description.
66 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
67 const DIEAbbrevData &AttrData = Data[i];
68
69 // Emit attribute type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000070 AP->EmitULEB128(AttrData.getAttribute(),
Nick Lewycky3bbb6f72011-07-29 03:49:23 +000071 dwarf::AttributeString(AttrData.getAttribute()));
Bill Wendling88423ee2009-05-15 00:11:17 +000072
73 // Emit form type.
Chris Lattnerd38fee82010-04-05 00:13:49 +000074 AP->EmitULEB128(AttrData.getForm(),
75 dwarf::FormEncodingString(AttrData.getForm()));
Bill Wendling88423ee2009-05-15 00:11:17 +000076 }
77
78 // Mark end of abbreviation.
Chris Lattnerd38fee82010-04-05 00:13:49 +000079 AP->EmitULEB128(0, "EOM(1)");
80 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling88423ee2009-05-15 00:11:17 +000081}
82
83#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +000084void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling88423ee2009-05-15 00:11:17 +000085 O << "Abbreviation @"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000086 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling88423ee2009-05-15 00:11:17 +000087 << " "
88 << dwarf::TagString(Tag)
89 << " "
90 << dwarf::ChildrenString(ChildrenFlag)
Chris Lattnerb01acfa2009-08-23 01:01:17 +000091 << '\n';
Bill Wendling88423ee2009-05-15 00:11:17 +000092
93 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
94 O << " "
95 << dwarf::AttributeString(Data[i].getAttribute())
96 << " "
97 << dwarf::FormEncodingString(Data[i].getForm())
Chris Lattnerb01acfa2009-08-23 01:01:17 +000098 << '\n';
Bill Wendling88423ee2009-05-15 00:11:17 +000099 }
100}
David Greene0c8b6e62009-12-24 00:27:55 +0000101void DIEAbbrev::dump() { print(dbgs()); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000102#endif
103
104//===----------------------------------------------------------------------===//
105// DIE Implementation
106//===----------------------------------------------------------------------===//
107
108DIE::~DIE() {
109 for (unsigned i = 0, N = Children.size(); i < N; ++i)
110 delete Children[i];
111}
112
Eric Christopher3bf2bcd2013-05-06 17:50:46 +0000113/// Climb up the parent chain to get the compile unit DIE to which this DIE
114/// belongs.
Eric Christopher4d7f2ce2013-05-14 21:33:10 +0000115DIE *DIE::getCompileUnit() {
116 DIE *p = this;
Manman Renbc3e96f2013-03-12 18:27:15 +0000117 while (p) {
118 if (p->getTag() == dwarf::DW_TAG_compile_unit)
119 return p;
120 p = p->getParent();
121 }
Manman Renb1e052a2013-03-13 18:33:41 +0000122 llvm_unreachable("We should not have orphaned DIEs.");
Manman Renbc3e96f2013-03-12 18:27:15 +0000123}
124
Eric Christopher31667622013-08-08 01:41:00 +0000125DIEValue *DIE::findAttribute(uint16_t Attribute) {
Eric Christopherb7669132013-08-07 01:18:33 +0000126 const SmallVectorImpl<DIEValue *> &Values = getValues();
127 const DIEAbbrev &Abbrevs = getAbbrev();
128
129 // Iterate through all the attributes until we find the one we're
130 // looking for, if we can't find it return NULL.
131 for (size_t i = 0; i < Values.size(); ++i)
132 if (Abbrevs.getData()[i].getAttribute() == Attribute)
133 return Values[i];
134 return NULL;
135}
136
Bill Wendling88423ee2009-05-15 00:11:17 +0000137#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000138void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000139 const std::string Indent(IndentCount, ' ');
140 bool isBlock = Abbrev.getTag() == 0;
141
142 if (!isBlock) {
143 O << Indent
144 << "Die: "
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000145 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling88423ee2009-05-15 00:11:17 +0000146 << ", Offset: " << Offset
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000147 << ", Size: " << Size << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000148
149 O << Indent
150 << dwarf::TagString(Abbrev.getTag())
151 << " "
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000152 << dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000153 } else {
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000154 O << "Size: " << Size << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000155 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000156
Eric Christopherf7cef702013-03-29 23:34:06 +0000157 const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
Bill Wendling88423ee2009-05-15 00:11:17 +0000158
159 IndentCount += 2;
160 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
161 O << Indent;
162
163 if (!isBlock)
164 O << dwarf::AttributeString(Data[i].getAttribute());
165 else
166 O << "Blk[" << i << "]";
167
168 O << " "
169 << dwarf::FormEncodingString(Data[i].getForm())
170 << " ";
171 Values[i]->print(O);
172 O << "\n";
173 }
174 IndentCount -= 2;
175
176 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Eric Christopher30cb8362013-05-06 17:50:50 +0000177 Children[j]->print(O, IndentCount+4);
Bill Wendling88423ee2009-05-15 00:11:17 +0000178 }
179
180 if (!isBlock) O << "\n";
Bill Wendling88423ee2009-05-15 00:11:17 +0000181}
182
183void DIE::dump() {
David Greene0c8b6e62009-12-24 00:27:55 +0000184 print(dbgs());
Bill Wendling88423ee2009-05-15 00:11:17 +0000185}
186#endif
187
David Blaikie2d24e2a2011-12-20 02:50:00 +0000188void DIEValue::anchor() { }
Bill Wendling88423ee2009-05-15 00:11:17 +0000189
190#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000191void DIEValue::dump() const {
David Greene0c8b6e62009-12-24 00:27:55 +0000192 print(dbgs());
Bill Wendling88423ee2009-05-15 00:11:17 +0000193}
194#endif
195
196//===----------------------------------------------------------------------===//
197// DIEInteger Implementation
198//===----------------------------------------------------------------------===//
199
200/// EmitValue - Emit integer of appropriate size.
201///
Eric Christopher31667622013-08-08 01:41:00 +0000202void DIEInteger::EmitValue(AsmPrinter *Asm, uint16_t Form) const {
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000203 unsigned Size = ~0U;
Bill Wendling88423ee2009-05-15 00:11:17 +0000204 switch (Form) {
Eric Christopher873cf0a2012-08-24 01:14:27 +0000205 case dwarf::DW_FORM_flag_present:
206 // Emit something to keep the lines and comments in sync.
207 // FIXME: Is there a better way to do this?
208 if (Asm->OutStreamer.hasRawTextSupport())
209 Asm->OutStreamer.EmitRawText(StringRef(""));
210 return;
Bill Wendling88423ee2009-05-15 00:11:17 +0000211 case dwarf::DW_FORM_flag: // Fall thru
212 case dwarf::DW_FORM_ref1: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000213 case dwarf::DW_FORM_data1: Size = 1; break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000214 case dwarf::DW_FORM_ref2: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000215 case dwarf::DW_FORM_data2: Size = 2; break;
Eric Christopherd96c72a2013-01-17 02:59:59 +0000216 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling88423ee2009-05-15 00:11:17 +0000217 case dwarf::DW_FORM_ref4: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000218 case dwarf::DW_FORM_data4: Size = 4; break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000219 case dwarf::DW_FORM_ref8: // Fall thru
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000220 case dwarf::DW_FORM_data8: Size = 8; break;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000221 case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000222 case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000223 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
224 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
Eric Christopher4984e012012-09-10 23:34:03 +0000225 case dwarf::DW_FORM_addr:
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000226 Size = Asm->getDataLayout().getPointerSize(); break;
Torok Edwinc23197a2009-07-14 16:55:14 +0000227 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling88423ee2009-05-15 00:11:17 +0000228 }
Eric Christopherca1dd052013-01-09 01:35:34 +0000229 Asm->OutStreamer.EmitIntValue(Integer, Size);
Bill Wendling88423ee2009-05-15 00:11:17 +0000230}
231
232/// SizeOf - Determine size of integer value in bytes.
233///
Eric Christopher31667622013-08-08 01:41:00 +0000234unsigned DIEInteger::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000235 switch (Form) {
Eric Christopher17dd9a92012-08-29 17:59:32 +0000236 case dwarf::DW_FORM_flag_present: return 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000237 case dwarf::DW_FORM_flag: // Fall thru
238 case dwarf::DW_FORM_ref1: // Fall thru
239 case dwarf::DW_FORM_data1: return sizeof(int8_t);
240 case dwarf::DW_FORM_ref2: // Fall thru
241 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Eric Christopherd96c72a2013-01-17 02:59:59 +0000242 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling88423ee2009-05-15 00:11:17 +0000243 case dwarf::DW_FORM_ref4: // Fall thru
244 case dwarf::DW_FORM_data4: return sizeof(int32_t);
245 case dwarf::DW_FORM_ref8: // Fall thru
246 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000247 case dwarf::DW_FORM_GNU_str_index: return MCAsmInfo::getULEB128Size(Integer);
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000248 case dwarf::DW_FORM_GNU_addr_index: return MCAsmInfo::getULEB128Size(Integer);
Chris Lattneraf76e592009-08-22 20:48:53 +0000249 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
250 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000251 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
David Blaikie4d6ccb52012-01-20 21:51:11 +0000252 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling88423ee2009-05-15 00:11:17 +0000253 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000254}
255
Bill Wendling88423ee2009-05-15 00:11:17 +0000256#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000257void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramer41a96492011-11-05 08:57:40 +0000258 O << "Int: " << (int64_t)Integer << " 0x";
259 O.write_hex(Integer);
Bill Wendling88423ee2009-05-15 00:11:17 +0000260}
261#endif
262
263//===----------------------------------------------------------------------===//
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000264// DIEExpr Implementation
265//===----------------------------------------------------------------------===//
266
267/// EmitValue - Emit expression value.
268///
Eric Christopher31667622013-08-08 01:41:00 +0000269void DIEExpr::EmitValue(AsmPrinter *AP, uint16_t Form) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000270 AP->OutStreamer.EmitValue(Expr, SizeOf(AP, Form));
271}
272
273/// SizeOf - Determine size of expression value in bytes.
274///
Eric Christopher31667622013-08-08 01:41:00 +0000275unsigned DIEExpr::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000276 if (Form == dwarf::DW_FORM_data4) return 4;
277 if (Form == dwarf::DW_FORM_sec_offset) return 4;
278 if (Form == dwarf::DW_FORM_strp) return 4;
279 return AP->getDataLayout().getPointerSize();
280}
281
282#ifndef NDEBUG
283void DIEExpr::print(raw_ostream &O) const {
284 O << "Expr: ";
285 Expr->print(O);
286}
287#endif
288
289//===----------------------------------------------------------------------===//
Chris Lattner4faf59a2010-03-08 22:31:46 +0000290// DIELabel Implementation
Bill Wendling88423ee2009-05-15 00:11:17 +0000291//===----------------------------------------------------------------------===//
292
293/// EmitValue - Emit label value.
294///
Eric Christopher31667622013-08-08 01:41:00 +0000295void DIELabel::EmitValue(AsmPrinter *AP, uint16_t Form) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000296 AP->EmitLabelReference(Label, SizeOf(AP, Form));
Bill Wendling88423ee2009-05-15 00:11:17 +0000297}
298
299/// SizeOf - Determine size of label value in bytes.
300///
Eric Christopher31667622013-08-08 01:41:00 +0000301unsigned DIELabel::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000302 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher446b88f2013-01-17 03:00:04 +0000303 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewycky390c40d2011-10-27 06:44:11 +0000304 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000305 return AP->getDataLayout().getPointerSize();
Bill Wendling88423ee2009-05-15 00:11:17 +0000306}
307
Bill Wendling88423ee2009-05-15 00:11:17 +0000308#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000309void DIELabel::print(raw_ostream &O) const {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000310 O << "Lbl: " << Label->getName();
Bill Wendling88423ee2009-05-15 00:11:17 +0000311}
312#endif
313
314//===----------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000315// DIEDelta Implementation
316//===----------------------------------------------------------------------===//
317
318/// EmitValue - Emit delta value.
319///
Eric Christopher31667622013-08-08 01:41:00 +0000320void DIEDelta::EmitValue(AsmPrinter *AP, uint16_t Form) const {
Chris Lattnera37d5382010-04-05 00:18:22 +0000321 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling88423ee2009-05-15 00:11:17 +0000322}
323
324/// SizeOf - Determine size of delta value in bytes.
325///
Eric Christopher31667622013-08-08 01:41:00 +0000326unsigned DIEDelta::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000327 if (Form == dwarf::DW_FORM_data4) return 4;
Nick Lewycky390c40d2011-10-27 06:44:11 +0000328 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth426c2bf2012-11-01 09:14:31 +0000329 return AP->getDataLayout().getPointerSize();
Bill Wendling88423ee2009-05-15 00:11:17 +0000330}
331
Bill Wendling88423ee2009-05-15 00:11:17 +0000332#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000333void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000334 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling88423ee2009-05-15 00:11:17 +0000335}
336#endif
337
338//===----------------------------------------------------------------------===//
Eric Christopher3dee5752013-07-26 17:02:41 +0000339// DIEString Implementation
340//===----------------------------------------------------------------------===//
341
342/// EmitValue - Emit string value.
343///
Eric Christopher31667622013-08-08 01:41:00 +0000344void DIEString::EmitValue(AsmPrinter *AP, uint16_t Form) const {
Eric Christopher3dee5752013-07-26 17:02:41 +0000345 Access->EmitValue(AP, Form);
346}
347
348/// SizeOf - Determine size of delta value in bytes.
349///
Eric Christopher31667622013-08-08 01:41:00 +0000350unsigned DIEString::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Eric Christopher3dee5752013-07-26 17:02:41 +0000351 return Access->SizeOf(AP, Form);
352}
353
354#ifndef NDEBUG
355void DIEString::print(raw_ostream &O) const {
356 O << "String: " << Str << "\tSymbol: ";
357 Access->print(O);
358}
359#endif
360
361//===----------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000362// DIEEntry Implementation
363//===----------------------------------------------------------------------===//
364
365/// EmitValue - Emit debug information entry offset.
366///
Eric Christopher31667622013-08-08 01:41:00 +0000367void DIEEntry::EmitValue(AsmPrinter *AP, uint16_t Form) const {
Chris Lattnerd38fee82010-04-05 00:13:49 +0000368 AP->EmitInt32(Entry->getOffset());
Bill Wendling88423ee2009-05-15 00:11:17 +0000369}
370
Manman Ren0e6783f2013-07-02 23:40:10 +0000371unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
372 // DWARF4: References that use the attribute form DW_FORM_ref_addr are
373 // specified to be four bytes in the DWARF 32-bit format and eight bytes
374 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
375 // references have the same size as an address on the target system.
376 if (AP->getDwarfDebug()->getDwarfVersion() == 2)
377 return AP->getDataLayout().getPointerSize();
378 return sizeof(int32_t);
379}
380
Bill Wendling88423ee2009-05-15 00:11:17 +0000381#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000382void DIEEntry::print(raw_ostream &O) const {
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000383 O << format("Die: 0x%lx", (long)(intptr_t)Entry);
Bill Wendling88423ee2009-05-15 00:11:17 +0000384}
385#endif
386
387//===----------------------------------------------------------------------===//
388// DIEBlock Implementation
389//===----------------------------------------------------------------------===//
390
391/// ComputeSize - calculate the size of the block.
392///
Chris Lattnera37d5382010-04-05 00:18:22 +0000393unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000394 if (!Size) {
Eric Christopherf7cef702013-03-29 23:34:06 +0000395 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Bill Wendling88423ee2009-05-15 00:11:17 +0000396 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattnera37d5382010-04-05 00:18:22 +0000397 Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
Bill Wendling88423ee2009-05-15 00:11:17 +0000398 }
399
400 return Size;
401}
402
403/// EmitValue - Emit block data.
404///
Eric Christopher31667622013-08-08 01:41:00 +0000405void DIEBlock::EmitValue(AsmPrinter *Asm, uint16_t Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000406 switch (Form) {
Craig Topper5e25ee82012-02-05 08:31:47 +0000407 default: llvm_unreachable("Improper form for block");
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000408 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
409 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
410 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
411 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling88423ee2009-05-15 00:11:17 +0000412 }
413
Eric Christopherf7cef702013-03-29 23:34:06 +0000414 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Chris Lattner0d9d70f2010-03-09 23:38:23 +0000415 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattnerd38fee82010-04-05 00:13:49 +0000416 Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
Bill Wendling88423ee2009-05-15 00:11:17 +0000417}
418
419/// SizeOf - Determine size of block data in bytes.
420///
Eric Christopher31667622013-08-08 01:41:00 +0000421unsigned DIEBlock::SizeOf(AsmPrinter *AP, uint16_t Form) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000422 switch (Form) {
423 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
424 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
425 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000426 case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
David Blaikie4d6ccb52012-01-20 21:51:11 +0000427 default: llvm_unreachable("Improper form for block");
Bill Wendling88423ee2009-05-15 00:11:17 +0000428 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000429}
430
Bill Wendling88423ee2009-05-15 00:11:17 +0000431#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000432void DIEBlock::print(raw_ostream &O) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000433 O << "Blk: ";
434 DIE::print(O, 5);
435}
436#endif