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 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
58 /// will enclose any GlobalVariable (that isn't a function)
60 const char *GlobalVarAddrPrefix; // Defaults to ""
61 const char *GlobalVarAddrSuffix; // Defaults to ""
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.
69 const char *FunctionAddrPrefix; // Defaults to ""
70 const char *FunctionAddrSuffix; // Defaults to ""
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"
78 /// AsciiDirective - This directive allows emission of an ascii string with
79 /// the standard C escape characters embedded into it.
80 const char *AsciiDirective;
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"
90 /// AlignDirective - The directive used to emit round up to an alignment
93 const char *AlignDirective; // Defaults to "\t.align\t"
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
99 bool AlignmentIsInBytes; // Defaults to true
101 AsmPrinter(std::ostream &o, TargetMachine &tm)
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) {
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);
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);
128 /// setupMachineFunction - This should be called when a new MachineFunction
129 /// is being processed from runOnMachineFunction.
130 void setupMachineFunction(MachineFunction &MF);
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
135 void emitAlignment(unsigned NumBits) const;
137 /// emitZeros - Emit a block of zeros.
139 void emitZeros(uint64_t NumZeros) const;
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);
145 /// emitGlobalConstant - Print a general LLVM constant to the .s file.
147 void emitGlobalConstant(const Constant* CV);