summaryrefslogtreecommitdiff
path: root/include/llvm/CodeGen/DwarfWriter.h
blob: b9953004df36ccfba64de2362977a4885631e591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
//===-- llvm/CodeGen/DwarfWriter.h - Dwarf Framework ------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by James M. Laskey and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains support for writing Dwarf debug info into asm files.  For
// Details on the Dwarf 3 specfication see DWARF Debugging Information Format
// V.3 reference manual http://dwarf.freestandards.org ,
//
// The role of the Dwarf Writer class is to extract debug information from the
// MachineDebugInfo object, organize it in Dwarf form and then emit it into asm
// the current asm file using data and high level Dwarf directives.
// 
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_DWARFWRITER_H
#define LLVM_CODEGEN_DWARFWRITER_H

#include "llvm/ADT/UniqueVector.h"
#include "llvm/Support/DataTypes.h"

#include <iosfwd>
#include <string>


namespace llvm {
  
  //===--------------------------------------------------------------------===//
  // Forward declarations.
  //
  class AsmPrinter;
  class CompileUnitDesc;
  class DebugInfoDesc;
  class DIE;
  class DwarfWriter;
  class GlobalVariableDesc;
  class MachineDebugInfo;
  class MachineFunction;
  class Module;
  class SubprogramDesc;
  class Type;
  class TypeDesc;
  
  //===--------------------------------------------------------------------===//
  // DWLabel - Labels are used to track locations in the assembler file.
  // Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
  // category of label (Ex. location) and number is a value unique in that
  // category.
  class DWLabel {
  public:
    const char *Tag;                    // Label category tag. Should always be
                                        // a staticly declared C string.
    unsigned    Number;                 // Unique number.

    DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
  };
  
  //===--------------------------------------------------------------------===//
  // DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
  // Dwarf abbreviation.
  class DIEAbbrevData {
  private:
    unsigned Attribute;                 // Dwarf attribute code.
    unsigned Form;                      // Dwarf form code.
    
  public:
    DIEAbbrevData(unsigned A, unsigned F)
    : Attribute(A)
    , Form(F)
    {}
    
    // Accessors
    unsigned getAttribute() const { return Attribute; }
    unsigned getForm()      const { return Form; }
    
    /// operator== - Used by DIEAbbrev to locate entry.
    ///
    bool operator==(const DIEAbbrevData &DAD) const {
      return Attribute == DAD.Attribute && Form == DAD.Form;
    }

    /// operator!= - Used by DIEAbbrev to locate entry.
    ///
    bool operator!=(const DIEAbbrevData &DAD) const {
      return Attribute != DAD.Attribute || Form != DAD.Form;
    }
    
    /// operator< - Used by DIEAbbrev to locate entry.
    ///
    bool operator<(const DIEAbbrevData &DAD) const {
      return Attribute < DAD.Attribute ||
            (Attribute == DAD.Attribute && Form < DAD.Form);
    }
  };
  
  //===--------------------------------------------------------------------===//
  // DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
  // information object.
  class DIEAbbrev {
  private:
    unsigned Tag;                       // Dwarf tag code.
    unsigned ChildrenFlag;              // Dwarf children flag.
    std::vector<DIEAbbrevData> Data;    // Raw data bytes for abbreviation.

  public:
  
    DIEAbbrev(unsigned T, unsigned C)
    : Tag(T)
    , ChildrenFlag(C)
    , Data()
    {}
    ~DIEAbbrev() {}
    
    // Accessors
    unsigned getTag()                           const { return Tag; }
    unsigned getChildrenFlag()                  const { return ChildrenFlag; }
    const std::vector<DIEAbbrevData> &getData() const { return Data; }
    void setChildrenFlag(unsigned CF)                 { ChildrenFlag = CF; }

    /// operator== - Used by UniqueVector to locate entry.
    ///
    bool operator==(const DIEAbbrev &DA) const;

    /// operator< - Used by UniqueVector to locate entry.
    ///
    bool operator<(const DIEAbbrev &DA) const;

    /// AddAttribute - Adds another set of attribute information to the
    /// abbreviation.
    void AddAttribute(unsigned Attribute, unsigned Form) {
      Data.push_back(DIEAbbrevData(Attribute, Form));
    }
    
    /// Emit - Print the abbreviation using the specified Dwarf writer.
    ///
    void Emit(const DwarfWriter &DW) const; 
        
#ifndef NDEBUG
    void print(std::ostream &O);
    void dump();
#endif
  };

