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