LLVM API Documentation
00001 //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // AT&T assembly code printer class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef X86ATTASMPRINTER_H 00015 #define X86ATTASMPRINTER_H 00016 00017 #include "../X86.h" 00018 #include "../X86MachineFunctionInfo.h" 00019 #include "../X86TargetMachine.h" 00020 #include "llvm/ADT/StringSet.h" 00021 #include "llvm/CodeGen/AsmPrinter.h" 00022 #include "llvm/CodeGen/DwarfWriter.h" 00023 #include "llvm/CodeGen/MachineModuleInfo.h" 00024 #include "llvm/CodeGen/ValueTypes.h" 00025 #include "llvm/Support/Compiler.h" 00026 00027 namespace llvm { 00028 00029 class MachineJumpTableInfo; 00030 class MCContext; 00031 class MCInst; 00032 class MCOperand; 00033 class MCStreamer; 00034 class MCSymbol; 00035 00036 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { 00037 const X86Subtarget *Subtarget; 00038 public: 00039 explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM, 00040 const TargetAsmInfo *T, bool V) 00041 : AsmPrinter(O, TM, T, V) { 00042 Subtarget = &TM.getSubtarget<X86Subtarget>(); 00043 } 00044 00045 virtual const char *getPassName() const { 00046 return "X86 AT&T-Style Assembly Printer"; 00047 } 00048 00049 void getAnalysisUsage(AnalysisUsage &AU) const { 00050 AU.setPreservesAll(); 00051 if (Subtarget->isTargetDarwin() || 00052 Subtarget->isTargetELF() || 00053 Subtarget->isTargetCygMing()) { 00054 AU.addRequired<MachineModuleInfo>(); 00055 } 00056 AU.addRequired<DwarfWriter>(); 00057 AsmPrinter::getAnalysisUsage(AU); 00058 } 00059 00060 bool doFinalization(Module &M); 00061 00062 /// printInstruction - This method is automatically generated by tablegen 00063 /// from the instruction set description. This method returns true if the 00064 /// machine instruction was sufficiently described to print it, otherwise it 00065 /// returns false. 00066 void printInstruction(const MachineInstr *MI); 00067 00068 00069 // New MCInst printing stuff. 00070 void printInstruction(const MCInst *MI); 00071 MCSymbol *GetPICBaseSymbol(); 00072 MCOperand LowerGlobalAddressOperand(const MachineOperand &MO); 00073 MCOperand LowerExternalSymbolOperand(const MachineOperand &MO); 00074 00075 virtual void printMCInst(const MCInst *MI) { printInstruction(MI); } 00076 00077 void printSymbolOperand(const MachineOperand &MO); 00078 void printOperand(const MCInst *MI, unsigned OpNo, 00079 const char *Modifier = 0); 00080 void printMemReference(const MCInst *MI, unsigned Op); 00081 void printLeaMemReference(const MCInst *MI, unsigned Op); 00082 void printSSECC(const MCInst *MI, unsigned Op); 00083 void printPICLabel(const MCInst *MI, unsigned Op); 00084 void print_pcrel_imm(const MCInst *MI, unsigned OpNo); 00085 00086 void printi8mem(const MCInst *MI, unsigned OpNo) { 00087 printMemReference(MI, OpNo); 00088 } 00089 void printi16mem(const MCInst *MI, unsigned OpNo) { 00090 printMemReference(MI, OpNo); 00091 } 00092 void printi32mem(const MCInst *MI, unsigned OpNo) { 00093 printMemReference(MI, OpNo); 00094 } 00095 void printi64mem(const MCInst *MI, unsigned OpNo) { 00096 printMemReference(MI, OpNo); 00097 } 00098 void printi128mem(const MCInst *MI, unsigned OpNo) { 00099 printMemReference(MI, OpNo); 00100 } 00101 void printf32mem(const MCInst *MI, unsigned OpNo) { 00102 printMemReference(MI, OpNo); 00103 } 00104 void printf64mem(const MCInst *MI, unsigned OpNo) { 00105 printMemReference(MI, OpNo); 00106 } 00107 void printf80mem(const MCInst *MI, unsigned OpNo) { 00108 printMemReference(MI, OpNo); 00109 } 00110 void printf128mem(const MCInst *MI, unsigned OpNo) { 00111 printMemReference(MI, OpNo); 00112 } 00113 void printlea32mem(const MCInst *MI, unsigned OpNo) { 00114 printLeaMemReference(MI, OpNo); 00115 } 00116 void printlea64mem(const MCInst *MI, unsigned OpNo) { 00117 printLeaMemReference(MI, OpNo); 00118 } 00119 void printlea64_32mem(const MCInst *MI, unsigned OpNo) { 00120 printLeaMemReference(MI, OpNo); 00121 } 00122 00123 00124 00125 // These methods are used by the tablegen'erated instruction printer. 00126 void printOperand(const MachineInstr *MI, unsigned OpNo, 00127 const char *Modifier = 0); 00128 void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo); 00129 void printi8mem(const MachineInstr *MI, unsigned OpNo) { 00130 printMemReference(MI, OpNo); 00131 } 00132 void printi16mem(const MachineInstr *MI, unsigned OpNo) { 00133 printMemReference(MI, OpNo); 00134 } 00135 void printi32mem(const MachineInstr *MI, unsigned OpNo) { 00136 printMemReference(MI, OpNo); 00137 } 00138 void printi64mem(const MachineInstr *MI, unsigned OpNo) { 00139 printMemReference(MI, OpNo); 00140 } 00141 void printi128mem(const MachineInstr *MI, unsigned OpNo) { 00142 printMemReference(MI, OpNo); 00143 } 00144 void printi256mem(const MachineInstr *MI, unsigned OpNo) { 00145 printMemReference(MI, OpNo); 00146 } 00147 void printf32mem(const MachineInstr *MI, unsigned OpNo) { 00148 printMemReference(MI, OpNo); 00149 } 00150 void printf64mem(const MachineInstr *MI, unsigned OpNo) { 00151 printMemReference(MI, OpNo); 00152 } 00153 void printf80mem(const MachineInstr *MI, unsigned OpNo) { 00154 printMemReference(MI, OpNo); 00155 } 00156 void printf128mem(const MachineInstr *MI, unsigned OpNo) { 00157 printMemReference(MI, OpNo); 00158 } 00159 void printf256mem(const MachineInstr *MI, unsigned OpNo) { 00160 printMemReference(MI, OpNo); 00161 } 00162 void printlea32mem(const MachineInstr *MI, unsigned OpNo) { 00163 printLeaMemReference(MI, OpNo); 00164 } 00165 void printlea64mem(const MachineInstr *MI, unsigned OpNo) { 00166 printLeaMemReference(MI, OpNo); 00167 } 00168 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { 00169 printLeaMemReference(MI, OpNo, "subreg64"); 00170 } 00171 00172 bool printAsmMRegister(const MachineOperand &MO, char Mode); 00173 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00174 unsigned AsmVariant, const char *ExtraCode); 00175 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 00176 unsigned AsmVariant, const char *ExtraCode); 00177 00178 void printMachineInstruction(const MachineInstr *MI); 00179 void printSSECC(const MachineInstr *MI, unsigned Op); 00180 void printMemReference(const MachineInstr *MI, unsigned Op, 00181 const char *Modifier=NULL); 00182 void printLeaMemReference(const MachineInstr *MI, unsigned Op, 00183 const char *Modifier=NULL); 00184 void printPICJumpTableSetLabel(unsigned uid, 00185 const MachineBasicBlock *MBB) const; 00186 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, 00187 const MachineBasicBlock *MBB) const { 00188 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); 00189 } 00190 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, 00191 const MachineBasicBlock *MBB, 00192 unsigned uid) const; 00193 00194 void printPICLabel(const MachineInstr *MI, unsigned Op); 00195 void PrintGlobalVariable(const GlobalVariable* GVar); 00196 00197 void PrintPICBaseSymbol() const; 00198 00199 bool runOnMachineFunction(MachineFunction &F); 00200 00201 void emitFunctionHeader(const MachineFunction &MF); 00202 00203 // Necessary for Darwin to print out the apprioriate types of linker stubs 00204 StringMap<std::string> FnStubs, GVStubs, HiddenGVStubs; 00205 00206 // Necessary for dllexport support 00207 StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs; 00208 00209 // We have to propagate some information about MachineFunction to 00210 // AsmPrinter. It's ok, when we're printing the function, since we have 00211 // access to MachineFunction and can get the appropriate MachineFunctionInfo. 00212 // Unfortunately, this is not possible when we're printing reference to 00213 // Function (e.g. calling it and so on). Even more, there is no way to get the 00214 // corresponding MachineFunctions: it can even be not created at all. That's 00215 // why we should use additional structure, when we're collecting all necessary 00216 // information. 00217 // 00218 // This structure is using e.g. for name decoration for stdcall & fastcall'ed 00219 // function, since we have to use arguments' size for decoration. 00220 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; 00221 FMFInfoMap FunctionInfoMap; 00222 00223 void DecorateCygMingName(std::string &Name, const GlobalValue *GV); 00224 }; 00225 00226 } // end namespace llvm 00227 00228 #endif