blob: 79c4b438f8e0b54703d58d3b8a2614c2cbce1a5c [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"
David Greene8bc072c2009-12-24 00:27:55 +000023#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Chris Lattner74725712009-08-23 01:01:17 +000025#include "llvm/Support/Format.h"
Chris Lattnerf5c834f2010-01-22 22:09:00 +000026#include "llvm/Support/FormattedStream.h"
Eric Christopher67646432013-07-26 17:02:41 +000027#include "llvm/Support/MD5.h"
Bill Wendling47054f32009-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 Klecknerad65f102013-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 Wendling47054f32009-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 Klecknerad65f102013-10-21 19:18:31 +000050 ID.AddInteger(unsigned(Tag));
Bill Wendling47054f32009-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 Lattner3a383cb2010-04-05 00:13:49 +000060void DIEAbbrev::Emit(AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000061 // Emit its Dwarf tag type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000062 AP->EmitULEB128(Tag, dwarf::TagString(Tag));
Bill Wendling47054f32009-05-15 00:11:17 +000063
64 // Emit whether it has children DIEs.
Chris Lattner3a383cb2010-04-05 00:13:49 +000065 AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
Bill Wendling47054f32009-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 Lattner3a383cb2010-04-05 00:13:49 +000072 AP->EmitULEB128(AttrData.getAttribute(),
Nick Lewycky019d2552011-07-29 03:49:23 +000073 dwarf::AttributeString(AttrData.getAttribute()));
Bill Wendling47054f32009-05-15 00:11:17 +000074
75 // Emit form type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000076 AP->EmitULEB128(AttrData.getForm(),
77 dwarf::FormEncodingString(AttrData.getForm()));
Bill Wendling47054f32009-05-15 00:11:17 +000078 }
79
80 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +000081 AP->EmitULEB128(0, "EOM(1)");
82 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +000083}
84
85#ifndef NDEBUG
Chris Lattner74725712009-08-23 01:01:17 +000086void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling47054f32009-05-15 00:11:17 +000087 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +000088 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +000089 << " "
90 << dwarf::TagString(Tag)
91 << " "
92 << dwarf::ChildrenString(ChildrenFlag)
Chris Lattner74725712009-08-23 01:01:17 +000093 << '\n';
Bill Wendling47054f32009-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 Lattner74725712009-08-23 01:01:17 +0000100 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000101 }
102}
David Greene8bc072c2009-12-24 00:27:55 +0000103void DIEAbbrev::dump() { print(dbgs()); }
Bill Wendling47054f32009-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
Eric Christopherd89221e2013-11-21 01:01:30 +0000115/// Climb up the parent chain to get the unit DIE to which this DIE
Manman Rence20d462013-10-29 22:57:10 +0000116/// belongs.
David Blaikie409dd9c2013-11-19 23:08:21 +0000117const DIE *DIE::getUnit() const {
118 const DIE *Cu = getUnitOrNull();
Manman Ren4dbdc902013-10-31 17:54:35 +0000119 assert(Cu && "We should not have orphaned DIEs.");
120 return Cu;
121}
122
Eric Christopherd89221e2013-11-21 01:01:30 +0000123/// Climb up the parent chain to get the unit DIE this DIE belongs
Manman Ren4dbdc902013-10-31 17:54:35 +0000124/// to. Return NULL if DIE is not added to an owner yet.
David Blaikie409dd9c2013-11-19 23:08:21 +0000125const DIE *DIE::getUnitOrNull() const {
Manman Rence20d462013-10-29 22:57:10 +0000126 const DIE *p = this;
127 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000128 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
129 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000130 return p;
131 p = p->getParent();
132 }
Manman Ren4dbdc902013-10-31 17:54:35 +0000133 return NULL;
Manman Rence20d462013-10-29 22:57:10 +0000134}
135
Eric Christopher0fe676a2013-11-21 00:48:22 +0000136DIEValue *DIE::findAttribute(uint16_t Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000137 const SmallVectorImpl<DIEValue *> &Values = getValues();
138 const DIEAbbrev &Abbrevs = getAbbrev();
139
140 // Iterate through all the attributes until we find the one we're
141 // looking for, if we can't find it return NULL.
142 for (size_t i = 0; i < Values.size(); ++i)
143 if (Abbrevs.getData()[i].getAttribute() == Attribute)
144 return Values[i];
145 return NULL;
146}
147
Bill Wendling47054f32009-05-15 00:11:17 +0000148#ifndef NDEBUG
Eric Christopher6c6de842013-05-06 17:50:50 +0000149void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000150 const std::string Indent(IndentCount, ' ');
151 bool isBlock = Abbrev.getTag() == 0;
152
153 if (!isBlock) {
154 O << Indent
155 << "Die: "
Chris Lattner74725712009-08-23 01:01:17 +0000156 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000157 << ", Offset: " << Offset
Chris Lattner3d72a672010-03-09 23:38:23 +0000158 << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000159
160 O << Indent
161 << dwarf::TagString(Abbrev.getTag())
162 << " "
Chris Lattner3d72a672010-03-09 23:38:23 +0000163 << dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000164 } else {
Chris Lattner3d72a672010-03-09 23:38:23 +0000165 O << "Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000166 }
Bill Wendling47054f32009-05-15 00:11:17 +0000167
Eric Christopher4887c8f2013-03-29 23:34:06 +0000168 const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
Bill Wendling47054f32009-05-15 00:11:17 +0000169
170 IndentCount += 2;
171 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
172 O << Indent;
173
174 if (!isBlock)
175 O << dwarf::AttributeString(Data[i].getAttribute());
176 else
177 O << "Blk[" << i << "]";
178
179 O << " "
180 << dwarf::FormEncodingString(Data[i].getForm())
181 << " ";
182 Values[i]->print(O);
183 O << "\n";
184 }
185 IndentCount -= 2;
186
187 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Eric Christopher6c6de842013-05-06 17:50:50 +0000188 Children[j]->print(O, IndentCount+4);
Bill Wendling47054f32009-05-15 00:11:17 +0000189 }
190
191 if (!isBlock) O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000192}
193
194void DIE::dump() {
David Greene8bc072c2009-12-24 00:27:55 +0000195 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000196}
197#endif
198
David Blaikiea379b1812011-12-20 02:50:00 +0000199void DIEValue::anchor() { }
Bill Wendling47054f32009-05-15 00:11:17 +0000200
201#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000202void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000203 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000204}
205#endif
206
207//===----------------------------------------------------------------------===//
208// DIEInteger Implementation
209//===----------------------------------------------------------------------===//
210
211/// EmitValue - Emit integer of appropriate size.
212///
David Blaikief2443192013-10-21 17:28:37 +0000213void DIEInteger::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Chris Lattner71601e82010-01-20 07:41:15 +0000214 unsigned Size = ~0U;
Bill Wendling47054f32009-05-15 00:11:17 +0000215 switch (Form) {
Eric Christopherbb69a272012-08-24 01:14:27 +0000216 case dwarf::DW_FORM_flag_present:
217 // Emit something to keep the lines and comments in sync.
218 // FIXME: Is there a better way to do this?
Rafael Espindola74c3e632014-01-16 07:36:00 +0000219 Asm->OutStreamer.AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000220 return;
Bill Wendling47054f32009-05-15 00:11:17 +0000221 case dwarf::DW_FORM_flag: // Fall thru
222 case dwarf::DW_FORM_ref1: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000223 case dwarf::DW_FORM_data1: Size = 1; break;
Bill Wendling47054f32009-05-15 00:11:17 +0000224 case dwarf::DW_FORM_ref2: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000225 case dwarf::DW_FORM_data2: Size = 2; break;
Eric Christopher18266172013-01-17 02:59:59 +0000226 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000227 case dwarf::DW_FORM_ref4: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000228 case dwarf::DW_FORM_data4: Size = 4; break;
Bill Wendling47054f32009-05-15 00:11:17 +0000229 case dwarf::DW_FORM_ref8: // Fall thru
David Blaikie409dd9c2013-11-19 23:08:21 +0000230 case dwarf::DW_FORM_ref_sig8: // Fall thru
Chris Lattner71601e82010-01-20 07:41:15 +0000231 case dwarf::DW_FORM_data8: Size = 8; break;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000232 case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
Eric Christopher962c9082013-01-15 23:56:56 +0000233 case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
Chris Lattner9efd1182010-04-04 19:09:29 +0000234 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
235 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000236 case dwarf::DW_FORM_addr:
Chandler Carruth5da3f052012-11-01 09:14:31 +0000237 Size = Asm->getDataLayout().getPointerSize(); break;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000238 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000239 }
Eric Christopherce0cfce2013-01-09 01:35:34 +0000240 Asm->OutStreamer.EmitIntValue(Integer, Size);
Bill Wendling47054f32009-05-15 00:11:17 +0000241}
242
243/// SizeOf - Determine size of integer value in bytes.
244///
David Blaikief2443192013-10-21 17:28:37 +0000245unsigned DIEInteger::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000246 switch (Form) {
Eric Christopher2a4e6162012-08-29 17:59:32 +0000247 case dwarf::DW_FORM_flag_present: return 0;
Bill Wendling47054f32009-05-15 00:11:17 +0000248 case dwarf::DW_FORM_flag: // Fall thru
249 case dwarf::DW_FORM_ref1: // Fall thru
250 case dwarf::DW_FORM_data1: return sizeof(int8_t);
251 case dwarf::DW_FORM_ref2: // Fall thru
252 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Eric Christopher18266172013-01-17 02:59:59 +0000253 case dwarf::DW_FORM_sec_offset: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000254 case dwarf::DW_FORM_ref4: // Fall thru
255 case dwarf::DW_FORM_data4: return sizeof(int32_t);
256 case dwarf::DW_FORM_ref8: // Fall thru
David Blaikie409dd9c2013-11-19 23:08:21 +0000257 case dwarf::DW_FORM_ref_sig8: // Fall thru
Bill Wendling47054f32009-05-15 00:11:17 +0000258 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000259 case dwarf::DW_FORM_GNU_str_index: return MCAsmInfo::getULEB128Size(Integer);
Eric Christopher962c9082013-01-15 23:56:56 +0000260 case dwarf::DW_FORM_GNU_addr_index: return MCAsmInfo::getULEB128Size(Integer);
Chris Lattner7b26fce2009-08-22 20:48:53 +0000261 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
262 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
Chandler Carruth5da3f052012-11-01 09:14:31 +0000263 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000264 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000265 }
Bill Wendling47054f32009-05-15 00:11:17 +0000266}
267
Bill Wendling47054f32009-05-15 00:11:17 +0000268#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000269void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000270 O << "Int: " << (int64_t)Integer << " 0x";
271 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000272}
273#endif
274
275//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000276// DIEExpr Implementation
277//===----------------------------------------------------------------------===//
278
279/// EmitValue - Emit expression value.
280///
David Blaikief2443192013-10-21 17:28:37 +0000281void DIEExpr::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000282 AP->OutStreamer.EmitValue(Expr, SizeOf(AP, Form));
283}
284
285/// SizeOf - Determine size of expression value in bytes.
286///
David Blaikief2443192013-10-21 17:28:37 +0000287unsigned DIEExpr::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000288 if (Form == dwarf::DW_FORM_data4) return 4;
289 if (Form == dwarf::DW_FORM_sec_offset) return 4;
290 if (Form == dwarf::DW_FORM_strp) return 4;
291 return AP->getDataLayout().getPointerSize();
292}
293
294#ifndef NDEBUG
295void DIEExpr::print(raw_ostream &O) const {
296 O << "Expr: ";
297 Expr->print(O);
298}
299#endif
300
301//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000302// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000303//===----------------------------------------------------------------------===//
304
305/// EmitValue - Emit label value.
306///
David Blaikief2443192013-10-21 17:28:37 +0000307void DIELabel::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
308 AP->EmitLabelReference(Label, SizeOf(AP, Form),
309 Form == dwarf::DW_FORM_strp ||
310 Form == dwarf::DW_FORM_sec_offset ||
311 Form == dwarf::DW_FORM_ref_addr);
Bill Wendling47054f32009-05-15 00:11:17 +0000312}
313
314/// SizeOf - Determine size of label value in bytes.
315///
David Blaikief2443192013-10-21 17:28:37 +0000316unsigned DIELabel::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000317 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000318 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000319 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth5da3f052012-11-01 09:14:31 +0000320 return AP->getDataLayout().getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000321}
322
Bill Wendling47054f32009-05-15 00:11:17 +0000323#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000324void DIELabel::print(raw_ostream &O) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000325 O << "Lbl: " << Label->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000326}
327#endif
328
329//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000330// DIEDelta Implementation
331//===----------------------------------------------------------------------===//
332
333/// EmitValue - Emit delta value.
334///
David Blaikief2443192013-10-21 17:28:37 +0000335void DIEDelta::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000336 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000337}
338
339/// SizeOf - Determine size of delta value in bytes.
340///
David Blaikief2443192013-10-21 17:28:37 +0000341unsigned DIEDelta::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000342 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000343 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000344 if (Form == dwarf::DW_FORM_strp) return 4;
Chandler Carruth5da3f052012-11-01 09:14:31 +0000345 return AP->getDataLayout().getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000346}
347
Bill Wendling47054f32009-05-15 00:11:17 +0000348#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000349void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000350 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000351}
352#endif
353
354//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000355// DIEString Implementation
356//===----------------------------------------------------------------------===//
357
358/// EmitValue - Emit string value.
359///
David Blaikief2443192013-10-21 17:28:37 +0000360void DIEString::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher67646432013-07-26 17:02:41 +0000361 Access->EmitValue(AP, Form);
362}
363
364/// SizeOf - Determine size of delta value in bytes.
365///
David Blaikief2443192013-10-21 17:28:37 +0000366unsigned DIEString::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher67646432013-07-26 17:02:41 +0000367 return Access->SizeOf(AP, Form);
368}
369
370#ifndef NDEBUG
371void DIEString::print(raw_ostream &O) const {
372 O << "String: " << Str << "\tSymbol: ";
373 Access->print(O);
374}
375#endif
376
377//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000378// DIEEntry Implementation
379//===----------------------------------------------------------------------===//
380
381/// EmitValue - Emit debug information entry offset.
382///
David Blaikief2443192013-10-21 17:28:37 +0000383void DIEEntry::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner3a383cb2010-04-05 00:13:49 +0000384 AP->EmitInt32(Entry->getOffset());
Bill Wendling47054f32009-05-15 00:11:17 +0000385}
386
Manman Renac8062b2013-07-02 23:40:10 +0000387unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
388 // DWARF4: References that use the attribute form DW_FORM_ref_addr are
389 // specified to be four bytes in the DWARF 32-bit format and eight bytes
390 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
391 // references have the same size as an address on the target system.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000392 const DwarfDebug *DD = AP->getDwarfDebug();
393 assert(DD && "Expected Dwarf Debug info to be available");
394 if (DD->getDwarfVersion() == 2)
Manman Renac8062b2013-07-02 23:40:10 +0000395 return AP->getDataLayout().getPointerSize();
396 return sizeof(int32_t);
397}
398
Bill Wendling47054f32009-05-15 00:11:17 +0000399#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000400void DIEEntry::print(raw_ostream &O) const {
Chris Lattner74725712009-08-23 01:01:17 +0000401 O << format("Die: 0x%lx", (long)(intptr_t)Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000402}
403#endif
404
405//===----------------------------------------------------------------------===//
David Blaikie47f615e2013-12-17 23:32:35 +0000406// DIETypeSignature Implementation
407//===----------------------------------------------------------------------===//
408void DIETypeSignature::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
409 assert(Form == dwarf::DW_FORM_ref_sig8);
410 Asm->OutStreamer.EmitIntValue(Unit.getTypeSignature(), 8);
411}
412
413#ifndef NDEBUG
414void DIETypeSignature::print(raw_ostream &O) const {
415 O << format("Type Unit: 0x%lx", Unit.getTypeSignature());
416}
417
418void DIETypeSignature::dump() const { print(dbgs()); }
419#endif
420
421//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000422// DIELoc Implementation
423//===----------------------------------------------------------------------===//
424
425/// ComputeSize - calculate the size of the location expression.
426///
427unsigned DIELoc::ComputeSize(AsmPrinter *AP) {
428 if (!Size) {
429 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
430 for (unsigned i = 0, N = Values.size(); i < N; ++i)
431 Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
432 }
433
434 return Size;
435}
436
437/// EmitValue - Emit location data.
438///
439void DIELoc::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
440 switch (Form) {
441 default: llvm_unreachable("Improper form for block");
442 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
443 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
444 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
445 case dwarf::DW_FORM_block:
446 case dwarf::DW_FORM_exprloc:
447 Asm->EmitULEB128(Size); break;
448 }
449
450 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
451 for (unsigned i = 0, N = Values.size(); i < N; ++i)
452 Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
453}
454
455/// SizeOf - Determine size of location data in bytes.
456///
457unsigned DIELoc::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
458 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);
462 case dwarf::DW_FORM_block:
463 case dwarf::DW_FORM_exprloc:
464 return Size + MCAsmInfo::getULEB128Size(Size);
465 default: llvm_unreachable("Improper form for block");
466 }
467}
468
469#ifndef NDEBUG
470void DIELoc::print(raw_ostream &O) const {
471 O << "ExprLoc: ";
472 DIE::print(O, 5);
473}
474#endif
475
476//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000477// DIEBlock Implementation
478//===----------------------------------------------------------------------===//
479
480/// ComputeSize - calculate the size of the block.
481///
Chris Lattner5a00dea2010-04-05 00:18:22 +0000482unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
Bill Wendling47054f32009-05-15 00:11:17 +0000483 if (!Size) {
Eric Christopher4887c8f2013-03-29 23:34:06 +0000484 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Bill Wendling47054f32009-05-15 00:11:17 +0000485 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattner5a00dea2010-04-05 00:18:22 +0000486 Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
Bill Wendling47054f32009-05-15 00:11:17 +0000487 }
488
489 return Size;
490}
491
492/// EmitValue - Emit block data.
493///
David Blaikief2443192013-10-21 17:28:37 +0000494void DIEBlock::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000495 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000496 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000497 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
498 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
499 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
500 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling47054f32009-05-15 00:11:17 +0000501 }
502
Eric Christopher4887c8f2013-03-29 23:34:06 +0000503 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Chris Lattner3d72a672010-03-09 23:38:23 +0000504 for (unsigned i = 0, N = Values.size(); i < N; ++i)
Chris Lattner3a383cb2010-04-05 00:13:49 +0000505 Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
Bill Wendling47054f32009-05-15 00:11:17 +0000506}
507
508/// SizeOf - Determine size of block data in bytes.
509///
David Blaikief2443192013-10-21 17:28:37 +0000510unsigned DIEBlock::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000511 switch (Form) {
512 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
513 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
514 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Chris Lattner9efd1182010-04-04 19:09:29 +0000515 case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
David Blaikie46a9f012012-01-20 21:51:11 +0000516 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000517 }
Bill Wendling47054f32009-05-15 00:11:17 +0000518}
519
Bill Wendling47054f32009-05-15 00:11:17 +0000520#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000521void DIEBlock::print(raw_ostream &O) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000522 O << "Blk: ";
523 DIE::print(O, 5);
524}
525#endif