  //===--------------------------------------------------------------------===//
  // DIEValue - A debug information entry value.
  //
  class DIEValue {
  public:
    enum {
      isInteger,
      isString,
      isLabel,
      isAsIsLabel,
      isDelta,
      isEntry
    };
    
    unsigned Type;                      // Type of the value
    
    DIEValue(unsigned T) : Type(T) {}
    virtual ~DIEValue() {}
    
    // Implement isa/cast/dyncast.
    static bool classof(const DIEValue *) { return true; }
    
    /// EmitValue - Emit value via the Dwarf writer.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const = 0;
    
    /// SizeOf - Return the size of a value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const = 0;
  };

  //===--------------------------------------------------------------------===//
  // DWInteger - An integer value DIE.
  // 
  class DIEInteger : public DIEValue {
  private:
    uint64_t Integer;
    
  public:
    DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEInteger *) { return true; }
    static bool classof(const DIEValue *I)  { return I->Type == isInteger; }
    
    /// EmitValue - Emit integer of appropriate size.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of integer value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };

  //===--------------------------------------------------------------------===//
  // DIEString - A string value DIE.
  // 
  struct DIEString : public DIEValue {
    const std::string String;
    
    DIEString(const std::string &S) : DIEValue(isString), String(S) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEString *) { return true; }
    static bool classof(const DIEValue *S) { return S->Type == isString; }
    
    /// EmitValue - Emit string value.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of string value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };

  //===--------------------------------------------------------------------===//
  // DIEDwarfLabel - A Dwarf internal label expression DIE.
  //
  struct DIEDwarfLabel : public DIEValue {
    const DWLabel Label;
    
    DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEDwarfLabel *)  { return true; }
    static bool classof(const DIEValue *L) { return L->Type == isLabel; }
    
    /// EmitValue - Emit label value.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of label value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };


  //===--------------------------------------------------------------------===//
  // DIEObjectLabel - A label to an object in code or data.
  //
  struct DIEObjectLabel : public DIEValue {
    const std::string Label;
    
    DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEObjectLabel *) { return true; }
    static bool classof(const DIEValue *L)    { return L->Type == isAsIsLabel; }
    
    /// EmitValue - Emit label value.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of label value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };

  //===--------------------------------------------------------------------===//
  // DIEDelta - A simple label difference DIE.
  // 
  struct DIEDelta : public DIEValue {
    const DWLabel LabelHi;
    const DWLabel LabelLo;
    
    DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
    : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEDelta *)  { return true; }
    static bool classof(const DIEValue *D) { return D->Type == isDelta; }
    
    /// EmitValue - Emit delta value.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of delta value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };
  
  //===--------------------------------------------------------------------===//
  // DIEntry - A pointer to a debug information entry.
  // 
  struct DIEntry : public DIEValue {
    DIE *Entry;
    
    DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}

    // Implement isa/cast/dyncast.
    static bool classof(const DIEntry *)   { return true; }
    static bool classof(const DIEValue *E) { return E->Type == isEntry; }
    
    /// EmitValue - Emit delta value.
    ///
    virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
    
