blob: e973541ee5be37ff17d71f9959883dd97c9cf360 [file] [log] [blame]
Bill Wendling47054f32009-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 Christopherb800ff72013-01-07 22:40:45 +000011//
Bill Wendling47054f32009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
14#include "DIE.h"
Manman Renac8062b2013-07-02 23:40:10 +000015#include "DwarfDebug.h"
David Blaikie47f615e2013-12-17 23:32:35 +000016#include "DwarfUnit.h"
Benjamin Kramer4d128a22010-01-17 07:46:39 +000017#include "llvm/ADT/Twine.h"
Bill Wendling47054f32009-05-15 00:11:17 +000018#include "llvm/CodeGen/AsmPrinter.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000019#include "llvm/IR/DataLayout.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000020#include "llvm/MC/MCAsmInfo.h"
Chris Lattner71601e82010-01-20 07:41:15 +000021#include "llvm/MC/MCStreamer.h"
Chris Lattner06d45f62010-01-16 18:50:28 +000022#include "llvm/MC/MCSymbol.h"
Benjamin Kramer74729ae2010-03-31 19:34:01 +000023#include "llvm/Support/Allocator.h"
David Greene8bc072c2009-12-24 00:27:55 +000024#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner74725712009-08-23 01:01:17 +000026#include "llvm/Support/Format.h"
Chris Lattnerf5c834f2010-01-22 22:09:00 +000027#include "llvm/Support/FormattedStream.h"
Eric Christopher67646432013-07-26 17:02:41 +000028#include "llvm/Support/MD5.h"
Bill Wendling47054f32009-05-15 00:11:17 +000029using namespace llvm;
30
31//===----------------------------------------------------------------------===//
32// DIEAbbrevData Implementation
33//===----------------------------------------------------------------------===//
34
35/// Profile - Used to gather unique data for the abbreviation folding set.
36///
37void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000038 // Explicitly cast to an integer type for which FoldingSetNodeID has
39 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
40 ID.AddInteger(unsigned(Attribute));
41 ID.AddInteger(unsigned(Form));
Bill Wendling47054f32009-05-15 00:11:17 +000042}
43
44//===----------------------------------------------------------------------===//
45// DIEAbbrev Implementation
46//===----------------------------------------------------------------------===//
47
48/// Profile - Used to gather unique data for the abbreviation folding set.
49///
50void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000051 ID.AddInteger(unsigned(Tag));
Bill Wendling47054f32009-05-15 00:11:17 +000052 ID.AddInteger(ChildrenFlag);
53
54 // For each attribute description.
55 for (unsigned i = 0, N = Data.size(); i < N; ++i)
56 Data[i].Profile(ID);
57}
58
59/// Emit - Print the abbreviation using the specified asm printer.
60///
Chris Lattner3a383cb2010-04-05 00:13:49 +000061void DIEAbbrev::Emit(AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000062 // Emit its Dwarf tag type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000063 AP->EmitULEB128(Tag, dwarf::TagString(Tag));
Bill Wendling47054f32009-05-15 00:11:17 +000064
65 // Emit whether it has children DIEs.
Chris Lattner3a383cb2010-04-05 00:13:49 +000066 AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
Bill Wendling47054f32009-05-15 00:11:17 +000067
68 // For each attribute description.
69 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
70 const DIEAbbrevData &AttrData = Data[i];
71
72 // Emit attribute type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000073 AP->EmitULEB128(AttrData.getAttribute(),
Nick Lewycky019d2552011-07-29 03:49:23 +000074 dwarf::AttributeString(AttrData.getAttribute()));
Bill Wendling47054f32009-05-15 00:11:17 +000075
76 // Emit form type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000077 AP->EmitULEB128(AttrData.getForm(),
78 dwarf::FormEncodingString(AttrData.getForm()));
Bill Wendling47054f32009-05-15 00:11:17 +000079 }
80
81 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +000082 AP->EmitULEB128(0, "EOM(1)");
83 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +000084}
85
86#ifndef NDEBUG
Chris Lattner74725712009-08-23 01:01:17 +000087void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling47054f32009-05-15 00:11:17 +000088 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +000089 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +000090 << " "
91 << dwarf::TagString(Tag)
92 << " "
93 << dwarf::ChildrenString(ChildrenFlag)
Chris Lattner74725712009-08-23 01:01:17 +000094 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +000095
96 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
97 O << " "
98 << dwarf::AttributeString(Data[i].getAttribute())
99 << " "
100 << dwarf::FormEncodingString(Data[i].getForm())
Chris Lattner74725712009-08-23 01:01:17 +0000101 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000102 }
103}
David Greene8bc072c2009-12-24 00:27:55 +0000104void DIEAbbrev::dump() { print(dbgs()); }
Bill Wendling47054f32009-05-15 00:11:17 +0000105#endif
106
107//===----------------------------------------------------------------------===//
108// DIE Implementation
109//===----------------------------------------------------------------------===//
110
111DIE::~DIE() {
112 for (unsigned i = 0, N = Children.size(); i < N; ++i)
113 delete Children[i];
114}
115
Eric Christopherd89221e2013-11-21 01:01:30 +0000116/// Climb up the parent chain to get the unit DIE to which this DIE
Manman Rence20d462013-10-29 22:57:10 +0000117/// belongs.
David Blaikie409dd9c2013-11-19 23:08:21 +0000118const DIE *DIE::getUnit() const {
119 const DIE *Cu = getUnitOrNull();
Manman Ren4dbdc902013-10-31 17:54:35 +0000120 assert(Cu && "We should not have orphaned DIEs.");
121 return Cu;
122}
123
Eric Christopherd89221e2013-11-21 01:01:30 +0000124/// Climb up the parent chain to get the unit DIE this DIE belongs
Manman Ren4dbdc902013-10-31 17:54:35 +0000125/// to. Return NULL if DIE is not added to an owner yet.
David Blaikie409dd9c2013-11-19 23:08:21 +0000126const DIE *DIE::getUnitOrNull() const {
Manman Rence20d462013-10-29 22:57:10 +0000127 const DIE *p = this;
128 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000129 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
130 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000131 return p;
132 p = p->getParent();
133 }
Manman Ren4dbdc902013-10-31 17:54:35 +0000134 return NULL;
Manman Rence20d462013-10-29 22:57:10 +0000135}
136
Eric Christopher0fe676a2013-11-21 00:48:22 +0000137DIEValue *DIE::findAttribute(uint16_t Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000138 const SmallVectorImpl<DIEValue *> &Values = getValues();
139 const DIEAbbrev &Abbrevs = getAbbrev();
140
141 // Iterate through all the attributes until we find the one we're
142 // looking for, if we can't find it return NULL.
143 for (size_t i = 0; i < Values.size(); ++i)
144 if (Abbrevs.getData()[i].getAttribute() == Attribute)
145 return Values[i];
146 return NULL;
147}
148
Bill Wendling47054f32009-05-15 00:11:17 +0000149#ifndef NDEBUG
Eric Christopher6c6de842013-05-06 17:50:50 +0000150void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000151 const std::string Indent(IndentCount, ' ');
152 bool isBlock = Abbrev.getTag() == 0;
153
154 if (!isBlock) {
155 O << Indent
156 << "Die: "
Chris Lattner74725712009-08-23 01:01:17 +0000157 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000158 << ", Offset: " << Offset
Chris Lattner3d72a672010-03-09 23:38:23 +0000159 << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000160
161 O << Indent
162 << dwarf::TagString(Abbrev.getTag())
163 << " "
Chris Lattner3d72a672010-03-09 23:38:23 +0000164 << dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000165 } else {
Chris Lattner3d72a672010-03-09 23:38:23 +0000166 O << "Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000167 }
Bill Wendling47054f32009-05-15 00:11:17 +0000168
Eric Christopher4887c8f2013-03-29 23:34:06 +0000169 const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
Bill Wendling47054f32009-05-15 00:11:17 +0000170
171 IndentCount += 2;
172 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
173 O << Indent;
174
175 if (!isBlock)
176 O << dwarf::AttributeString(Data[i].getAttribute());
177 else
178 O << "Blk[" << i << "]";
179
180 O << " "
181 << dwarf::FormEncodingString(Data[i].getForm())
182 << " ";
183 Values[i]->print(O);
184 O << "\n";
185 }
186 IndentCount -= 2;
187
188 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Eric Christopher6c6de842013-05-06 17:50:50 +0000189 Children[j]->print(O, IndentCount+4);
Bill Wendling47054f32009-05-15 00:11:17 +0000190 }
191
192 if (!isBlock) O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000193}
194
195void DIE::dump() {
David Greene8bc072c2009-12-24 00:27:55 +0000196 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000197}
198#endif
199
David Blaikiea379b1812011-12-20 02:50:00 +0000200void DIEValue::anchor() { }
Bill Wendling47054f32009-05-15 00:11:17 +0000201
202#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000203void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000204 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000205}
206#endif
207
208//===----------------------------------------------------------------------===//
209// DIEInteger Implementation
210//===----------------------------------------------------------------------===//
211
212/// EmitValue - Emit integer of appropriate size.
213///
David Blaikief2443192013-10-21 17:28:37 +0000214void DIEInteger::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Chris Lattner71601e82010-01-20 07:41:15 +0000215 unsigned Size = ~0U;
Bill Wendling47054f32009-05-15 00:11:17 +0000216 switch (Form) {
Eric Christopherbb69a272012-08-24 01:14:27 +0000217 case dwarf::DW_FORM_flag_present:
218 // Emit something to keep the lines and comments in sync.
219 // FIXME: Is there a better way to do this?
220 if (Asm->OutStreamer.hasRawTextSupport())
David Blaikied8c5b4e2013-10-24 22:43:10 +0000221 Asm->OutStreamer.EmitRawText("");
Eric Christopherbb69a272012-08-24 01:14:27 +0000222 return;
Bill Wendling47054f32009-05-15 00:11:17 +0000223 case dwarf::DW_FORM_flag: // Fall thru
224 case dwarf::DW_FORM_ref1: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000225 case dwarf::DW_FORM_data1: Size = 1; break;
Bill Wendling47054f32009-05-15 00:11:17 +0000226 case dwarf::DW_FORM_ref2: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000227 case dwarf::DW_FORM_data2: Size = 2; break;
Eric Christopher18266172013-01-17 02:59:59 +0000228 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000229 case dwarf::DW_FORM_ref4: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000230 case dwarf::DW_FORM_data4: Size = 4; break;
Bill Wendling47054f32009-05-15 00:11:17 +0000231 case dwarf::DW_FORM_ref8: // Fall thru
David Blaikie409dd9c2013-11-19 23:08:21 +0000232 case dwarf::DW_FORM_ref_sig8: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000233 case dwarf::DW_FORM_data8: Size = 8; break;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000234 case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
Eric Christopher962c9082013-01-15 23:56:56 +0000235 case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
Chris Lattner9efd1182010-04-04 19:09:29 +0000236 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
237 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000238 case dwarf::DW_FORM_addr:
Chandler Carruth5da3f052012-11-01 09:14:31 +0000239 Size = Asm->getDataLayout().getPointerSize(); break;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000240 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000241 }
Eric Christopherce0cfce2013-01-09 01:35:34 +0000242 Asm->OutStreamer.EmitIntValue(Integer, Size);
Bill Wendling47054f32009-05-15 00:11:17 +0000243}
244
245/// SizeOf - Determine size of integer value in bytes.
246///
David Blaikief2443192013-10-21 17:28:37 +0000247unsigned DIEInteger::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000248 switch (Form) {
Eric Christopher2a4e6162012-08-29 17:59:32 +0000249 case dwarf::DW_FORM_flag_present: return 0;
Bill Wendling47054f32009-05-15 00:11:17 +0000250 case dwarf::DW_FORM_flag: // Fall thru
251 case dwarf::DW_FORM_ref1: // Fall thru
252 case dwarf::DW_FORM_data1: return sizeof(int8_t);
253 case dwarf::DW_FORM_ref2: // Fall thru
254 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Eric Christopher18266172013-01-17 02:59:59 +0000255 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000256 case dwarf::DW_FORM_ref4: // Fall thru
257 case dwarf::DW_FORM_data4: return sizeof(int32_t);
258 case dwarf::DW_FORM_ref8: // Fall thru
David Blaikie409dd9c2013-11-19 23:08:21 +0000259 case dwarf::DW_FORM_ref_sig8: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000260 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000261 case dwarf::DW_FORM_GNU_str_index: return MCAsmInfo::getULEB128Size(Integer);
Eric Christopher962c9082013-01-15 23:56:56 +0000262 case dwarf::DW_FORM_GNU_addr_index: return MCAsmInfo::getULEB128Size(Integer);
Chris Lattner7b26fce2009-08-22 20:48:53 +0000263 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
264 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
Chandler Carruth5da3f052012-11-01 09:14:31 +0000265 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000266 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000267 }
Bill Wendling47054f32009-05-15 00:11:17 +0000268}
269
Bill Wendling47054f32009-05-15 00:11:17 +0000270#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000271void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000272 O << "Int: " << (int64_t)Integer << " 0x";
273 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000274}
275#endif
276
277//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000278// DIEExpr Implementation
279//===----------------------------------------------------------------------===//
280
281/// EmitValue - Emit expression value.
282///
David Blaikief2443192013-10-21 17:28:37 +0000283void DIEExpr::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000284 AP->OutStreamer.EmitValue(Expr, SizeOf(AP, Form));
285}
286
287/// SizeOf - Determine size of expression value in bytes.
288///
David Blaikief2443192013-10-21 17:28:37 +0000289unsigned DIEExpr::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000290 if (Form == dwarf::DW_FORM_data4) return 4;
291 if (Form == dwarf::DW_FORM_sec_offset) return 4;
292 if (Form == dwarf::DW_FORM_strp) return 4;
293 return AP->getDataLayout().getPointerSize();
294}
295
296#ifndef NDEBUG
297void DIEExpr::print(raw_ostream &O) const {
298 O << "Expr: ";
299 Expr->print(O);
300}
301#endif
302
303//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000304// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000305//===----------------------------------------------------------------------===//
306
307/// EmitValue - Emit label value.
308///
David Blaikief2443192013-10-21 17:28:37 +0000309void DIELabel::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
310 AP->EmitLabelReference(Label, SizeOf(AP, Form),
311 Form == dwarf::DW_FORM_strp ||
312 Form == dwarf::DW_FORM_sec_offset ||
313 Form == dwarf::DW_FORM_ref_addr);
Bill Wendling47054f32009-05-15 00:11:17 +0000314}
315
316/// SizeOf - Determine size of label value in bytes.
317///
David Blaikief2443192013-10-21 17:28:37 +0000318unsigned DIELabel::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000319 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000320 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000321 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth5da3f052012-11-01 09:14:31 +0000322 return AP->getDataLayout().getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000323}
324
Bill Wendling47054f32009-05-15 00:11:17 +0000325#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000326void DIELabel::print(raw_ostream &O) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000327 O << "Lbl: " << Label->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000328}
329#endif
330
331//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000332// DIEDelta Implementation
333//===----------------------------------------------------------------------===//
334
335/// EmitValue - Emit delta value.
336///
David Blaikief2443192013-10-21 17:28:37 +0000337void DIEDelta::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000338 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000339}
340
341/// SizeOf - Determine size of delta value in bytes.
342///
David Blaikief2443192013-10-21 17:28:37 +0000343unsigned DIEDelta::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000344 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000345 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000346 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth5da3f052012-11-01 09:14:31 +0000347 return AP->getDataLayout().getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000348}
349
Bill Wendling47054f32009-05-15 00:11:17 +0000350#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000351void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000352 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000353}
354#endif
355
356//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000357// DIEString Implementation
358//===----------------------------------------------------------------------===//
359
360/// EmitValue - Emit string value.
361///
David Blaikief2443192013-10-21 17:28:37 +0000362void DIEString::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher67646432013-07-26 17:02:41 +0000363 Access->EmitValue(AP, Form);
364}
365
366/// SizeOf - Determine size of delta value in bytes.
367///
David Blaikief2443192013-10-21 17:28:37 +0000368unsigned DIEString::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher67646432013-07-26 17:02:41 +0000369 return Access->SizeOf(AP, Form);
370}
371
372#ifndef NDEBUG
373void DIEString::print(raw_ostream &O) const {
374 O << "String: " << Str << "\tSymbol: ";
375 Access->print(O);
376}
377#endif
378
379//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000380// DIEEntry Implementation
381//===----------------------------------------------------------------------===//
382
383/// EmitValue - Emit debug information entry offset.
384///
David Blaikief2443192013-10-21 17:28:37 +0000385void DIEEntry::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner3a383cb2010-04-05 00:13:49 +0000386 AP->EmitInt32(Entry->getOffset());
Bill Wendling47054f32009-05-15 00:11:17 +0000387}
388
Manman Renac8062b2013-07-02 23:40:10 +0000389unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
390 // DWARF4: References that use the attribute form DW_FORM_ref_addr are
391 // specified to be four bytes in the DWARF 32-bit format and eight bytes
392 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
393 // references have the same size as an address on the target system.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000394 const DwarfDebug *DD = AP->getDwarfDebug();
395 assert(DD && "Expected Dwarf Debug info to be available");
396 if (DD->getDwarfVersion() == 2)
Manman Renac8062b2013-07-02 23:40:10 +0000397 return AP->getDataLayout().getPointerSize();
398 return sizeof(int32_t);
399}
400
Bill Wendling47054f32009-05-15 00:11:17 +0000401#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000402void DIEEntry::print(raw_ostream &O) const {
Chris Lattner74725712009-08-23 01:01:17 +0000403 O << format("Die: 0x%lx", (long)(intptr_t)Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000404}
405#endif
406
407//===----------------------------------------------------------------------===//
David Blaikie47f615e2013-12-17 23:32:35 +0000408// DIETypeSignature Implementation
409//===----------------------------------------------------------------------===//
410void DIETypeSignature::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
411 assert(Form == dwarf::DW_FORM_ref_sig8);
412 Asm->OutStreamer.EmitIntValue(Unit.getTypeSignature(), 8);
413}
414
415#ifndef NDEBUG
416void DIETypeSignature::print(raw_ostream &O) const {
417 O << format("Type Unit: 0x%lx", Unit.getTypeSignature());
418}
419
420void DIETypeSignature::dump() const { print(dbgs()); }
421#endif
422
423//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000424// DIEBlock Implementation
425//===----------------------------------------------------------------------===//
426
427/// ComputeSize - calculate the size of the block.
428///
Chris Lattner5a00dea2010-04-05 00:18:22 +0000429unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
Bill Wendling47054f32009-05-15 00:11:17 +0000430 if (!Size) {
Eric Christopher4887c8f2013-03-29 23:34:06 +0000431 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Bill Wendling47054f32009-05-15 00:11:17 +0000432 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattner5a00dea2010-04-05 00:18:22 +0000433 Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
Bill Wendling47054f32009-05-15 00:11:17 +0000434 }
435
436 return Size;
437}
438
439/// EmitValue - Emit block data.
440///
David Blaikief2443192013-10-21 17:28:37 +0000441void DIEBlock::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000442 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000443 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000444 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
445 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
446 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
447 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling47054f32009-05-15 00:11:17 +0000448 }
449
Eric Christopher4887c8f2013-03-29 23:34:06 +0000450 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Chris Lattner3d72a672010-03-09 23:38:23 +0000451 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattner3a383cb2010-04-05 00:13:49 +0000452 Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
Bill Wendling47054f32009-05-15 00:11:17 +0000453}
454
455/// SizeOf - Determine size of block data in bytes.
456///
David Blaikief2443192013-10-21 17:28:37 +0000457unsigned DIEBlock::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000458 switch (Form) {
459 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
460 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
461 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Chris Lattner9efd1182010-04-04 19:09:29 +0000462 case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
David Blaikie46a9f012012-01-20 21:51:11 +0000463 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000464 }
Bill Wendling47054f32009-05-15 00:11:17 +0000465}
466
Bill Wendling47054f32009-05-15 00:11:17 +0000467#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000468void DIEBlock::print(raw_ostream &O) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000469 O << "Blk: ";
470 DIE::print(O, 5);
471}
472#endif