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 struct MachineJumpTableInfo; 00030 00031 struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { 00032 DwarfWriter DW; 00033 MachineModuleInfo *MMI; 00034 00035 const X86Subtarget *Subtarget; 00036 00037 X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM, 00038 const TargetAsmInfo *T) 00039 : AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) { 00040 Subtarget = &TM.getSubtarget<X86Subtarget>(); 00041 } 00042 00043 virtual const char *getPassName() const { 00044 return "X86 AT&T-Style Assembly Printer"; 00045 } 00046 00047 void getAnalysisUsage(AnalysisUsage &AU) const { 00048 AU.setPreservesAll(); 00049 if (Subtarget->isTargetDarwin() || 00050 Subtarget->isTargetELF() || 00051 Subtarget->isTargetCygMing()) { 00052 AU.addRequired<MachineModuleInfo>(); 00053 } 00054 AsmPrinter::getAnalysisUsage(AU); 00055 } 00056 00057 bool doInitialization(Module &M); 00058 bool doFinalization(Module &M); 00059 00060 /// printInstruction - This method is automatically generated by tablegen 00061 /// from the instruction set description. This method returns true if the 00062 /// machine instruction was sufficiently described to print it, otherwise it 00063 /// returns false. 00064 bool printInstruction(const MachineInstr *MI); 00065 00066 // These methods are used by the tablegen'erated instruction printer. 00067 void printOperand(const MachineInstr *MI, unsigned OpNo, 00068 const char *Modifier = 0, bool NotRIPRel = false); 00069 void printi8mem(const MachineInstr *MI, unsigned OpNo) { 00070 printMemReference(MI, OpNo); 00071 } 00072 void printi16mem(const MachineInstr *MI, unsigned OpNo) { 00073 printMemReference(MI, OpNo); 00074 } 00075 void printi32mem(const MachineInstr *MI, unsigned OpNo) { 00076 printMemReference(MI, OpNo); 00077 } 00078 void printi64mem(const MachineInstr *MI, unsigned OpNo) { 00079 printMemReference(MI, OpNo); 00080 } 00081 void printi128mem(const MachineInstr *MI, unsigned OpNo) { 00082 printMemReference(MI, OpNo); 00083 } 00084 void printf32mem(const MachineInstr *MI, unsigned OpNo) { 00085 printMemReference(MI, OpNo); 00086 } 00087 void printf64mem(const MachineInstr *MI, unsigned OpNo) { 00088 printMemReference(MI, OpNo); 00089 } 00090 void printf80mem(const MachineInstr *MI, unsigned OpNo) { 00091 printMemReference(MI, OpNo); 00092 } 00093 void printf128mem(const MachineInstr *MI, unsigned OpNo) { 00094 printMemReference(MI, OpNo); 00095 } 00096 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { 00097 printMemReference(MI, OpNo, "subreg64"); 00098 } 00099 00100 bool printAsmMRegister(const MachineOperand &MO, const char Mode); 00101 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00102 unsigned AsmVariant, const char *ExtraCode); 00103 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 00104 unsigned AsmVariant, const char *ExtraCode); 00105 00106 void printMachineInstruction(const MachineInstr *MI); 00107 void printSSECC(const MachineInstr *MI, unsigned Op); 00108 void printMemReference(const MachineInstr *MI, unsigned Op, 00109 const char *Modifier=NULL); 00110 void printPICJumpTableSetLabel(unsigned uid, 00111 const MachineBasicBlock *MBB) const; 00112 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, 00113 const MachineBasicBlock *MBB) const { 00114 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); 00115 } 00116 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, 00117 const MachineBasicBlock *MBB, 00118 unsigned uid) const; 00119 00120 void printPICLabel(const MachineInstr *MI, unsigned Op); 00121 void printModuleLevelGV(const GlobalVariable* GVar); 00122 00123 void printGVStub(const char *GV, const char *Prefix = NULL); 00124 00125 bool runOnMachineFunction(MachineFunction &F); 00126 00127 /// getSectionForFunction - Return the section that we should emit the 00128 /// specified function body into. 00129 virtual std::string getSectionForFunction(const Function &F) const; 00130 00131 void emitFunctionHeader(const MachineFunction &MF); 00132 00133 // Necessary for Darwin to print out the apprioriate types of linker stubs 00134 StringSet<> FnStubs, GVStubs, LinkOnceStubs; 00135 00136 // Necessary for dllexport support 00137 StringSet<> DLLExportedFns, DLLExportedGVs; 00138 00139 // We have to propagate some information about MachineFunction to 00140 // AsmPrinter. It's ok, when we're printing the function, since we have 00141 // access to MachineFunction and can get the appropriate MachineFunctionInfo. 00142 // Unfortunately, this is not possible when we're printing reference to 00143 // Function (e.g. calling it and so on). Even more, there is no way to get the 00144 // corresponding MachineFunctions: it can even be not created at all. That's 00145 // why we should use additional structure, when we're collecting all necessary 00146 // information. 00147 // 00148 // This structure is using e.g. for name decoration for stdcall & fastcall'ed 00149 // function, since we have to use arguments' size for decoration. 00150 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; 00151 FMFInfoMap FunctionInfoMap; 00152 00153 void decorateName(std::string& Name, const GlobalValue* GV); 00154 }; 00155 00156 } // end namespace llvm 00157 00158 #endif