mc'ize EmitLabel.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfPrinter.h
1 //===--- lib/CodeGen/DwarfPrinter.h - Dwarf Printer -------------*- C++ -*-===//
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 // Emit general DWARF directives.
11 // 
12 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_DWARFPRINTER_H__
15 #define CODEGEN_ASMPRINTER_DWARFPRINTER_H__
16
17 #include "llvm/CodeGen/MachineLocation.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/FormattedStream.h"
20 #include <vector>
21
22 namespace llvm {
23 class AsmPrinter;
24 class MachineFunction;
25 class MachineModuleInfo;
26 class Module;
27 class MCAsmInfo;
28 class TargetData;
29 class TargetRegisterInfo;
30 class GlobalValue;
31 class MCSymbol;
32 class Twine;
33
34 class DwarfPrinter {
35 protected:
36   ~DwarfPrinter() {}
37
38   //===-------------------------------------------------------------==---===//
39   // Core attributes used by the DWARF printer.
40   //
41
42   /// O - Stream to .s file.
43   raw_ostream &O;
44
45   /// Asm - Target of Dwarf emission.
46   AsmPrinter *Asm;
47
48   /// MAI - Target asm information.
49   const MCAsmInfo *MAI;
50
51   /// TD - Target data.
52   const TargetData *TD;
53
54   /// RI - Register Information.
55   const TargetRegisterInfo *RI;
56
57   /// M - Current module.
58   Module *M;
59
60   /// MF - Current machine function.
61   const MachineFunction *MF;
62
63   /// MMI - Collected machine module information.
64   MachineModuleInfo *MMI;
65
66   /// SubprogramCount - The running count of functions being compiled.
67   unsigned SubprogramCount;
68
69   /// Flavor - A unique string indicating what dwarf producer this is, used to
70   /// unique labels.
71   const char * const Flavor;
72
73   /// SetCounter - A unique number for each '.set' directive.
74   unsigned SetCounter;
75
76   DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
77                const char *flavor);
78 public:
79   
80   //===------------------------------------------------------------------===//
81   // Accessors.
82   //
83   const AsmPrinter *getAsm() const { return Asm; }
84   MachineModuleInfo *getMMI() const { return MMI; }
85   const MCAsmInfo *getMCAsmInfo() const { return MAI; }
86   const TargetData *getTargetData() const { return TD; }
87
88   /// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
89   /// label with the specified stem and unique ID.
90   MCSymbol *getDWLabel(const char *Name, unsigned ID) const;
91   
92   /// getTempLabel - Return an assembler temporary label with the specified
93   /// name.
94   MCSymbol *getTempLabel(const char *Name) const;
95
96   /// SizeOfEncodedValue - Return the size of the encoding in bytes.
97   unsigned SizeOfEncodedValue(unsigned Encoding) const;
98
99   void PrintRelDirective(unsigned Encoding) const;
100   void PrintRelDirective(bool Force32Bit = false,
101                          bool isInSection = false) const;
102
103   /// EOL - Print a newline character to asm stream.  If a comment is present
104   /// then it will be printed first.  Comments should not contain '\n'.
105   void EOL(const Twine &Comment) const;
106   
107   /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
108   /// encoding.  If verbose assembly output is enabled, we output comments
109   /// describing the encoding.  Desc is a string saying what the encoding is
110   /// specifying (e.g. "LSDA").
111   void EmitEncodingByte(unsigned Val, const char *Desc);
112   
113   /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
114   void EmitCFAByte(unsigned Val);
115   
116   
117   /// EmitSLEB128 - emit the specified signed leb128 value.
118   void EmitSLEB128(int Value, const char *Desc) const;
119
120   /// EmitULEB128 - emit the specified unsigned leb128 value.
121   void EmitULEB128(unsigned Value, const char *Desc = 0,
122                    unsigned PadTo = 0) const;
123
124   
125   /// PrintLabelName - Print label name in form used by Dwarf writer.
126   ///
127   void PrintLabelName(const MCSymbol *Label) const;
128   void PrintLabelName(const char *Tag, unsigned Number) const;
129   void PrintLabelName(const char *Tag, unsigned Number,
130                       const char *Suffix) const;
131
132   /// EmitReference - Emit a reference to a label.
133   ///
134   void EmitReference(const MCSymbol *Label, bool IsPCRelative = false,
135                      bool Force32Bit = false) const;
136   void EmitReference(const char *Tag, unsigned Number,
137                      bool IsPCRelative = false,
138                      bool Force32Bit = false) const;
139   void EmitReference(const std::string &Name, bool IsPCRelative = false,
140                      bool Force32Bit = false) const;
141
142   void EmitReference(const char *Tag, unsigned Number, unsigned Encoding) const;
143   void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
144   void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
145
146   /// EmitDifference - Emit the difference between two labels.
147   void EmitDifference(const MCSymbol *LabelHi, const MCSymbol *LabelLo,
148                       bool IsSmall = false);
149   void EmitDifference(const char *TagHi, unsigned NumberHi,
150                       const char *TagLo, unsigned NumberLo,
151                       bool IsSmall = false);
152
153   void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,
154                          bool IsSmall = false, bool isEH = false,
155                          bool useSet = true);
156   
157   /// EmitFrameMoves - Emit frame instructions to describe the layout of the
158   /// frame.
159   void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
160                       const std::vector<MachineMove> &Moves, bool isEH);
161 };
162
163 } // end llvm namespace
164
165 #endif