Fix some doxygen usage in these headers.
[oota-llvm.git] / include / llvm / CodeGen / AsmPrinter.h
1 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class is intended to be used as a base class for target-specific
11 // asmwriters.  This class primarily takes care of printing global constants,
12 // which are printed in a very similar way across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_ASMPRINTER_H
17 #define LLVM_CODEGEN_ASMPRINTER_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23   class Constant;
24   class ConstantArray;
25   class Mangler;
26   class GlobalVariable;
27
28   class AsmPrinter : public MachineFunctionPass {
29     /// CurrentSection - The current section we are emitting to.  This is
30     /// controlled and used by the SwitchSection method.
31     std::string CurrentSection;
32     
33     /// FunctionNumber - This provides a unique ID for each function emitted in
34     /// this translation unit.  It is autoincremented by SetupMachineFunction,
35     /// and can be accessed with getFunctionNumber() and 
36     /// IncrementFunctionNumber().
37     ///
38     unsigned FunctionNumber;
39
40   public:
41     /// Output stream on which we're printing assembly code.
42     ///
43     std::ostream &O;
44
45     /// Target machine description.
46     ///
47     TargetMachine &TM;
48
49     /// Name-mangler for global names.
50     ///
51     Mangler *Mang;
52
53     /// Cache of mangled name for current function. This is recalculated at the
54     /// beginning of each call to runOnMachineFunction().
55     ///
56     std::string CurrentFnName;
57
58     //===------------------------------------------------------------------===//
59     // Properties to be set by the derived class ctor, used to configure the
60     // asmwriter.
61
62     /// CommentString - This indicates the comment character used by the
63     /// assembler.
64     const char *CommentString;     // Defaults to "#"
65
66     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
67     /// onto all global symbols.  This is often used for "_" or ".".
68     const char *GlobalPrefix;    // Defaults to ""
69
70     /// PrivateGlobalPrefix - This prefix is used for globals like constant
71     /// pool entries that are completely private to the .o file and should not
72     /// have names in the .o file.  This is often "." or "L".
73     const char *PrivateGlobalPrefix;   // Defaults to "."
74     
75     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
76     /// will enclose any GlobalVariable (that isn't a function)
77     ///
78     const char *GlobalVarAddrPrefix;       // Defaults to ""
79     const char *GlobalVarAddrSuffix;       // Defaults to ""
80
81     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
82     /// will enclose any GlobalVariable that points to a function.
83     /// For example, this is used by the IA64 backend to materialize
84     /// function descriptors, by decorating the ".data8" object with the
85     /// \literal @fptr( ) \endliteral
86     /// link-relocation operator.
87     ///
88     const char *FunctionAddrPrefix;       // Defaults to ""
89     const char *FunctionAddrSuffix;       // Defaults to ""
90
91     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
92     /// emit before and after an inline assmebly statement.
93     const char *InlineAsmStart;           // Defaults to "#APP\n"
94     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
95     
96     //===--- Data Emission Directives -------------------------------------===//
97
98     /// ZeroDirective - this should be set to the directive used to get some
99     /// number of zero bytes emitted to the current section.  Common cases are
100     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
101     /// Data*bitsDirective's will be used to emit zero bytes.
102     const char *ZeroDirective;   // Defaults to "\t.zero\t"
103     const char *ZeroDirectiveSuffix;  // Defaults to ""
104
105     /// AsciiDirective - This directive allows emission of an ascii string with
106     /// the standard C escape characters embedded into it.
107     const char *AsciiDirective;  // Defaults to "\t.ascii\t"
108     
109     /// AscizDirective - If not null, this allows for special handling of
110     /// zero terminated strings on this target.  This is commonly supported as
111     /// ".asciz".  If a target doesn't support this, it can be set to null.
112     const char *AscizDirective;  // Defaults to "\t.asciz\t"
113
114     /// DataDirectives - These directives are used to output some unit of
115     /// integer data to the current section.  If a data directive is set to
116     /// null, smaller data directives will be used to emit the large sizes.
117     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
118     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
119     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
120     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
121
122     //===--- Alignment Information ----------------------------------------===//
123
124     /// AlignDirective - The directive used to emit round up to an alignment
125     /// boundary.
126     ///
127     const char *AlignDirective;       // Defaults to "\t.align\t"
128
129     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
130     /// emits ".align N" directives, where N is the number of bytes to align to.
131     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
132     /// boundary.
133     bool AlignmentIsInBytes;          // Defaults to true
134     
135     //===--- Section Switching Directives ---------------------------------===//
136     
137     /// SwitchToSectionDirective - This is the directive used when we want to
138     /// emit a global to an arbitrary section.  The section name is emited after
139     /// this.
140     const char *SwitchToSectionDirective;  // Defaults to "\t.section\t"
141     
142     /// TextSectionStartSuffix - This is printed after each start of section
143     /// directive for text sections.
144     const char *TextSectionStartSuffix;        // Defaults to "".
145
146     /// DataSectionStartSuffix - This is printed after each start of section
147     /// directive for data sections.
148     const char *DataSectionStartSuffix;        // Defaults to "".
149     
150     /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
151     /// section with the section name and this suffix printed.
152     const char *SectionEndDirectiveSuffix; // Defaults to null.
153     
154     /// ConstantPoolSection - This is the section that we SwitchToSection right
155     /// before emitting the constant pool for a function.
156     const char *ConstantPoolSection;     // Defaults to "\t.section .rodata\n"
157
158     /// JumpTableSection - This is the section that we SwitchToSection right
159     /// before emitting the jump tables for a function.
160     const char *JumpTableSection;     // Defaults to "\t.section .rodata\n"
161     
162     /// StaticCtorsSection - This is the directive that is emitted to switch to
163     /// a section to emit the static constructor list.
164     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
165     const char *StaticCtorsSection;
166
167     /// StaticDtorsSection - This is the directive that is emitted to switch to
168     /// a section to emit the static destructor list.
169     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
170     const char *StaticDtorsSection;
171     
172     //===--- Global Variable Emission Directives --------------------------===//
173     
174     /// LCOMMDirective - This is the name of a directive (if supported) that can
175     /// be used to efficiently declare a local (internal) block of zero
176     /// initialized data in the .bss/.data section.  The syntax expected is:
177     /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
178     /// \endliteral
179     const char *LCOMMDirective;          // Defaults to null.
180     
181     const char *COMMDirective;           // Defaults to "\t.comm\t".
182     
183     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
184     /// argument that specifies the alignment of the declaration.
185     bool COMMDirectiveTakesAlignment;    // Defaults to true.
186     
187     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
188     /// directives, this is true for most ELF targets.
189     bool HasDotTypeDotSizeDirective;     // Defaults to true.
190   
191   protected:
192     AsmPrinter(std::ostream &o, TargetMachine &TM);
193     
194   public:
195     /// SwitchToTextSection - Switch to the specified section of the executable
196     /// if we are not already in it!  If GV is non-null and if the global has an
197     /// explicitly requested section, we switch to the section indicated for the
198     /// global instead of NewSection.
199     ///
200     /// If the new section is an empty string, this method forgets what the
201     /// current section is, but does not emit a .section directive.
202     ///
203     /// This method is used when about to emit executable code.
204     ///
205     void SwitchToTextSection(const char *NewSection, const GlobalValue *GV);
206
207     /// SwitchToDataSection - Switch to the specified section of the executable
208     /// if we are not already in it!  If GV is non-null and if the global has an
209     /// explicitly requested section, we switch to the section indicated for the
210     /// global instead of NewSection.
211     ///
212     /// If the new section is an empty string, this method forgets what the
213     /// current section is, but does not emit a .section directive.
214     ///
215     /// This method is used when about to emit data.  For most assemblers, this
216     /// is the same as the SwitchToTextSection method, but not all assemblers
217     /// are the same.
218     ///
219     void SwitchToDataSection(const char *NewSection, const GlobalValue *GV);
220     
221     /// getPreferredAlignmentLog - Return the preferred alignment of the
222     /// specified global, returned in log form.  This includes an explicitly
223     /// requested alignment (if the global has one).
224     unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
225   protected:
226     /// doInitialization - Set up the AsmPrinter when we are working on a new
227     /// module.  If your pass overrides this, it must make sure to explicitly
228     /// call this implementation.
229     bool doInitialization(Module &M);
230
231     /// doFinalization - Shut down the asmprinter.  If you override this in your
232     /// pass, you must make sure to call it explicitly.
233     bool doFinalization(Module &M);
234
235     /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
236     /// instruction, using the specified assembler variant.  Targets should
237     /// override this to format as appropriate.  This method can return true if
238     /// the operand is erroneous.
239     virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
240                                  unsigned AsmVariant, const char *ExtraCode);
241     
242     /// PrintAsmMemoryOperand - Print the specified operand of MI, an INLINEASM
243     /// instruction, using the specified assembler variant as an address.
244     /// Targets should override this to format as appropriate.  This method can
245     /// return true if the operand is erroneous.
246     virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
247                                        unsigned AsmVariant, 
248                                        const char *ExtraCode);
249     
250     /// SetupMachineFunction - This should be called when a new MachineFunction
251     /// is being processed from runOnMachineFunction.
252     void SetupMachineFunction(MachineFunction &MF);
253     
254     /// getFunctionNumber - Return a unique ID for the current function.
255     ///
256     unsigned getFunctionNumber() const { return FunctionNumber; }
257     
258     /// IncrementFunctionNumber - Increase Function Number.  AsmPrinters should
259     /// not normally call this, as the counter is automatically bumped by
260     /// SetupMachineFunction.
261     void IncrementFunctionNumber() { FunctionNumber++; }
262     
263     /// EmitConstantPool - Print to the current output stream assembly
264     /// representations of the constants in the constant pool MCP. This is
265     /// used to print out constants which have been "spilled to memory" by
266     /// the code generator.
267     ///
268     void EmitConstantPool(MachineConstantPool *MCP);
269
270     /// EmitJumpTableInfo - Print assembly representations of the jump tables 
271     /// used by the current function to the current output stream.  
272     ///
273     void EmitJumpTableInfo(MachineJumpTableInfo *MJTI);
274     
275     /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
276     /// special global used by LLVM.  If so, emit it and return true, otherwise
277     /// do nothing and return false.
278     bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
279
280     /// EmitAlignment - Emit an alignment directive to the specified power of
281     /// two boundary.  For example, if you pass in 3 here, you will get an 8
282     /// byte alignment.  If a global value is specified, and if that global has
283     /// an explicit alignment requested, it will override the alignment request.
284     void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const;
285
286     /// EmitZeros - Emit a block of zeros.
287     ///
288     void EmitZeros(uint64_t NumZeros) const;
289
290     /// EmitString - Emit a zero-byte-terminated string constant.
291     ///
292     virtual void EmitString(const ConstantArray *CVA) const;
293
294     /// EmitConstantValueOnly - Print out the specified constant, without a
295     /// storage class.  Only constants of first-class type are allowed here.
296     void EmitConstantValueOnly(const Constant *CV);
297
298     /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
299     ///
300     void EmitGlobalConstant(const Constant* CV);
301     
302     /// printInlineAsm - This method formats and prints the specified machine
303     /// instruction that is an inline asm.
304     void printInlineAsm(const MachineInstr *MI) const;
305     
306     /// printBasicBlockLabel - This method prints the label for the specified
307     /// MachineBasicBlock
308     virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
309                                       bool printColon = false,
310                                       bool printComment = true) const;
311     
312   private:
313     void EmitXXStructorList(Constant *List);
314
315   };
316 }
317
318 #endif