AsmPrinter: Introduce DIEValue.def, NFC
[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 HANDLE_DIEVALUE(T)                                                     \
197   case is##T:                                                                  \
198     cast<DIE##T>(this)->EmitValueImpl(AP, Form);                               \
199     break;
200 #include "llvm/CodeGen/DIEValue.def"
201   }
202 }
203
204 unsigned DIEValue::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
205   switch (Ty) {
206 #define HANDLE_DIEVALUE(T)                                                     \
207   case is##T:                                                                  \
208     return cast<DIE##T>(this)->SizeOfImpl(AP, Form);
209 #include "llvm/CodeGen/DIEValue.def"
210   }
211   llvm_unreachable("Unknown DIE kind");
212 }
213
214 #ifndef NDEBUG
215 void DIEValue::print(raw_ostream &O) const {
216   switch (Ty) {
217 #define HANDLE_DIEVALUE(T)                                                     \
218   case is##T:                                                                  \
219     cast<DIE##T>(this)->printImpl(O);                                          \
220     break;
221 #include "llvm/CodeGen/DIEValue.def"
222   }
223 }
224
225 void DIEValue::dump() const {
226   print(dbgs());
227 }
228 #endif
229
230 //===----------------------------------------------------------------------===//
231 // DIEInteger Implementation
232 //===----------------------------------------------------------------------===//
233
234 /// EmitValue - Emit integer of appropriate size.
235 ///
236 void DIEInteger::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
237   unsigned Size = ~0U;
238   switch (Form) {
239   case dwarf::DW_FORM_flag_present:
240     // Emit something to keep the lines and comments in sync.
241     // FIXME: Is there a better way to do this?
242     Asm->OutStreamer->AddBlankLine();
243     return;
244   case dwarf::DW_FORM_flag:  // Fall thru
245   case dwarf::DW_FORM_ref1:  // Fall thru
246   case dwarf::DW_FORM_data1: Size = 1; break;
247   case dwarf::DW_FORM_ref2:  // Fall thru
248   case dwarf::DW_FORM_data2: Size = 2; break;
249   case dwarf::DW_FORM_sec_offset: // Fall thru
250   case dwarf::DW_FORM_strp: // Fall thru
251   case dwarf::DW_FORM_ref4:  // Fall thru
252   case dwarf::DW_FORM_data4: Size = 4; break;
253   case dwarf::DW_FORM_ref8:  // Fall thru
254   case dwarf::DW_FORM_ref_sig8:  // Fall thru
255   case dwarf::DW_FORM_data8: Size = 8; break;
256   case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return;
257   case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return;
258   case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
259   case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
260   case dwarf::DW_FORM_addr:
261     Size = Asm->getDataLayout().getPointerSize(); break;
262   case dwarf::DW_FORM_ref_addr:
263     Size = SizeOf(Asm, dwarf::DW_FORM_ref_addr);
264     break;
265   default: llvm_unreachable("DIE Value form not supported yet");
266   }
267   Asm->OutStreamer->EmitIntValue(Integer, Size);
268 }
269
270 /// SizeOf - Determine size of integer value in bytes.
271 ///
272 unsigned DIEInteger::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
273   switch (Form) {
274   case dwarf::DW_FORM_flag_present: return 0;
275   case dwarf::DW_FORM_flag:  // Fall thru
276   case dwarf::DW_FORM_ref1:  // Fall thru
277   case dwarf::DW_FORM_data1: return sizeof(int8_t);
278   case dwarf::DW_FORM_ref2:  // Fall thru
279   case dwarf::DW_FORM_data2: return sizeof(int16_t);
280   case dwarf::DW_FORM_sec_offset: // Fall thru
281   case dwarf::DW_FORM_strp: // Fall thru
282   case dwarf::DW_FORM_ref4:  // Fall thru
283   case dwarf::DW_FORM_data4: return sizeof(int32_t);
284   case dwarf::DW_FORM_ref8:  // Fall thru
285   case dwarf::DW_FORM_ref_sig8:  // Fall thru
286   case dwarf::DW_FORM_data8: return sizeof(int64_t);
287   case dwarf::DW_FORM_GNU_str_index: return getULEB128Size(Integer);
288   case dwarf::DW_FORM_GNU_addr_index: return getULEB128Size(Integer);
289   case dwarf::DW_FORM_udata: return getULEB128Size(Integer);
290   case dwarf::DW_FORM_sdata: return getSLEB128Size(Integer);
291   case dwarf::DW_FORM_addr:  return AP->getDataLayout().getPointerSize();
292   case dwarf::DW_FORM_ref_addr:
293     if (AP->OutStreamer->getContext().getDwarfVersion() == 2)
294       return AP->getDataLayout().getPointerSize();
295     return sizeof(int32_t);
296   default: llvm_unreachable("DIE Value form not supported yet");
297   }
298 }
299
300 #ifndef NDEBUG
301 void DIEInteger::printImpl(raw_ostream &O) const {
302   O << "Int: " << (int64_t)Integer << "  0x";
303   O.write_hex(Integer);
304 }
305 #endif
306
307 //===----------------------------------------------------------------------===//
308 // DIEExpr Implementation
309 //===----------------------------------------------------------------------===//
310
311 /// EmitValue - Emit expression value.
312 ///
313 void DIEExpr::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
314   AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
315 }
316
317 /// SizeOf - Determine size of expression value in bytes.
318 ///
319 unsigned DIEExpr::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
320   if (Form == dwarf::DW_FORM_data4) return 4;
321   if (Form == dwarf::DW_FORM_sec_offset) return 4;
322   if (Form == dwarf::DW_FORM_strp) return 4;
323   return AP->getDataLayout().getPointerSize();
324 }
325
326 #ifndef NDEBUG
327 void DIEExpr::printImpl(raw_ostream &O) const { O << "Expr: " << *Expr; }
328 #endif
329
330 //===----------------------------------------------------------------------===//
331 // DIELabel Implementation
332 //===----------------------------------------------------------------------===//
333
334 /// EmitValue - Emit label value.
335 ///
336 void DIELabel::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
337   AP->EmitLabelReference(Label, SizeOf(AP, Form),
338                          Form == dwarf::DW_FORM_strp ||
339                              Form == dwarf::DW_FORM_sec_offset ||
340                              Form == dwarf::DW_FORM_ref_addr);
341 }
342
343 /// SizeOf - Determine size of label value in bytes.
344 ///
345 unsigned DIELabel::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
346   if (Form == dwarf::DW_FORM_data4) return 4;
347   if (Form == dwarf::DW_FORM_sec_offset) return 4;
348   if (Form == dwarf::DW_FORM_strp) return 4;
349   return AP->getDataLayout().getPointerSize();
350 }
351
352 #ifndef NDEBUG
353 void DIELabel::printImpl(raw_ostream &O) const {
354   O << "Lbl: " << Label->getName();
355 }
356 #endif
357
358 //===----------------------------------------------------------------------===//
359 // DIEDelta Implementation
360 //===----------------------------------------------------------------------===//
361
362 /// EmitValue - Emit delta value.
363 ///
364 void DIEDelta::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
365   AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
366 }
367
368 /// SizeOf - Determine size of delta value in bytes.
369 ///
370 unsigned DIEDelta::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
371   if (Form == dwarf::DW_FORM_data4) return 4;
372   if (Form == dwarf::DW_FORM_sec_offset) return 4;
373   if (Form == dwarf::DW_FORM_strp) return 4;
374   return AP->getDataLayout().getPointerSize();
375 }
376
377 #ifndef NDEBUG
378 void DIEDelta::printImpl(raw_ostream &O) const {
379   O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
380 }
381 #endif
382
383 //===----------------------------------------------------------------------===//
384 // DIEString Implementation
385 //===----------------------------------------------------------------------===//
386
387 /// EmitValue - Emit string value.
388 ///
389 void DIEString::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
390   assert(
391       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
392       "Expected valid string form");
393
394   // Index of string in symbol table.
395   if (Form == dwarf::DW_FORM_GNU_str_index) {
396     DIEInteger(S.getIndex()).EmitValue(AP, Form);
397     return;
398   }
399
400   // Relocatable symbol.
401   assert(Form == dwarf::DW_FORM_strp);
402   if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
403     DIELabel(S.getSymbol()).EmitValue(AP, Form);
404     return;
405   }
406
407   // Offset into symbol table.
408   DIEInteger(S.getOffset()).EmitValue(AP, Form);
409 }
410
411 /// SizeOf - Determine size of delta value in bytes.
412 ///
413 unsigned DIEString::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
414   assert(
415       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
416       "Expected valid string form");
417
418   // Index of string in symbol table.
419   if (Form == dwarf::DW_FORM_GNU_str_index)
420     return DIEInteger(S.getIndex()).SizeOf(AP, Form);
421
422   // Relocatable symbol.
423   if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
424     return DIELabel(S.getSymbol()).SizeOf(AP, Form);
425
426   // Offset into symbol table.
427   return DIEInteger(S.getOffset()).SizeOf(AP, Form);
428 }
429
430 #ifndef NDEBUG
431 void DIEString::printImpl(raw_ostream &O) const {
432   O << "String: " << S.getString();
433 }
434 #endif
435
436 //===----------------------------------------------------------------------===//
437 // DIEEntry Implementation
438 //===----------------------------------------------------------------------===//
439
440 /// EmitValue - Emit debug information entry offset.
441 ///
442 void DIEEntry::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
443
444   if (Form == dwarf::DW_FORM_ref_addr) {
445     const DwarfDebug *DD = AP->getDwarfDebug();
446     unsigned Addr = Entry.getOffset();
447     assert(!DD->useSplitDwarf() && "TODO: dwo files can't have relocations.");
448     // For DW_FORM_ref_addr, output the offset from beginning of debug info
449     // section. Entry->getOffset() returns the offset from start of the
450     // compile unit.
451     DwarfCompileUnit *CU = DD->lookupUnit(Entry.getUnit());
452     assert(CU && "CUDie should belong to a CU.");
453     Addr += CU->getDebugInfoOffset();
454     if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
455       AP->EmitLabelPlusOffset(CU->getSectionSym(), Addr,
456                               DIEEntry::getRefAddrSize(AP));
457     else
458       AP->OutStreamer->EmitIntValue(Addr, DIEEntry::getRefAddrSize(AP));
459   } else
460     AP->EmitInt32(Entry.getOffset());
461 }
462
463 unsigned DIEEntry::getRefAddrSize(const AsmPrinter *AP) {
464   // DWARF4: References that use the attribute form DW_FORM_ref_addr are
465   // specified to be four bytes in the DWARF 32-bit format and eight bytes
466   // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
467   // references have the same size as an address on the target system.
468   const DwarfDebug *DD = AP->getDwarfDebug();
469   assert(DD && "Expected Dwarf Debug info to be available");
470   if (DD->getDwarfVersion() == 2)
471     return AP->getDataLayout().getPointerSize();
472   return sizeof(int32_t);
473 }
474
475 #ifndef NDEBUG
476 void DIEEntry::printImpl(raw_ostream &O) const {
477   O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
478 }
479 #endif
480
481 //===----------------------------------------------------------------------===//
482 // DIETypeSignature Implementation
483 //===----------------------------------------------------------------------===//
484 void DIETypeSignature::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
485   assert(Form == dwarf::DW_FORM_ref_sig8);
486   Asm->OutStreamer->EmitIntValue(Unit.getTypeSignature(), 8);
487 }
488
489 #ifndef NDEBUG
490 void DIETypeSignature::printImpl(raw_ostream &O) const {
491   O << format("Type Unit: 0x%lx", Unit.getTypeSignature());
492 }
493 #endif
494
495 //===----------------------------------------------------------------------===//
496 // DIELoc Implementation
497 //===----------------------------------------------------------------------===//
498
499 /// ComputeSize - calculate the size of the location expression.
500 ///
501 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
502   if (!Size) {
503     const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
504     for (unsigned i = 0, N = Values.size(); i < N; ++i)
505       Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
506   }
507
508   return Size;
509 }
510
511 /// EmitValue - Emit location data.
512 ///
513 void DIELoc::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
514   switch (Form) {
515   default: llvm_unreachable("Improper form for block");
516   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
517   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
518   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
519   case dwarf::DW_FORM_block:
520   case dwarf::DW_FORM_exprloc:
521     Asm->EmitULEB128(Size); break;
522   }
523
524   const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
525   for (unsigned i = 0, N = Values.size(); i < N; ++i)
526     Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
527 }
528
529 /// SizeOf - Determine size of location data in bytes.
530 ///
531 unsigned DIELoc::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
532   switch (Form) {
533   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
534   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
535   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
536   case dwarf::DW_FORM_block:
537   case dwarf::DW_FORM_exprloc:
538     return Size + getULEB128Size(Size);
539   default: llvm_unreachable("Improper form for block");
540   }
541 }
542
543 #ifndef NDEBUG
544 void DIELoc::printImpl(raw_ostream &O) const {
545   O << "ExprLoc: ";
546   DIE::print(O, 5);
547 }
548 #endif
549
550 //===----------------------------------------------------------------------===//
551 // DIEBlock Implementation
552 //===----------------------------------------------------------------------===//
553
554 /// ComputeSize - calculate the size of the block.
555 ///
556 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
557   if (!Size) {
558     const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
559     for (unsigned i = 0, N = Values.size(); i < N; ++i)
560       Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
561   }
562
563   return Size;
564 }
565
566 /// EmitValue - Emit block data.
567 ///
568 void DIEBlock::EmitValueImpl(const AsmPrinter *Asm, dwarf::Form Form) const {
569   switch (Form) {
570   default: llvm_unreachable("Improper form for block");
571   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
572   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
573   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
574   case dwarf::DW_FORM_block:  Asm->EmitULEB128(Size); break;
575   }
576
577   const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
578   for (unsigned i = 0, N = Values.size(); i < N; ++i)
579     Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
580 }
581
582 /// SizeOf - Determine size of block data in bytes.
583 ///
584 unsigned DIEBlock::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
585   switch (Form) {
586   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
587   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
588   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
589   case dwarf::DW_FORM_block:  return Size + getULEB128Size(Size);
590   default: llvm_unreachable("Improper form for block");
591   }
592 }
593
594 #ifndef NDEBUG
595 void DIEBlock::printImpl(raw_ostream &O) const {
596   O << "Blk: ";
597   DIE::print(O, 5);
598 }
599 #endif
600
601 //===----------------------------------------------------------------------===//
602 // DIELocList Implementation
603 //===----------------------------------------------------------------------===//
604
605 unsigned DIELocList::SizeOfImpl(const AsmPrinter *AP, dwarf::Form Form) const {
606   if (Form == dwarf::DW_FORM_data4)
607     return 4;
608   if (Form == dwarf::DW_FORM_sec_offset)
609     return 4;
610   return AP->getDataLayout().getPointerSize();
611 }
612
613 /// EmitValue - Emit label value.
614 ///
615 void DIELocList::EmitValueImpl(const AsmPrinter *AP, dwarf::Form Form) const {
616   DwarfDebug *DD = AP->getDwarfDebug();
617   MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
618
619   if (AP->MAI->doesDwarfUseRelocationsAcrossSections() && !DD->useSplitDwarf())
620     AP->emitSectionOffset(Label);
621   else
622     AP->EmitLabelDifference(Label, Label->getSection().getBeginSymbol(), 4);
623 }
624
625 #ifndef NDEBUG
626 void DIELocList::printImpl(raw_ostream &O) const {
627   O << "LocList: " << Index;
628
629 }
630 #endif