Add a couple more fields, move ctor init list to .cpp file, add support
[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 Mangler;
25   class GlobalVariable;
26
27   class AsmPrinter : public MachineFunctionPass {
28     /// CurrentSection - The current section we are emitting to.  This is
29     /// controlled and used by the SwitchSection method.
30     std::string CurrentSection;
31     
32     /// FunctionNumber - This provides a unique ID for each function emitted in
33     /// this translation unit.  It is autoincremented by SetupMachineFunction,
34     /// and can be accessed with getFunctionNumber() and 
35     /// IncrementFunctionNumber().
36     ///
37     unsigned FunctionNumber;
38     
39   protected:
40     /// Output stream on which we're printing assembly code.
41     ///
42     std::ostream &O;
43
44     /// Target machine description.
45     ///
46     TargetMachine &TM;
47
48     /// Name-mangler for global names.
49     ///
50     Mangler *Mang;
51
52     /// Cache of mangled name for current function. This is recalculated at the
53     /// beginning of each call to runOnMachineFunction().
54     ///
55     std::string CurrentFnName;
56
57     //===------------------------------------------------------------------===//
58     // Properties to be set by the derived class ctor, used to configure the
59     // asmwriter.
60
61     /// CommentString - This indicates the comment character used by the
62     /// assembler.
63     const char *CommentString;     // Defaults to "#"
64
65     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
66     /// onto all global symbols.  This is often used for "_" or ".".
67     const char *GlobalPrefix;    // Defaults to ""
68
69     /// PrivateGlobalPrefix - This prefix is used for globals like constant
70     /// pool entries that are completely private to the .o file and should not
71     /// have names in the .o file.  This is often "." or "L".
72     const char *PrivateGlobalPrefix;   // Defaults to "."
73     
74     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
75     /// will enclose any GlobalVariable (that isn't a function)
76     ///
77     const char *GlobalVarAddrPrefix;       // Defaults to ""
78     const char *GlobalVarAddrSuffix;       // Defaults to ""
79
80     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
81     /// will enclose any GlobalVariable that points to a function.
82     /// For example, this is used by the IA64 backend to materialize
83     /// function descriptors, by decorating the ".data8" object with the
84     /// @fptr( ) link-relocation operator.
85     ///
86     const char *FunctionAddrPrefix;       // Defaults to ""
87     const char *FunctionAddrSuffix;       // Defaults to ""
88
89     //===--- Data Emission Directives -------------------------------------===//
90
91     /// ZeroDirective - this should be set to the directive used to get some
92     /// number of zero bytes emitted to the current section.  Common cases are
93     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
94     /// Data*bitsDirective's will be used to emit zero bytes.
95     const char *ZeroDirective;   // Defaults to "\t.zero\t"
96
97     /// AsciiDirective - This directive allows emission of an ascii string with
98     /// the standard C escape characters embedded into it.
99     const char *AsciiDirective;  // Defaults to "\t.ascii\t"
100     
101     /// AscizDirective - If not null, this allows for special handling of
102     /// zero terminated strings on this target.  This is commonly supported as
103     /// ".asciz".  If a target doesn't support this, it can be set to null.
104     const char *AscizDirective;  // Defaults to "\t.asciz\t"
105
106     /// DataDirectives - These directives are used to output some unit of
107     /// integer data to the current section.  If a data directive is set to
108     /// null, smaller data directives will be used to emit the large sizes.
109     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
110     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
111     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
112     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
113
114     //===--- Alignment Information ----------------------------------------===//
115
116     /// AlignDirective - The directive used to emit round up to an alignment
117     /// boundary.
118     ///
119     const char *AlignDirective;       // Defaults to "\t.align\t"
120
121     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
122     /// emits ".align N" directives, where N is the number of bytes to align to.
123     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
124     /// boundary.
125     bool AlignmentIsInBytes;          // Defaults to true
126     
127     //===--- Section Switching Directives ---------------------------------===//
128     
129     /// SwitchToSectionDirective - This is the directive used when we want to
130     /// emit a global to an arbitrary section.  The section name is emited after
131     /// this.
132     const char *SwitchToSectionDirective;  // Defaults to "\t.section\t"
133     
134     /// ConstantPoolSection - This is the section that we SwitchToSection right
135     /// before emitting the constant pool for a function.
136     const char *ConstantPoolSection;     // Defaults to "\t.section .rodata\n"
137
138     /// StaticCtorsSection - This is the directive that is emitted to switch to
139     /// a section to emit the static constructor list.
140     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
141     const char *StaticCtorsSection;
142
143     /// StaticDtorsSection - This is the directive that is emitted to switch to
144     /// a section to emit the static destructor list.
145     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
146     const char *StaticDtorsSection;
147     
148     //===--- Global Variable Emission Directives --------------------------===//
149     
150     /// LCOMMDirective - This is the name of a directive (if supported) that can
151     /// be used to efficiently declare a local (internal) block of zero
152     /// initialized data in the .bss/.data section.  The syntax expected is:
153     ///    <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
154     const char *LCOMMDirective;          // Defaults to null.
155     
156     const char *COMMDirective;           // Defaults to "\t.comm\t".
157     
158     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
159     /// argument that specifies the alignment of the declaration.
160     bool COMMDirectiveTakesAlignment;    // Defaults to true.
161     
162     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
163     /// directives, this is true for most ELF targets.
164     bool HasDotTypeDotSizeDirective;     // Defaults to true.
165
166     AsmPrinter(std::ostream &o, TargetMachine &TM);
167     
168     /// SwitchSection - Switch to the specified section of the executable if we
169     /// are not already in it!  If GV is non-null and if the global has an
170     /// explicitly requested section, we switch to the section indicated for the
171     /// global instead of NewSection.
172     ///
173     /// If the new section is an empty string, this method forgets what the
174     /// current section is, but does not emit a .section directive.
175     ///
176     void SwitchSection(const char *NewSection, const GlobalValue *GV);
177
178     /// getFunctionNumber - Return a unique ID for the current function.
179     ///
180     unsigned getFunctionNumber() const { return FunctionNumber; }
181     
182     /// IncrementFunctionNumber - Increase Function Number.  AsmPrinters should
183     /// not normally call this, as the counter is automatically bumped by
184     /// SetupMachineFunction.
185     void IncrementFunctionNumber() { FunctionNumber++; }
186     
187     /// doInitialization - Set up the AsmPrinter when we are working on a new
188     /// module.  If your pass overrides this, it must make sure to explicitly
189     /// call this implementation.
190     bool doInitialization(Module &M);
191
192     /// doFinalization - Shut down the asmprinter.  If you override this in your
193     /// pass, you must make sure to call it explicitly.
194     bool doFinalization(Module &M);
195
196     /// SetupMachineFunction - This should be called when a new MachineFunction
197     /// is being processed from runOnMachineFunction.
198     void SetupMachineFunction(MachineFunction &MF);
199     
200     /// EmitConstantPool - Print to the current output stream assembly
201     /// representations of the constants in the constant pool MCP. This is
202     /// used to print out constants which have been "spilled to memory" by
203     /// the code generator.
204     ///
205     void EmitConstantPool(MachineConstantPool *MCP);
206
207     /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
208     /// special global used by LLVM.  If so, emit it and return true, otherwise
209     /// do nothing and return false.
210     bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
211
212     /// EmitAlignment - Emit an alignment directive to the specified power of
213     /// two boundary.  For example, if you pass in 3 here, you will get an 8
214     /// byte alignment.  If a global value is specified, and if that global has
215     /// an explicit alignment requested, it will override the alignment request.
216     void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const;
217
218     /// EmitZeros - Emit a block of zeros.
219     ///
220     void EmitZeros(uint64_t NumZeros) const;
221
222     /// EmitConstantValueOnly - Print out the specified constant, without a
223     /// storage class.  Only constants of first-class type are allowed here.
224     void EmitConstantValueOnly(const Constant *CV);
225
226     /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
227     ///
228     void EmitGlobalConstant(const Constant* CV);
229     
230   private:
231     void EmitXXStructorList(Constant *List);
232   };
233 }
234
235 #endif