Revert "AsmPrinter: Change DIEValue to be stored by value"
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DIE.cpp
1 //===--- 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.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/DIE.h"
15 #include "DwarfCompileUnit.h"
16 #include "DwarfDebug.h"
17 #include "DwarfUnit.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/Format.h"
28 #include "llvm/Support/FormattedStream.h"
29 #include "llvm/Support/LEB128.h"
30 #include "llvm/Support/MD5.h"
31 #include "llvm/Support/raw_ostream.h"
32 using namespace llvm;
33
34 //===----------------------------------------------------------------------===//
35 // DIEAbbrevData Implementation
36 //===----------------------------------------------------------------------===//
37
38 /// Profile - Used to gather unique data for the abbreviation folding set.
39 ///
40 void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
41   // Explicitly cast to an integer type for which FoldingSetNodeID has
42   // overloads.  Otherwise MSVC 2010 thinks this call is ambiguous.
43   ID.AddInteger(unsigned(Attribute));
44   ID.AddInteger(unsigned(Form));
45 }
46
47 //===----------------------------------------------------------------------===//
48 // DIEAbbrev Implementation
49 //===----------------------------------------------------------------------===//
50
51 /// Profile - Used to gather unique data for the abbreviation folding set.
52 ///
53 void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
54   ID.AddInteger(unsigned(Tag));
55   ID.AddInteger(unsigned(Children));
56
57   // For each attribute description.
58   for (unsigned i = 0, N = Data.size(); i < N; ++i)
59     Data[i].Profile(ID);
60 }
61
62 /// Emit - Print the abbreviation using the specified asm printer.
63 ///
64 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
65   // Emit its Dwarf tag type.
66   AP->EmitULEB128(Tag, dwarf::TagString(Tag));
67
68   // Emit whether it has children DIEs.
69   AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children));
70
71   // For each attribute description.
72   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
73     const DIEAbbrevData &AttrData = Data[i];
74
75     // Emit attribute type.
76     AP->EmitULEB128(AttrData.getAttribute(),
77                     dwarf::AttributeString(AttrData.getAttribute()));
78
79     // Emit form type.
80     AP->EmitULEB128(AttrData.getForm(),
81                     dwarf::FormEncodingString(AttrData.getForm()));
82   }
83
84   // Mark end of abbreviation.
85   AP->EmitULEB128(0, "EOM(1)");
86   AP->EmitULEB128(0, "EOM(2)");
87 }
88
89 #ifndef NDEBUG
90 void DIEAbbrev::print(raw_ostream &O) {
91   O << "Abbreviation @"
92     << format("0x%lx", (long)(intptr_t)this)
93     << "  "
94     << dwarf::TagString(Tag)
95     << " "
96     << dwarf::ChildrenString(Children)
97     << '\n';
98
99   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
100     O << "  "
101       << dwarf::AttributeString(Data[i].getAttribute())
102       << "  "
103       << dwarf::FormEncodingString(Data[i].getForm())
104       << '\n';
105   }
106 }
107 void DIEAbbrev::dump() { print(dbgs()); }
108 #endif
109
110 /// Climb up the parent chain to get the unit DIE to which this DIE
111 /// belongs.
112 const DIE *DIE::getUnit() const {
113   const DIE *Cu = getUnitOrNull();
114   assert(Cu && "We should not have orphaned DIEs.");
115   return Cu;
116 }
117
118 /// Climb up the parent chain to get the unit DIE this DIE belongs
119 /// to. Return NULL if DIE is not added to an owner yet.
120 const DIE *DIE::getUnitOrNull() const {
121   const DIE *p = this;
122   while (p) {
123     if (p->getTag() == dwarf::DW_TAG_compile_unit ||
124         p->getTag() == dwarf::DW_TAG_type_unit)
125       return p;
126     p = p->getParent();
127   }
128   return nullptr;
129 }
130
131 DIEValue *DIE::findAttribute(dwarf::Attribute Attribute) const {
132   const SmallVectorImpl<DIEValue *> &Values = getValues();
133   const DIEAbbrev &Abbrevs = getAbbrev();
134
135   // Iterate through all the attributes until we find the one we're
136   // looking for, if we can't find it return NULL.
137   for (size_t i = 0; i < Values.size(); ++i)
138     if (Abbrevs.getData()[i].getAttribute() == Attribute)
139       return Values[i];
140   return nullptr;
141 }
142
143 #ifndef NDEBUG
144 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
145   const std::string Indent(IndentCount, ' ');
146   bool isBlock = Abbrev.getTag() == 0;
147
148   if (!isBlock) {
149     O << Indent
150       << "Die: "
151       << format("0x%lx", (long)(intptr_t)this)
152       << ", Offset: " << Offset
153       << ", Size: " << Size << "\n";
154
155     O << Indent
156       << dwarf::TagString(Abbrev.getTag())
157       << " "
158       << dwarf::ChildrenString(Abbrev.hasChildren()) << "\n";
159   } else {
160     O << "Size: " << Size << "\n";
161   }
162
163   const SmallVectorImpl<DIEAbbrevData> &Data = Abbrev.getData();
164
165   IndentCount += 2;
166   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
167     O << Indent;
168
169     if (!isBlock)
170       O << dwarf::AttributeString(Data[i].getAttribute());
171     else
172       O << "Blk[" << i << "]";
173
174     O <<  "  "
175       << dwarf::FormEncodingString(Data[i].getForm())
176       << " ";
177     Values[i]->print(O);
178     O << "\n";
179   }
180   IndentCount -= 2;
181
182   for (unsigned j = 0, M = Children.size(); j < M; ++j) {
183     Children[j]->print(O, IndentCount+4);
184   }
185
186   if (!isBlock) O << "\n";
187 }
188
189 void DIE::dump() {
190   print(dbgs());
191 }
192 #endif
193
194 void DIEValue::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
195   switch (Ty) {
196 #define EMIT_VALUE_IMPL(Kind)                                                  \
197   case is##Kind:                                                               \
198     cast<DIE##Kind>(this)->EmitValueImpl(AP, Form);                            \
199     break;
200     EMIT_VALUE_IMPL(Integer)
201     EMIT_VALUE_IMPL(String)
202     EMIT_VALUE_IMPL(Expr)
203     EMIT_VALUE_IMPL(Label)
204     EMIT_VALUE_IMPL(Delta)
205     EMIT_VALUE_IMPL(Entry)
206     EMIT_VALUE_IMPL(TypeSignature)
207     EMIT_VALUE_IMPL(Block)
208     EMIT_VALUE_IMPL(Loc)
209     EMIT_VALUE_IMPL(LocList)
210 #undef EMIT_VALUE_IMPL
211   }
212 }
213
214 unsigned DIEValue::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
215   switch (Ty) {
216 #define SIZE_OF_IMPL(Kind)                                                     \
217   case is##Kind:                                                               \
218     return cast<DIE##Kind>(this)->SizeOfImpl(AP, Form);
219     SIZE_OF_IMPL(Integer)
220     SIZE_OF_IMPL(String)
221     SIZE_OF_IMPL(Expr)
222     SIZE_OF_IMPL(Label)
223     SIZE_OF_IMPL(Delta)
224     SIZE_OF_IMPL(Entry)
225     SIZE_OF_IMPL(TypeSignature)
226     SIZE_OF_IMPL(Block)
227     SIZE_OF_IMPL(Loc)
228     SIZE_OF_IMPL(LocList)
229 #undef SIZE_OF_IMPL
230   }
231   llvm_unreachable("Unknown DIE kind");
232 }
233
234 #ifndef NDEBUG
235 void DIEValue::print(raw_ostream &O) const {
236   switch (Ty) {
237 #define PRINT_IMPL(Kind)                                                       \
238   case is##Kind:                                                               \
239     cast<DIE##Kind>(this)->printImpl(O);                                       \
240     break;
241     PRINT_IMPL(Integer)
242     PRINT_IMPL(String)
243     PRINT_IMPL(Expr)
244     PRINT_IMPL(Label)
245     PRINT_IMPL(Delta)
246     PRINT_IMPL(Entry)
247     PRINT_IMPL(TypeSignature)
248     PRINT_IMPL(Block)
249     PRINT_IMPL(Loc)
250     PRINT_IMPL(LocList)
251 #undef PRINT_IMPL
252   }
253 }
254
255 void DIEValue::dump() const {
256   print(dbgs());
257 }
258 #endif
259
260 //===----------------------------------------------------------------------===//
261 // DIEInteger Implementation
262 //===----------------------------------------------------------------------===//
263
264 /// EmitValue - Emit integer of appropriate size.
265 ///
266 void DIEInteger::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
267   unsigned Size = ~0U;
268   switch (Form) {
269   case dwarf::DW_FORM_flag_present:
270     // Emit something to keep the lines and comments in sync.
271     // FIXME: Is there a better way to do this?
272     Asm->OutStreamer->AddBlankLine();
273     return;
274   case dwarf::DW_FORM_flag:  // Fall thru
275   case dwarf::DW_FORM_ref1:  // Fall thru
276   case dwarf::DW_FORM_data1: Size = 1; break;
277   case dwarf::DW_FORM_ref2:  // Fall thru
278   case dwarf::DW_FORM_data2: Size = 2; break;
279   case dwarf::DW_FORM_sec_offset: // Fall thru
280   case dwarf::DW_FORM_strp: // Fall thru
281   case dwarf::DW_FORM_ref4:  // Fall thru
282   case dwarf::DW_FORM_data4: Size = 4; break;
283   case dwarf::DW_FORM_ref8:  // Fall thru
284   case dwarf::DW_FORM_ref_sig8:  // Fall thru
285   case dwarf::DW_FORM_data8: Size = 8; break;
286   case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
287   case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
288   case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
289   case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
290   case dwarf::DW_FORM_addr:
291     Size = Asm->getDataLayout().getPointerSize(); break;
292   case dwarf::DW_FORM_ref_addr:
293     Size = SizeOf(Asm, dwarf::DW_FORM_ref_addr);
294     break;
295   default: llvm_unreachable("DIE Value form not supported yet");
296   }
297   Asm->OutStreamer->EmitIntValue(Integer, Size);
298 }
299
300 /// SizeOf - Determine size of integer value in bytes.
301 ///
302 unsigned DIEInteger::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
303   switch (Form) {
304   case dwarf::DW_FORM_flag_present: return 0;
305   case dwarf::DW_FORM_flag:  // Fall thru
306   case dwarf::DW_FORM_ref1:  // Fall thru
307   case dwarf::DW_FORM_data1: return sizeof(int8_t);
308   case dwarf::DW_FORM_ref2:  // Fall thru
309   case dwarf::DW_FORM_data2: return sizeof(int16_t);
310   case dwarf::DW_FORM_sec_offset: // Fall thru
311   case dwarf::DW_FORM_strp: // Fall thru
312   case dwarf::DW_FORM_ref4:  // Fall thru
313   case dwarf::DW_FORM_data4: return sizeof(int32_t);
314   case dwarf::DW_FORM_ref8:  // Fall thru
315   case dwarf::DW_FORM_ref_sig8:  // Fall thru
316   case dwarf::DW_FORM_data8: return sizeof(int64_t);
317   case dwarf::DW_FORM_GNU_str_index: return getULEB128Size(Integer);
318   case dwarf::DW_FORM_GNU_addr_index: return getULEB128Size(Integer);
319   case dwarf::DW_FORM_udata: return getULEB128Size(Integer);
320   case dwarf::DW_FORM_sdata: return getSLEB128Size(Integer);
321   case dwarf::DW_FORM_addr:  return AP->getDataLayout().getPointerSize();
322   case dwarf::DW_FORM_ref_addr:
323     if (AP->OutStreamer->getContext().getDwarfVersion() == 2)
324       return AP->getDataLayout().getPointerSize();
325     return sizeof(int32_t);
326   default: llvm_unreachable("DIE Value form not supported yet");
327   }
328 }
329
330 #ifndef NDEBUG
331 void DIEInteger::printImpl(raw_ostream &O) const {
332   O << "Int: " << (int64_t)Integer << "  0x";
333   O.write_hex(Integer);
334 }
335 #endif
336
337 //===----------------------------------------------------------------------===//
338 // DIEExpr Implementation
339 //===----------------------------------------------------------------------===//
340
341 /// EmitValue - Emit expression value.
342 ///
343 void DIEExpr::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
344   AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
345 }
346
347 /// SizeOf - Determine size of expression value in bytes.
348 ///
349 unsigned DIEExpr::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
350   if (Form == dwarf::DW_FORM_data4) return 4;
351   if (Form == dwarf::DW_FORM_sec_offset) return 4;
352   if (Form == dwarf::DW_FORM_strp) return 4;
353   return AP->getDataLayout().getPointerSize();
354 }
355
356 #ifndef NDEBUG
357 void DIEExpr::printImpl(raw_ostream &O) const { O << "Expr: " << *Expr; }
358 #endif
359
360 //===----------------------------------------------------------------------===//
361 // DIELabel Implementation
362 //===----------------------------------------------------------------------===//
363
364 /// EmitValue - Emit label value.
365 ///
366 void DIELabel::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
367   AP->EmitLabelReference(Label, SizeOf(AP, Form),
368                          Form == dwarf::DW_FORM_strp ||
369                              Form == dwarf::DW_FORM_sec_offset ||
370                              Form == dwarf::DW_FORM_ref_addr);
371 }
372
373 /// SizeOf - Determine size of label value in bytes.
374 ///
375 unsigned DIELabel::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
376   if (Form == dwarf::DW_FORM_data4) return 4;
377   if (Form == dwarf::DW_FORM_sec_offset) return 4;
378   if (Form == dwarf::DW_FORM_strp) return 4;
379   return AP->getDataLayout().getPointerSize();
380 }
381
382 #ifndef NDEBUG
383 void DIELabel::printImpl(raw_ostream &O) const {
384   O << "Lbl: " << Label->getName();
385 }
386 #endif
387
388 //===----------------------------------------------------------------------===//
389 // DIEDelta Implementation
390 //===----------------------------------------------------------------------===//
391
392 /// EmitValue - Emit delta value.
393 ///
394 void DIEDelta::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
395   AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
396 }
397
398 /// SizeOf - Determine size of delta value in bytes.
399 ///
400 unsigned DIEDelta::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
401   if (Form == dwarf::DW_FORM_data4) return 4;
402   if (Form == dwarf::DW_FORM_sec_offset) return 4;
403   if (Form == dwarf::DW_FORM_strp) return 4;
404   return AP->getDataLayout().getPointerSize();
405 }
406
407 #ifndef NDEBUG
408 void DIEDelta::printImpl(raw_ostream &O) const {
409   O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
410 }
411 #endif
412
413 //===----------------------------------------------------------------------===//
414 // DIEString Implementation
415 //===----------------------------------------------------------------------===//
416
417 /// EmitValue - Emit string value.
418 ///
419 void DIEString::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
420   assert(
421       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
422       "Expected valid string form");
423
424   // Index of string in symbol table.
425   if (Form == dwarf::DW_FORM_GNU_str_index) {
426     DIEInteger(S.getIndex()).EmitValue(AP, Form);
427     return;
428   }
429
430   // Relocatable symbol.
431   assert(Form == dwarf::DW_FORM_strp);
432   if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
433     DIELabel(S.getSymbol()).EmitValue(AP, Form);
434     return;
435   }
436
437   // Offset into symbol table.
438   DIEInteger(S.getOffset()).EmitValue(AP, Form);
439 }
440
441 /// SizeOf - Determine size of delta value in bytes.
442 ///
443 unsigned DIEString::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
444   assert(
445       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
446       "Expected valid string form");
447
448   // Index of string in symbol table.
449   if (Form == dwarf::DW_FORM_GNU_str_index)
450     return DIEInteger(S.getIndex()).SizeOf(AP, Form);
451
452   // Relocatable symbol.
453   if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
454     return DIELabel(S.getSymbol()).SizeOf(AP, Form);
455
456   // Offset into symbol table.
457   return DIEInteger(S.getOffset()).SizeOf(AP, Form);
458 }
459
460 #ifndef NDEBUG
461 void DIEString::printImpl(raw_ostream &O) const {
462   O << "String: " << S.getString();
463 }
464 #endif
465
466 //===----------------------------------------------------------------------===//
467 // DIEEntry Implementation
468 //===----------------------------------------------------------------------===//
469
470 /// EmitValue - Emit debug information entry offset.
471 ///
472 void DIEEntry::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
473
474   if (Form == dwarf::DW_FORM_ref_addr) {
475     const DwarfDebug *DD = AP->getDwarfDebug();
476     unsigned Addr = Entry.getOffset();
477     assert(!DD->useSplitDwarf() && "TODO: dwo files can't have relocations.");
478     // For DW_FORM_ref_addr, output the offset from beginning of debug info
479     // section. Entry->getOffset() returns the offset from start of the
480     // compile unit.
481     DwarfCompileUnit *CU = DD->lookupUnit(Entry.getUnit());
482     assert(CU && "CUDie should belong to a CU.");
483     Addr += CU->getDebugInfoOffset();
484     if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
485       AP->EmitLabelPlusOffset(CU->getSectionSym(), Addr,
486                               DIEEntry::getRefAddrSize(AP));
487     else
488       AP->OutStreamer->EmitIntValue(Addr, DIEEntry::getRefAddrSize(AP));
489   } else
490     AP->EmitInt32(Entry.getOffset());
491 }
492
493 unsigned DIEEntry::getRefAddrSize(const AsmPrinter *AP) {
494   // DWARF4: References that use the attribute form DW_FORM_ref_addr are
495   // specified to be four bytes in the DWARF 32-bit format and eight bytes
496   // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
497   // references have the same size as an address on the target system.
498   const DwarfDebug *DD = AP->getDwarfDebug();
499   assert(DD && "Expected Dwarf Debug info to be available");
500   if (DD->getDwarfVersion() == 2)
501     return AP->getDataLayout().getPointerSize();
502   return sizeof(int32_t);
503 }
504
505 #ifndef NDEBUG
506 void DIEEntry::printImpl(raw_ostream &O) const {
507   O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
508 }
509 #endif
510
511 //===----------------------------------------------------------------------===//
512 // DIETypeSignature Implementation
513 //===----------------------------------------------------------------------===//
514 void DIETypeSignature::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
515   assert(Form == dwarf::DW_FORM_ref_sig8);
516   Asm->OutStreamer->EmitIntValue(Unit.getTypeSignature(), 8);
517 }
518
519 #ifndef NDEBUG
520 void DIETypeSignature::printImpl(raw_ostream &O) const {
521   O << format("Type Unit: 0x%lx", Unit.getTypeSignature());
522 }
523 #endif
524
525 //===----------------------------------------------------------------------===//
526 // DIELoc Implementation
527 //===----------------------------------------------------------------------===//
528
529 /// ComputeSize - calculate the size of the location expression.
530 ///
531 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
532   if (!Size) {
533     const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
534     for (unsigned i = 0, N = Values.size(); i < N; ++i)
535       Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
536   }
537
538   return Size;
539 }
540
541 /// EmitValue - Emit location data.
542 ///
543 void DIELoc::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
544   switch (Form) {
545   default: llvm_unreachable("Improper form for block");
546   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
547   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
548   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
549   case dwarf::DW_FORM_block:
550   case dwarf::DW_FORM_exprloc:
551     Asm->EmitULEB128(Size); break;
552   }
553
554   const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
555   for (unsigned i = 0, N = Values.size(); i < N; ++i)
556     Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
557 }
558
559 /// SizeOf - Determine size of location data in bytes.
560 ///
561 unsigned DIELoc::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
562   switch (Form) {
563   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
564   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
565   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
566   case dwarf::DW_FORM_block:
567   case dwarf::DW_FORM_exprloc:
568     return Size + getULEB128Size(Size);
569   default: llvm_unreachable("Improper form for block");
570   }
571 }
572
573 #ifndef NDEBUG
574 void DIELoc::printImpl(raw_ostream &O) const {
575   O << "ExprLoc: ";
576   DIE::print(O, 5);
577 }
578 #endif
579
580 //===----------------------------------------------------------------------===//
581 // DIEBlock Implementation
582 //===----------------------------------------------------------------------===//
583
584 /// ComputeSize - calculate the size of the block.
585 ///
586 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
587   if (!Size) {
588     const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
589     for (unsigned i = 0, N = Values.size(); i < N; ++i)
590       Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
591   }
592
593   return Size;
594 }
595
596 /// EmitValue - Emit block data.
597 ///
598 void DIEBlock::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
599   switch (Form) {
600   default: llvm_unreachable("Improper form for block");
601   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
602   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
603   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
604   case dwarf::DW_FORM_block:  Asm->EmitULEB128(Size); break;
605   }
606
607   const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
608   for (unsigned i = 0, N = Values.size(); i < N; ++i)
609     Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
610 }
611
612 /// SizeOf - Determine size of block data in bytes.
613 ///
614 unsigned DIEBlock::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
615   switch (Form) {
616   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
617   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
618   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
619   case dwarf::DW_FORM_block:  return Size + getULEB128Size(Size);
620   default: llvm_unreachable("Improper form for block");
621   }
622 }
623
624 #ifndef NDEBUG
625 void DIEBlock::printImpl(raw_ostream &O) const {
626   O << "Blk: ";
627   DIE::print(O, 5);
628 }
629 #endif
630
631 //===----------------------------------------------------------------------===//
632 // DIELocList Implementation
633 //===----------------------------------------------------------------------===//
634
635 unsigned DIELocList::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
636   if (Form == dwarf::DW_FORM_data4)
637     return 4;
638   if (Form == dwarf::DW_FORM_sec_offset)
639     return 4;
640   return AP->getDataLayout().getPointerSize();
641 }
642
643 /// EmitValue - Emit label value.
644 ///
645 void DIELocList::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
646   DwarfDebug *DD = AP->getDwarfDebug();
647   MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
648
649   if (AP->MAI->doesDwarfUseRelocationsAcrossSections() && !DD->useSplitDwarf())
650     AP->emitSectionOffset(Label);
651   else
652     AP->EmitLabelDifference(Label, Label->getSection().getBeginSymbol(), 4);
653 }
654
655 #ifndef NDEBUG
656 void DIELocList::printImpl(raw_ostream &O) const {
657   O << "LocList: " << Index;
658
659 }
660 #endif