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