Remove a bunch more SparcV9 specific stuff
[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     /// @fptr( ) link-relocation operator.
86     ///
87     const char *FunctionAddrPrefix;       // Defaults to ""
88     const char *FunctionAddrSuffix;       // Defaults to ""
89
90     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
91     /// emit before and after an inline assmebly statement.
92     const char *InlineAsmStart;           // Defaults to "#APP\n"
93     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
94     
95     //===--- Data Emission Directives -------------------------------------===//
96
97     /// ZeroDirective - this should be set to the directive used to get some
98     /// number of zero bytes emitted to the current section.  Common cases are
99     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
100     /// Data*bitsDirective's will be used to emit zero bytes.
101     const char *ZeroDirective;   // Defaults to "\t.zero\t"
102     const char *ZeroDirectiveSuffix;  // Defaults to ""
103
104     /// AsciiDirective - This directive allows emission of an ascii string with
105     /// the standard C escape characters embedded into it.
106     const char *AsciiDirective;  // Defaults to "\t.ascii\t"
107     
108     /// AscizDirective - If not null, this allows for special handling of
109     /// zero terminated strings on this target.  This is commonly supported as
110     /// ".asciz".  If a target doesn't support this, it can be set to null.
111     const char *AscizDirective;  // Defaults to "\t.asciz\t"
112
113     /// DataDirectives - These directives are used to output some unit of
114     /// integer data to the current section.  If a data directive is set to
115     /// null, smaller data directives will be used to emit the large sizes.
116     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
117     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
118     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
119     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
120
121     //===--- Alignment Information ----------------------------------------===//
122
123     /// AlignDirective - The directive used to emit round up to an alignment
124     /// boundary.
125     ///
126     const char *AlignDirective;       // Defaults to "\t.align\t"
127
128     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
129     /// emits ".align N" directives, where N is the number of bytes to align to.
130     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
131     /// boundary.
132     bool AlignmentIsInBytes;          // Defaults to true
133     
134     //===--- Section Switching Directives ---------------------------------===//
135     
136     /// SwitchToSectionDirective - This is the directive used when we want to
137     /// emit a global to an arbitrary section.  The section name is emited after
138     /// this.
139     const char *SwitchToSectionDirective;  // Defaults to "\t.section\t"
140     bool MLSections;  // True if Microsoft ML assembler is targetted
141     
142     /// ConstantPoolSection - This is the section that we SwitchToSection right
143     /// before emitting the constant pool for a function.
144     const char *ConstantPoolSection;     // Defaults to "\t.section .rodata\n"
145
146     /// JumpTableSection - This is the section that we SwitchToSection right
147     /// before emitting the jump tables for a function.
148     const char *JumpTableSection;     // Defaults to "\t.section .rodata\n"
149     
150     /// StaticCtorsSection - This is the directive that is emitted to switch to
151     /// a section to emit the static constructor list.
152     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
153     const char *StaticCtorsSection;
154
155     /// StaticDtorsSection - This is the directive that is emitted to switch to
156     /// a section to emit the static destructor list.
157     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
158     const char *StaticDtorsSection;
159     
160     //===--- Global Variable Emission Directives --------------------------===//
161     
162     /// LCOMMDirective - This is the name of a directive (if supported) that can
163     /// be used to efficiently declare a local (internal) block of zero
164     /// initialized data in the .bss/.data section.  The syntax expected is:
165     ///    <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
166     const char *LCOMMDirective;          // Defaults to null.
167     
168     const char *COMMDirective;           // Defaults to "\t.comm\t".
169     
170     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
171     /// argument that specifies the alignment of the declaration.
172     bool COMMDirectiveTakesAlignment;    // Defaults to true.
173     
174     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
175     /// directives, this is true for most ELF targets.
176     bool HasDotTypeDotSizeDirective;     // Defaults to true.
177   
178   protected:
179     AsmPrinter(std::ostream &o, TargetMachine &TM);
180     
181   public:
182     /// SwitchSection - Switch to the specified section of the executable if we
183     /// are not already in it!  If GV is non-null and if the global has an
184     /// explicitly requested section, we switch to the section indicated for the
185     /// global instead of NewSection.
186     ///
187     /// If the new section is an empty string, this method forgets what the
188     /// current section is, but does not emit a .section directive.
189     ///
190     void SwitchSection(const char *NewSection, const GlobalValue *GV);
191
192     /// getPreferredAlignmentLog - Return the preferred alignment of the
193     /// specified global, returned in log form.  This includes an explicitly
194     /// requested alignment (if the global has one).
195     unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
196   protected:
197     /// doInitialization - Set up the AsmPrinter when we are working on a new
198     /// module.  If your pass overrides this, it must make sure to explicitly
199     /// call this implementation.
200     bool doInitialization(Module &M);
201
202     /// doFinalization - Shut down the asmprinter.  If you override this in your
203     /// pass, you must make sure to call it explicitly.
204     bool doFinalization(Module &M);
205
206     /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
207     /// instruction, using the specified assembler variant.  Targets should
208     /// override this to format as appropriate.  This method can return true if
209     /// the operand is erroneous.
210     virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
211                                  unsigned AsmVariant, const char *ExtraCode);
212     
213     /// PrintAsmMemoryOperand - Print the specified operand of MI, an INLINEASM
214     /// instruction, using the specified assembler variant as an address.
215     /// Targets should override this to format as appropriate.  This method can
216     /// return true if the operand is erroneous.
217     virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
218                                        unsigned AsmVariant, 
219                                        const char *ExtraCode);
220     
221     /// SetupMachineFunction - This should be called when a new MachineFunction
222     /// is being processed from runOnMachineFunction.
223     void SetupMachineFunction(MachineFunction &MF);
224     
225     /// getFunctionNumber - Return a unique ID for the current function.
226     ///
227     unsigned getFunctionNumber() const { return FunctionNumber; }
228     
229     /// IncrementFunctionNumber - Increase Function Number.  AsmPrinters should
230     /// not normally call this, as the counter is automatically bumped by
231     /// SetupMachineFunction.
232     void IncrementFunctionNumber() { FunctionNumber++; }
233     
234     /// EmitConstantPool - Print to the current output stream assembly
235     /// representations of the constants in the constant pool MCP. This is
236     /// used to print out constants which have been "spilled to memory" by
237     /// the code generator.
238     ///
239     void EmitConstantPool(MachineConstantPool *MCP);
240
241     /// EmitJumpTableInfo - Print assembly representations of the jump tables 
242     /// used by the current function to the current output stream.  
243     ///
244     void EmitJumpTableInfo(MachineJumpTableInfo *MJTI);
245     
246     /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
247     /// special global used by LLVM.  If so, emit it and return true, otherwise
248     /// do nothing and return false.
249     bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
250
251     /// EmitAlignment - Emit an alignment directive to the specified power of
252     /// two boundary.  For example, if you pass in 3 here, you will get an 8
253     /// byte alignment.  If a global value is specified, and if that global has
254     /// an explicit alignment requested, it will override the alignment request.
255     void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const;
256
257     /// EmitZeros - Emit a block of zeros.
258     ///
259     void EmitZeros(uint64_t NumZeros) const;
260
261     /// EmitString - Emit a zero-byte-terminated string constant.
262     ///
263     virtual void EmitString(const ConstantArray *CVA) const;
264
265     /// EmitConstantValueOnly - Print out the specified constant, without a
266     /// storage class.  Only constants of first-class type are allowed here.
267     void EmitConstantValueOnly(const Constant *CV);
268
269     /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
270     ///
271     void EmitGlobalConstant(const Constant* CV);
272     
273     /// printInlineAsm - This method formats and prints the specified machine
274     /// instruction that is an inline asm.
275     void printInlineAsm(const MachineInstr *MI) const;
276     
277     /// printBasicBlockLabel - This method prints the label for the specified
278     /// MachineBasicBlock
279     virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
280                                       bool printColon = false,
281                                       bool printComment = true) const;
282     
283   private:
284     void EmitXXStructorList(Constant *List);
285
286   };
287 }
288
289 #endif