    /// SizeOf - Determine size of delta value in bytes.
    ///
    virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
  };
  
  //===--------------------------------------------------------------------===//
  // DIE - A structured debug information entry.  Has an abbreviation which
  // describes it's organization.
  class DIE {
  private:
    DIEAbbrev *Abbrev;                    // Temporary buffer for abbreviation.
    unsigned AbbrevID;                    // Decribing abbreviation ID.
    unsigned Offset;                      // Offset in debug info section.
    unsigned Size;                        // Size of instance + children.
    std::vector<DIE *> Children;          // Children DIEs.
    std::vector<DIEValue *> Values;       // Attributes values.
    
  public:
    DIE(unsigned Tag);
    ~DIE();
    
    // Accessors
    unsigned   getAbbrevID()                   const { return AbbrevID; }
    unsigned   getOffset()                     const { return Offset; }
    unsigned   getSize()                       const { return Size; }
    const std::vector<DIE *> &getChildren()    const { return Children; }
    const std::vector<DIEValue *> &getValues() const { return Values; }
    void setOffset(unsigned O)                 { Offset = O; }
    void setSize(unsigned S)                   { Size = S; }
    
    /// SiblingOffset - Return the offset of the debug information entry's
    /// sibling.
    unsigned SiblingOffset() const { return Offset + Size; }

    /// AddUInt - Add an unsigned integer attribute data and value.
    ///
    void AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer);

    /// AddSInt - Add an signed integer attribute data and value.
    ///
    void AddSInt(unsigned Attribute, unsigned Form, int64_t Integer);
        
    /// AddString - Add a std::string attribute data and value.
    ///
    void AddString(unsigned Attribute, unsigned Form,
                   const std::string &String);
        
    /// AddLabel - Add a Dwarf label attribute data and value.
    ///
    void AddLabel(unsigned Attribute, unsigned Form, const DWLabel &Label);
        
    /// AddObjectLabel - Add a non-Dwarf label attribute data and value.
    ///
    void AddObjectLabel(unsigned Attribute, unsigned Form,
                        const std::string &Label);
        
    /// AddDelta - Add a label delta attribute data and value.
    ///
    void AddDelta(unsigned Attribute, unsigned Form,
                  const DWLabel &Hi, const DWLabel &Lo);
        
    ///  AddDIEntry - Add a DIE attribute data and value.
    ///
    void AddDIEntry(unsigned Attribute, unsigned Form, DIE *Entry);

    /// Complete - Indicate that all attributes have been added and
    /// ready to get an abbreviation ID.
    ///
    void Complete(DwarfWriter &DW);
    
    /// AddChild - Add a child to the DIE.
    void AddChild(DIE *Child);
  };
  
  //===--------------------------------------------------------------------===//
  // DwarfWriter - Emits Dwarf debug and exception handling directives.
  //
  class DwarfWriter {
  protected:
  
    //===------------------------------------------------------------------===//
    // Core attributes used by the Dwarf  writer.
    //
    
    //
    /// O - Stream to .s file.
    ///
    std::ostream &O;

    /// Asm - Target of Dwarf emission.
    ///
    AsmPrinter *Asm;
    
    /// DebugInfo - Collected debug information.
    ///
    MachineDebugInfo *DebugInfo;
    
    /// didInitial - Flag to indicate if initial emission has been done.
    ///
    bool didInitial;
    
    //===------------------------------------------------------------------===//
    // Attributes used to construct specific Dwarf sections.
    //
    
    /// CompileUnits - All the compile units involved in this build.  The index
    /// of each entry in this vector corresponds to the sources in DebugInfo.
    std::vector<DIE *> CompileUnits;

    /// Abbreviations - A UniqueVector of TAG structure abbreviations.
    ///
    UniqueVector<DIEAbbrev> Abbreviations;
    
    /// GlobalTypes - A map of globally visible named types.
    ///
    std::map<std::string, DIE *> GlobalTypes;
    
    /// GlobalEntities - A map of globally visible named entities.
    ///
    std::map<std::string, DIE *> GlobalEntities;
     
    /// StringPool - A UniqueVector of strings used by indirect references.
    ///
    UniqueVector<std::string> StringPool;
    
    /// DescToDieMap - Tracks the mapping of debug informaton descriptors to
    /// DIES.
    std::map<DebugInfoDesc *, DIE *> DescToDieMap;
    
    /// TypeToDieMap - Type to DIEType map.
    ///
    // FIXME - Should not be needed.
    std::map<Type *, DIE *> TypeToDieMap;
    
    //===------------------------------------------------------------------===//
    // Properties to be set by the derived class ctor, used to configure the
    // Dwarf writer.
    //
    
    /// AddressSize - Size of addresses used in file.
    ///
    unsigned AddressSize;

    /// hasLEB128 - True if target asm supports leb128 directives.
    ///
    bool hasLEB128; /// Defaults to false.
    
    /// hasDotLoc - True if target asm supports .loc directives.
    ///
    bool hasDotLoc; /// Defaults to false.
    
    /// hasDotFile - True if target asm supports .file directives.
    ///
    bool hasDotFile; /// Defaults to false.
    
    /// needsSet - True if target asm can't compute addresses on data
    /// directives.
    bool needsSet; /// Defaults to false.
    
    /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
    ///
    const char *DwarfAbbrevSection; /// Defaults to ".debug_abbrev".

    /// DwarfInfoSection - Section directive for Dwarf info.
    ///
    const char *DwarfInfoSection; /// Defaults to ".debug_info".

    /// DwarfLineSection - Section directive for Dwarf info.
    ///
    const char *DwarfLineSection; /// Defaults to ".debug_line".
    
    /// DwarfFrameSection - Section directive for Dwarf info.
    ///
    const char *DwarfFrameSection; /// Defaults to ".debug_frame".
    
    /// DwarfPubNamesSection - Section directive for Dwarf info.
    ///
    const char *DwarfPubNamesSection; /// Defaults to ".debug_pubnames".
    
    /// DwarfPubTypesSection - Section directive for Dwarf info.
    ///
    const char *DwarfPubTypesSection; /// Defaults to ".debug_pubtypes".
    
    /// DwarfStrSection - Section directive for Dwarf info.
    ///
    const char *DwarfStrSection; /// Defaults to ".debug_str".

    /// DwarfLocSection - Section directive for Dwarf info.
    ///
    const char *DwarfLocSection; /// Defaults to ".debug_loc".

    /// DwarfARangesSection - Section directive for Dwarf info.
    ///
    const char *DwarfARangesSection; /// Defaults to ".debug_aranges".

    /// DwarfRangesSection - Section directive for Dwarf info.
    ///
    const char *DwarfRangesSection; /// Defaults to ".debug_ranges".

    /// DwarfMacInfoSection - Section directive for Dwarf info.
    ///
    const char *DwarfMacInfoSection; /// Defaults to ".debug_macinfo".

    /// TextSection - Section directive for standard text.
    ///
    const char *TextSection; /// Defaults to ".text".
    
    /// DataSection - Section directive for standard data.
    ///
    const char *DataSection; /// Defaults to ".data".

    //===------------------------------------------------------------------===//
    // Emission and print routines
    //

public:
    /// getAddressSize - Return the size of a target address in bytes.
    ///
    unsigned getAddressSize() const { return AddressSize; }

    /// PrintHex - Print a value as a hexidecimal value.
    ///
    void PrintHex(int Value) const;

    /// EOL - Print a newline character to asm stream.  If a comment is present
    /// then it will be printed first.  Comments should not contain '\n'.
    void EOL(const std::string &Comment) const;
                                          
    /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
    /// unsigned leb128 value.
    void EmitULEB128Bytes(unsigned Value) const;
    
    /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
    /// signed leb128 value.
    void EmitSLEB128Bytes(int Value) const;
    
    /// PrintULEB128 - Print a series of hexidecimal values (separated by
    /// commas) representing an unsigned leb128 value.
    void PrintULEB128(unsigned Value) const;

    /// SizeULEB128 - Compute the number of bytes required for an unsigned
    /// leb128 value.
    static unsigned SizeULEB128(unsigned Value);
    
    /// PrintSLEB128 - Print a series of hexidecimal values (separated by
    /// commas) representing a signed leb128 value.
    void PrintSLEB128(int Value) const;
    
    /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
    /// value.
    static unsigned SizeSLEB128(int Value);
    
    /// EmitInt8 - Emit a byte directive and value.
    ///
    void EmitInt8(int Value) const;

    /// EmitInt16 - Emit a short directive and value.
    ///
    void EmitInt16(int Value) const;

    /// EmitInt32 - Emit a long directive and value.
    ///
    void EmitInt32(int Value) const;
    
    /// EmitInt64 - Emit a long long directive and value.
    ///
    void EmitInt64(uint64_t Value) const;
    
    /// EmitString - Emit a string with quotes and a null terminator.
    /// Special characters are emitted properly. (Eg. '\t')
    void EmitString(const std::string &String) const;

    /// PrintLabelName - Print label name in form used by Dwarf writer.
    ///
    void PrintLabelName(DWLabel Label) const {
      PrintLabelName(Label.Tag, Label.Number);
    }
    void PrintLabelName(const char *Tag, unsigned Number) const;
    
    /// EmitLabel - Emit location label for internal use by Dwarf.
    ///
    void EmitLabel(DWLabel Label) const {
      EmitLabel(Label.Tag, Label.Number);
    }
    void EmitLabel(const char *Tag, unsigned Number) const;
    
    /// EmitReference - Emit a reference to a label.
    ///
    void EmitReference(DWLabel Label) const {
      EmitReference(Label.Tag, Label.Number);
    }
    void EmitReference(const char *Tag, unsigned Number) const;
    void EmitReference(const std::string &Name) const;

    /// EmitDifference - Emit the difference between two labels.  Some
    /// assemblers do not behave with absolute expressions with data directives,
    /// so there is an option (needsSet) to use an intermediary set expression.
    void EmitDifference(DWLabel LabelHi, DWLabel LabelLo) const {
      EmitDifference(LabelHi.Tag, LabelHi.Number, LabelLo.Tag, LabelLo.Number);
    }
    void EmitDifference(const char *TagHi, unsigned NumberHi,
                        const char *TagLo, unsigned NumberLo) const;
                                   
    /// NewAbbreviation - Add the abbreviation to the Abbreviation vector.
    ///  
    unsigned NewAbbreviation(DIEAbbrev *Abbrev);
    
    /// NewString - Add a string to the constant pool and returns a label.
    ///
    DWLabel NewString(const std::string &String);
    
    /// NewBasicType - Creates a new basic type if necessary, then adds to the
    /// owner.
    /// FIXME - Should never be needed.
    DIE *NewBasicType(DIE *Owner, Type *Ty);

    /// NewGlobalType - Make the type visible globally using the given name.
    ///
    void NewGlobalType(const std::string &Name, DIE *Type);
    
    /// NewGlobalEntity - Make the entity visible globally using the given name.
    ///
    void NewGlobalEntity(const std::string &Name, DIE *Entity);

private:

    /// NewType - Create a new type DIE.
    ///
    DIE *NewType(DIE *Unit, TypeDesc *TyDesc);
    
    /// NewCompileUnit - Create new compile unit DIE.
    ///
    DIE *NewCompileUnit(CompileUnitDesc *CompileUnit);
    
    /// NewGlobalVariable - Make a new global variable DIE.
    ///
    DIE *NewGlobalVariable(GlobalVariableDesc *GVD);

    /// NewSubprogram - Add a new subprogram DIE.
    ///
    DIE *NewSubprogram(SubprogramDesc *SPD);

    /// EmitInitial - Emit initial Dwarf declarations.
    ///
    void EmitInitial() const;
    
    /// EmitDIE - Recusively Emits a debug information entry.
    ///
    void EmitDIE(DIE *Die) const;
    
    /// SizeAndOffsetDie - Compute the size and offset of a DIE.
    ///
    unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset);

    /// SizeAndOffsets - Compute the size and offset of all the DIEs.
    ///
    void SizeAndOffsets();
    
    /// EmitDebugInfo - Emit the debug info section.
    ///
    void EmitDebugInfo() const;
    
    /// EmitAbbreviations - Emit the abbreviation section.
    ///
    void EmitAbbreviations() const;
    
    /// EmitDebugLines - Emit source line information.
    ///
    void EmitDebugLines() const;

    /// EmitDebugFrame - Emit info into a debug frame section.
    ///
    void EmitDebugFrame();
    
    /// EmitDebugPubNames - Emit info into a debug pubnames section.
    ///
    void EmitDebugPubNames();
    
    /// EmitDebugPubTypes - Emit info into a debug pubtypes section.
    ///
    void EmitDebugPubTypes();
    
    /// EmitDebugStr - Emit info into a debug str section.
    ///
    void EmitDebugStr();
    
    /// EmitDebugLoc - Emit info into a debug loc section.
    ///
    void EmitDebugLoc();
    
    /// EmitDebugARanges - Emit info into a debug aranges section.
    ///
    void EmitDebugARanges();
    
    /// EmitDebugRanges - Emit info into a debug ranges section.
    ///
    void EmitDebugRanges();
    
    /// EmitDebugMacInfo - Emit info into a debug macinfo section.
    ///
    void EmitDebugMacInfo();
    
    /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
    /// header file.
    void ConstructCompileUnitDIEs();
    
    /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
    /// global variables.
    void ConstructGlobalDIEs(Module &M);

    /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
    /// subprograms.
    void ConstructSubprogramDIEs(Module &M);

    /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
    /// When called it also checks to see if debug info is newly available.  if
    /// so the initial Dwarf headers are emitted.
    bool ShouldEmitDwarf();
  
  public:
    
    DwarfWriter(std::ostream &OS, AsmPrinter *A);
    virtual ~DwarfWriter();
    
    /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
    /// created it.  Set by the target AsmPrinter.
    void SetDebugInfo(MachineDebugInfo *DI) { DebugInfo = DI; }

    //===------------------------------------------------------------------===//
    // Main entry points.
    //
    
    /// BeginModule - Emit all Dwarf sections that should come prior to the
    /// content.
    void BeginModule(Module &M);
    
    /// EndModule - Emit all Dwarf sections that should come after the content.
    ///
    void EndModule(Module &M);
    
    /// BeginFunction - Gather pre-function debug information.
    ///
    void BeginFunction(MachineFunction &MF);
    
    /// EndFunction - Gather and emit post-function debug information.
    ///
    void EndFunction(MachineFunction &MF);
  };

} // end llvm namespace

#endif