I can't believe I caught this before Misha! :)
[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
26   class AsmPrinter : public MachineFunctionPass {
27   protected:
28     /// Output stream on which we're printing assembly code.
29     ///
30     std::ostream &O;
31
32     /// Target machine description.
33     ///
34     TargetMachine &TM;
35
36     /// Name-mangler for global names.
37     ///
38     Mangler *Mang;
39
40     /// Cache of mangled name for current function. This is recalculated at the
41     /// beginning of each call to runOnMachineFunction().
42     ///
43     std::string CurrentFnName;
44
45     //===------------------------------------------------------------------===//
46     // Properties to be set by the derived class ctor, used to configure the
47     // asmwriter.
48
49     /// CommentString - This indicates the comment character used by the
50     /// assembler.
51     const char *CommentString;     // Defaults to "#"
52
53     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
54     /// onto all global symbols.  This is often used for "_" or ".".
55     const char *GlobalPrefix;    // Defaults to ""
56
57     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
58     /// will enclose any GlobalVariable (that isn't a function)
59     ///
60     const char *GlobalVarAddrPrefix;       // Defaults to ""
61     const char *GlobalVarAddrSuffix;       // Defaults to ""
62
63     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
64     /// will enclose any GlobalVariable that points to a function.
65     /// For example, this is used by the IA64 backend to materialize
66     /// function descriptors, by decorating the ".data8" object with the
67     /// @fptr( ) link-relocation operator.
68     ///
69     const char *FunctionAddrPrefix;       // Defaults to ""
70     const char *FunctionAddrSuffix;       // Defaults to ""
71
72     /// ZeroDirective - this should be set to the directive used to get some
73     /// number of zero bytes emitted to the current section.  Common cases are
74     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
75     /// Data*bitsDirective's will be used to emit zero bytes.
76     const char *ZeroDirective;   // Defaults to "\t.zero\t"
77
78     /// AsciiDirective - This directive allows emission of an ascii string with
79     /// the standard C escape characters embedded into it.
80     const char *AsciiDirective;
81
82     /// DataDirectives - These directives are used to output some unit of
83     /// integer data to the current section.  If a data directive is set to
84     /// null, smaller data directives will be used to emit the large sizes.
85     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
86     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
87     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
88     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
89
90     /// AlignDirective - The directive used to emit round up to an alignment
91     /// boundary.
92     ///
93     const char *AlignDirective;       // Defaults to "\t.align\t"
94
95     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
96     /// emits ".align N" directives, where N is the number of bytes to align to.
97     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
98     /// boundary.
99     bool AlignmentIsInBytes;          // Defaults to true
100
101     AsmPrinter(std::ostream &o, TargetMachine &tm)
102       : O(o), TM(tm),
103         CommentString("#"),
104         GlobalPrefix(""),
105         GlobalVarAddrPrefix(""),
106         GlobalVarAddrSuffix(""),
107         FunctionAddrPrefix(""),
108         FunctionAddrSuffix(""),
109         ZeroDirective("\t.zero\t"),
110         AsciiDirective("\t.ascii\t"),
111         Data8bitsDirective("\t.byte\t"),
112         Data16bitsDirective("\t.short\t"),
113         Data32bitsDirective("\t.long\t"),
114         Data64bitsDirective("\t.quad\t"),
115         AlignDirective("\t.align\t"),
116         AlignmentIsInBytes(true) {
117     }
118
119     /// doInitialization - Set up the AsmPrinter when we are working on a new
120     /// module.  If your pass overrides this, it must make sure to explicitly
121     /// call this implementation.
122     bool doInitialization(Module &M);
123
124     /// doFinalization - Shut down the asmprinter.  If you override this in your
125     /// pass, you must make sure to call it explicitly.
126     bool doFinalization(Module &M);
127
128     /// setupMachineFunction - This should be called when a new MachineFunction
129     /// is being processed from runOnMachineFunction.
130     void setupMachineFunction(MachineFunction &MF);
131
132     /// emitAlignment - Emit an alignment directive to the specified power of
133     /// two boundary.  For example, if you pass in 3 here, you will get an 8
134     /// byte alignment.
135     void emitAlignment(unsigned NumBits) const;
136
137     /// emitZeros - Emit a block of zeros.
138     ///
139     void emitZeros(uint64_t NumZeros) const;
140
141     /// emitConstantValueOnly - Print out the specified constant, without a
142     /// storage class.  Only constants of first-class type are allowed here.
143     void emitConstantValueOnly(const Constant *CV);
144
145     /// emitGlobalConstant - Print a general LLVM constant to the .s file.
146     ///
147     void emitGlobalConstant(const Constant* CV);
148   };
149 }
150
151 #endif