LLVM API Documentation

X86IntelAsmPrinter.h

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