LLVM API Documentation
00001 //===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel 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 // Intel assembly code printer class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef X86INTELASMPRINTER_H 00015 #define X86INTELASMPRINTER_H 00016 00017 #include "../X86.h" 00018 #include "../X86MachineFunctionInfo.h" 00019 #include "../X86TargetMachine.h" 00020 #include "llvm/CodeGen/AsmPrinter.h" 00021 #include "llvm/ADT/StringSet.h" 00022 #include "llvm/Support/Compiler.h" 00023 #include "llvm/Support/raw_ostream.h" 00024 00025 namespace llvm { 00026 00027 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter { 00028 X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM, 00029 const TargetAsmInfo *T) 00030 : AsmPrinter(O, TM, T) { 00031 } 00032 00033 virtual const char *getPassName() const { 00034 return "X86 Intel-Style Assembly Printer"; 00035 } 00036 00037 /// printInstruction - This method is automatically generated by tablegen 00038 /// from the instruction set description. This method returns true if the 00039 /// machine instruction was sufficiently described to print it, otherwise it 00040 /// returns false. 00041 bool printInstruction(const MachineInstr *MI); 00042 00043 // This method is used by the tablegen'erated instruction printer. 00044 void printOperand(const MachineInstr *MI, unsigned OpNo, 00045 const char *Modifier = 0) { 00046 const MachineOperand &MO = MI->getOperand(OpNo); 00047 if (MO.isReg()) { 00048 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) && 00049 "Not physreg??"); 00050 O << TM.getRegisterInfo()->get(MO.getReg()).Name; // Capitalized names 00051 } else { 00052 printOp(MO, Modifier); 00053 } 00054 } 00055 00056 void printi8mem(const MachineInstr *MI, unsigned OpNo) { 00057 O << "BYTE PTR "; 00058 printMemReference(MI, OpNo); 00059 } 00060 void printi16mem(const MachineInstr *MI, unsigned OpNo) { 00061 O << "WORD PTR "; 00062 printMemReference(MI, OpNo); 00063 } 00064 void printi32mem(const MachineInstr *MI, unsigned OpNo) { 00065 O << "DWORD PTR "; 00066 printMemReference(MI, OpNo); 00067 } 00068 void printi64mem(const MachineInstr *MI, unsigned OpNo) { 00069 O << "QWORD PTR "; 00070 printMemReference(MI, OpNo); 00071 } 00072 void printi128mem(const MachineInstr *MI, unsigned OpNo) { 00073 O << "XMMWORD PTR "; 00074 printMemReference(MI, OpNo); 00075 } 00076 void printf32mem(const MachineInstr *MI, unsigned OpNo) { 00077 O << "DWORD PTR "; 00078 printMemReference(MI, OpNo); 00079 } 00080 void printf64mem(const MachineInstr *MI, unsigned OpNo) { 00081 O << "QWORD PTR "; 00082 printMemReference(MI, OpNo); 00083 } 00084 void printf80mem(const MachineInstr *MI, unsigned OpNo) { 00085 O << "XWORD PTR "; 00086 printMemReference(MI, OpNo); 00087 } 00088 void printf128mem(const MachineInstr *MI, unsigned OpNo) { 00089 O << "XMMWORD PTR "; 00090 printMemReference(MI, OpNo); 00091 } 00092 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { 00093 O << "QWORD PTR "; 00094 printMemReference(MI, OpNo, "subreg64"); 00095 } 00096 00097 bool printAsmMRegister(const MachineOperand &MO, const char Mode); 00098 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00099 unsigned AsmVariant, const char *ExtraCode); 00100 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 00101 unsigned AsmVariant, const char *ExtraCode); 00102 void printMachineInstruction(const MachineInstr *MI); 00103 void printOp(const MachineOperand &MO, const char *Modifier = 0); 00104 void printSSECC(const MachineInstr *MI, unsigned Op); 00105 void printMemReference(const MachineInstr *MI, unsigned Op, 00106 const char *Modifier=NULL); 00107 void printPICJumpTableSetLabel(unsigned uid, 00108 const MachineBasicBlock *MBB) const; 00109 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, 00110 const MachineBasicBlock *MBB) const { 00111 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); 00112 } 00113 void printPICLabel(const MachineInstr *MI, unsigned Op); 00114 bool runOnMachineFunction(MachineFunction &F); 00115 bool doInitialization(Module &M); 00116 bool doFinalization(Module &M); 00117 00118 // We have to propagate some information about MachineFunction to 00119 // AsmPrinter. It's ok, when we're printing the function, since we have 00120 // access to MachineFunction and can get the appropriate MachineFunctionInfo. 00121 // Unfortunately, this is not possible when we're printing reference to 00122 // Function (e.g. calling it and so on). Even more, there is no way to get the 00123 // corresponding MachineFunctions: it can even be not created at all. That's 00124 // why we should use additional structure, when we're collecting all necessary 00125 // information. 00126 // 00127 // This structure is using e.g. for name decoration for stdcall & fastcall'ed 00128 // function, since we have to use arguments' size for decoration. 00129 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; 00130 FMFInfoMap FunctionInfoMap; 00131 00132 void decorateName(std::string& Name, const GlobalValue* GV); 00133 00134 virtual void EmitString(const ConstantArray *CVA) const; 00135 00136 // Necessary for dllexport support 00137 StringSet<> DLLExportedFns, DLLExportedGVs; 00138 }; 00139 00140 } // end namespace llvm 00141 00142 #endif