Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel assembly ----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Intel assembly code printer class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef X86INTELASMPRINTER_H |
| 15 | #define X86INTELASMPRINTER_H |
| 16 | |
Cédric Venet | 9612506 | 2008-08-17 18:24:26 +0000 | [diff] [blame] | 17 | #include "../X86.h" |
| 18 | #include "../X86MachineFunctionInfo.h" |
| 19 | #include "../X86TargetMachine.h" |
Anton Korobeynikov | 2e7832f | 2008-06-28 11:07:54 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/AsmPrinter.h" |
| 21 | #include "llvm/ADT/StringSet.h" |
| 22 | #include "llvm/Support/Compiler.h" |
Owen Anderson | 847b99b | 2008-08-21 00:14:44 +0000 | [diff] [blame^] | 23 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | |
Anton Korobeynikov | 2e7832f | 2008-06-28 11:07:54 +0000 | [diff] [blame] | 27 | struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter { |
Owen Anderson | 847b99b | 2008-08-21 00:14:44 +0000 | [diff] [blame^] | 28 | X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 29 | const TargetAsmInfo *T) |
Anton Korobeynikov | 2e7832f | 2008-06-28 11:07:54 +0000 | [diff] [blame] | 30 | : AsmPrinter(O, TM, T) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | virtual const char *getPassName() const { |
| 34 | return "X86 Intel-Style Assembly Printer"; |
| 35 | } |
| 36 | |
| 37 | /// printInstruction - This method is automatically generated by tablegen |
| 38 | /// from the instruction set description. This method returns true if the |
| 39 | /// machine instruction was sufficiently described to print it, otherwise it |
| 40 | /// returns false. |
| 41 | bool printInstruction(const MachineInstr *MI); |
| 42 | |
| 43 | // This method is used by the tablegen'erated instruction printer. |
| 44 | void printOperand(const MachineInstr *MI, unsigned OpNo, |
| 45 | const char *Modifier = 0) { |
| 46 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 47 | if (MO.isRegister()) { |
Dan Gohman | 1e57df3 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 48 | assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) && |
| 49 | "Not physreg??"); |
Evan Cheng | 00d04a7 | 2008-07-07 22:21:06 +0000 | [diff] [blame] | 50 | O << TM.getRegisterInfo()->get(MO.getReg()).Name; // Capitalized names |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 51 | } else { |
| 52 | printOp(MO, Modifier); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void printi8mem(const MachineInstr *MI, unsigned OpNo) { |
| 57 | O << "BYTE PTR "; |
| 58 | printMemReference(MI, OpNo); |
| 59 | } |
| 60 | void printi16mem(const MachineInstr *MI, unsigned OpNo) { |
| 61 | O << "WORD PTR "; |
| 62 | printMemReference(MI, OpNo); |
| 63 | } |
| 64 | void printi32mem(const MachineInstr *MI, unsigned OpNo) { |
| 65 | O << "DWORD PTR "; |
| 66 | printMemReference(MI, OpNo); |
| 67 | } |
| 68 | void printi64mem(const MachineInstr *MI, unsigned OpNo) { |
| 69 | O << "QWORD PTR "; |
| 70 | printMemReference(MI, OpNo); |
| 71 | } |
| 72 | void printi128mem(const MachineInstr *MI, unsigned OpNo) { |
| 73 | O << "XMMWORD PTR "; |
| 74 | printMemReference(MI, OpNo); |
| 75 | } |
| 76 | void printf32mem(const MachineInstr *MI, unsigned OpNo) { |
| 77 | O << "DWORD PTR "; |
| 78 | printMemReference(MI, OpNo); |
| 79 | } |
| 80 | void printf64mem(const MachineInstr *MI, unsigned OpNo) { |
| 81 | O << "QWORD PTR "; |
| 82 | printMemReference(MI, OpNo); |
| 83 | } |
Dale Johannesen | 4ab00bd | 2007-08-05 18:49:15 +0000 | [diff] [blame] | 84 | void printf80mem(const MachineInstr *MI, unsigned OpNo) { |
| 85 | O << "XWORD PTR "; |
| 86 | printMemReference(MI, OpNo); |
| 87 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 88 | void printf128mem(const MachineInstr *MI, unsigned OpNo) { |
| 89 | O << "XMMWORD PTR "; |
| 90 | printMemReference(MI, OpNo); |
| 91 | } |
| 92 | void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { |
| 93 | O << "QWORD PTR "; |
| 94 | printMemReference(MI, OpNo, "subreg64"); |
| 95 | } |
| 96 | |
| 97 | bool printAsmMRegister(const MachineOperand &MO, const char Mode); |
| 98 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 99 | unsigned AsmVariant, const char *ExtraCode); |
| 100 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 101 | unsigned AsmVariant, const char *ExtraCode); |
| 102 | void printMachineInstruction(const MachineInstr *MI); |
| 103 | void printOp(const MachineOperand &MO, const char *Modifier = 0); |
| 104 | void printSSECC(const MachineInstr *MI, unsigned Op); |
| 105 | void printMemReference(const MachineInstr *MI, unsigned Op, |
| 106 | const char *Modifier=NULL); |
Evan Cheng | 6fb0676 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 107 | void printPICJumpTableSetLabel(unsigned uid, |
| 108 | const MachineBasicBlock *MBB) const; |
| 109 | void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, |
| 110 | const MachineBasicBlock *MBB) const { |
| 111 | AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); |
| 112 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 113 | void printPICLabel(const MachineInstr *MI, unsigned Op); |
| 114 | bool runOnMachineFunction(MachineFunction &F); |
| 115 | bool doInitialization(Module &M); |
| 116 | bool doFinalization(Module &M); |
Anton Korobeynikov | 2e7832f | 2008-06-28 11:07:54 +0000 | [diff] [blame] | 117 | |
| 118 | // We have to propagate some information about MachineFunction to |
| 119 | // AsmPrinter. It's ok, when we're printing the function, since we have |
| 120 | // access to MachineFunction and can get the appropriate MachineFunctionInfo. |
| 121 | // Unfortunately, this is not possible when we're printing reference to |
| 122 | // Function (e.g. calling it and so on). Even more, there is no way to get the |
| 123 | // corresponding MachineFunctions: it can even be not created at all. That's |
| 124 | // why we should use additional structure, when we're collecting all necessary |
| 125 | // information. |
| 126 | // |
| 127 | // This structure is using e.g. for name decoration for stdcall & fastcall'ed |
| 128 | // function, since we have to use arguments' size for decoration. |
| 129 | typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; |
| 130 | FMFInfoMap FunctionInfoMap; |
| 131 | |
| 132 | void decorateName(std::string& Name, const GlobalValue* GV); |
| 133 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 134 | /// getSectionForFunction - Return the section that we should emit the |
| 135 | /// specified function body into. |
| 136 | virtual std::string getSectionForFunction(const Function &F) const; |
| 137 | |
| 138 | virtual void EmitString(const ConstantArray *CVA) const; |
Anton Korobeynikov | 2e7832f | 2008-06-28 11:07:54 +0000 | [diff] [blame] | 139 | |
| 140 | // Necessary for dllexport support |
| 141 | StringSet<> DLLExportedFns, DLLExportedGVs; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | } // end namespace llvm |
| 145 | |
| 146 | #endif |