1 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_ASMPRINTER_H
17 #define LLVM_CODEGEN_ASMPRINTER_H
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
26 class AsmPrinter : public MachineFunctionPass {
28 /// Output stream on which we're printing assembly code.
32 /// Target machine description.
36 /// Name-mangler for global names.
40 /// Cache of mangled name for current function. This is recalculated at the
41 /// beginning of each call to runOnMachineFunction().
43 std::string CurrentFnName;
45 //===------------------------------------------------------------------===//
46 // Properties to be set by the derived class ctor, used to configure the
49 /// CommentString - This indicates the comment character used by the
51 const char *CommentString; // Defaults to "#"
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 ""
57 /// PrivateGlobalPrefix - This prefix is used for globals like constant
58 /// pool entries that are completely private to the .o file and should not
59 /// have names in the .o file. This is often "." or "L".
60 const char *PrivateGlobalPrefix; // Defaults to "."
62 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
63 /// will enclose any GlobalVariable (that isn't a function)
65 const char *GlobalVarAddrPrefix; // Defaults to ""
66 const char *GlobalVarAddrSuffix; // Defaults to ""
68 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
69 /// will enclose any GlobalVariable that points to a function.
70 /// For example, this is used by the IA64 backend to materialize
71 /// function descriptors, by decorating the ".data8" object with the
72 /// @fptr( ) link-relocation operator.
74 const char *FunctionAddrPrefix; // Defaults to ""
75 const char *FunctionAddrSuffix; // Defaults to ""
77 /// ZeroDirective - this should be set to the directive used to get some
78 /// number of zero bytes emitted to the current section. Common cases are
79 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
80 /// Data*bitsDirective's will be used to emit zero bytes.
81 const char *ZeroDirective; // Defaults to "\t.zero\t"
83 /// AsciiDirective - This directive allows emission of an ascii string with
84 /// the standard C escape characters embedded into it.
85 const char *AsciiDirective; // Defaults to "\t.ascii\t"
87 /// AscizDirective - If not null, this allows for special handling of
88 /// zero terminated strings on this target. This is commonly supported as
89 /// ".asciz". If a target doesn't support this, it can be set to null.
90 const char *AscizDirective; // Defaults to "\t.asciz\t"
92 /// DataDirectives - These directives are used to output some unit of
93 /// integer data to the current section. If a data directive is set to
94 /// null, smaller data directives will be used to emit the large sizes.
95 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
96 const char *Data16bitsDirective; // Defaults to "\t.short\t"
97 const char *Data32bitsDirective; // Defaults to "\t.long\t"
98 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
100 /// AlignDirective - The directive used to emit round up to an alignment
103 const char *AlignDirective; // Defaults to "\t.align\t"
105 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
106 /// emits ".align N" directives, where N is the number of bytes to align to.
107 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
109 bool AlignmentIsInBytes; // Defaults to true
111 AsmPrinter(std::ostream &o, TargetMachine &tm)
115 PrivateGlobalPrefix("."),
116 GlobalVarAddrPrefix(""),
117 GlobalVarAddrSuffix(""),
118 FunctionAddrPrefix(""),
119 FunctionAddrSuffix(""),
120 ZeroDirective("\t.zero\t"),
121 AsciiDirective("\t.ascii\t"),
122 AscizDirective("\t.asciz\t"),
123 Data8bitsDirective("\t.byte\t"),
124 Data16bitsDirective("\t.short\t"),
125 Data32bitsDirective("\t.long\t"),
126 Data64bitsDirective("\t.quad\t"),
127 AlignDirective("\t.align\t"),
128 AlignmentIsInBytes(true) {
131 /// doInitialization - Set up the AsmPrinter when we are working on a new
132 /// module. If your pass overrides this, it must make sure to explicitly
133 /// call this implementation.
134 bool doInitialization(Module &M);
136 /// doFinalization - Shut down the asmprinter. If you override this in your
137 /// pass, you must make sure to call it explicitly.
138 bool doFinalization(Module &M);
140 /// setupMachineFunction - This should be called when a new MachineFunction
141 /// is being processed from runOnMachineFunction.
142 void setupMachineFunction(MachineFunction &MF);
144 /// emitAlignment - Emit an alignment directive to the specified power of
145 /// two boundary. For example, if you pass in 3 here, you will get an 8
146 /// byte alignment. If a global value is specified, and if that global has
147 /// an explicit alignment requested, it will override the alignment request.
148 void emitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const;
150 /// emitZeros - Emit a block of zeros.
152 void emitZeros(uint64_t NumZeros) const;
154 /// emitConstantValueOnly - Print out the specified constant, without a
155 /// storage class. Only constants of first-class type are allowed here.
156 void emitConstantValueOnly(const Constant *CV);
158 /// emitGlobalConstant - Print a general LLVM constant to the .s file.
160 void emitGlobalConstant(const Constant* CV);