Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 1 | //===-- X86/Printer.cpp - Convert X86 code to human readable rep. ---------===// |
| 2 | // |
| 3 | // This file contains a printer that converts from our internal representation |
| 4 | // of LLVM code to a nice human readable form that is suitable for debuggging. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | #include "X86.h" |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 9 | #include "X86InstrInfo.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 10 | #include "llvm/Pass.h" |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 11 | #include "llvm/Function.h" |
| 12 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | dbb61c6 | 2002-11-17 22:53:13 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 233ad71 | 2002-11-21 01:33:44 +0000 | [diff] [blame] | 15 | #include "Support/Statistic.h" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 16 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 17 | namespace { |
| 18 | struct Printer : public FunctionPass { |
| 19 | TargetMachine &TM; |
| 20 | std::ostream &O; |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 21 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 22 | Printer(TargetMachine &tm, std::ostream &o) : TM(tm), O(o) {} |
| 23 | |
Chris Lattner | f0eb7be | 2002-12-15 21:13:40 +0000 | [diff] [blame] | 24 | virtual const char *getPassName() const { |
| 25 | return "X86 Assembly Printer"; |
| 26 | } |
| 27 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 28 | bool runOnFunction(Function &F); |
| 29 | }; |
| 30 | } |
| 31 | |
Chris Lattner | dbb61c6 | 2002-11-17 22:53:13 +0000 | [diff] [blame] | 32 | /// createX86CodePrinterPass - Print out the specified machine code function to |
| 33 | /// the specified stream. This function should work regardless of whether or |
| 34 | /// not the function is in SSA form or not. |
| 35 | /// |
| 36 | Pass *createX86CodePrinterPass(TargetMachine &TM, std::ostream &O) { |
| 37 | return new Printer(TM, O); |
| 38 | } |
| 39 | |
| 40 | |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 41 | /// runOnFunction - This uses the X86InstructionInfo::print method |
| 42 | /// to print assembly for each instruction. |
| 43 | bool Printer::runOnFunction (Function & F) |
| 44 | { |
| 45 | static unsigned bbnumber = 0; |
| 46 | MachineFunction & MF = MachineFunction::get (&F); |
| 47 | const MachineInstrInfo & MII = TM.getInstrInfo (); |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 48 | |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 49 | // Print out labels for the function. |
| 50 | O << "\t.globl\t" << F.getName () << "\n"; |
| 51 | O << "\t.type\t" << F.getName () << ", @function\n"; |
| 52 | O << F.getName () << ":\n"; |
| 53 | |
| 54 | // Print out code for the function. |
| 55 | for (MachineFunction::const_iterator bb_i = MF.begin (), bb_e = MF.end (); |
| 56 | bb_i != bb_e; ++bb_i) |
| 57 | { |
| 58 | // Print a label for the basic block. |
| 59 | O << ".BB" << bbnumber++ << ":\n"; |
| 60 | for (MachineBasicBlock::const_iterator i_i = bb_i->begin (), i_e = |
| 61 | bb_i->end (); i_i != i_e; ++i_i) |
| 62 | { |
| 63 | // Print the assembly for the instruction. |
| 64 | O << "\t"; |
Chris Lattner | 927dd09 | 2002-11-17 23:20:37 +0000 | [diff] [blame] | 65 | MII.print(*i_i, O, TM); |
Brian Gaeke | 6559bb9 | 2002-11-14 22:32:30 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | // We didn't modify anything. |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 70 | return false; |
| 71 | } |
| 72 | |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 73 | static bool isScale(const MachineOperand &MO) { |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 74 | return MO.isImmediate() && |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 75 | (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 || |
| 76 | MO.getImmedValue() == 4 || MO.getImmedValue() == 8); |
| 77 | } |
| 78 | |
| 79 | static bool isMem(const MachineInstr *MI, unsigned Op) { |
| 80 | return Op+4 <= MI->getNumOperands() && |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 81 | MI->getOperand(Op ).isRegister() &&isScale(MI->getOperand(Op+1)) && |
| 82 | MI->getOperand(Op+2).isRegister() &&MI->getOperand(Op+3).isImmediate(); |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 85 | static void printOp(std::ostream &O, const MachineOperand &MO, |
| 86 | const MRegisterInfo &RI) { |
| 87 | switch (MO.getType()) { |
| 88 | case MachineOperand::MO_VirtualRegister: |
Chris Lattner | ac573f6 | 2002-12-04 17:32:52 +0000 | [diff] [blame] | 89 | if (Value *V = MO.getVRegValueOrNull()) { |
Chris Lattner | dbf30f7 | 2002-12-04 06:45:19 +0000 | [diff] [blame] | 90 | O << "<" << V->getName() << ">"; |
| 91 | return; |
| 92 | } |
Misha Brukman | e1f0d81 | 2002-11-20 18:56:41 +0000 | [diff] [blame] | 93 | case MachineOperand::MO_MachineRegister: |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 94 | if (MO.getReg() < MRegisterInfo::FirstVirtualRegister) |
| 95 | O << RI.get(MO.getReg()).Name; |
| 96 | else |
| 97 | O << "%reg" << MO.getReg(); |
| 98 | return; |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 99 | |
| 100 | case MachineOperand::MO_SignExtendedImmed: |
| 101 | case MachineOperand::MO_UnextendedImmed: |
| 102 | O << (int)MO.getImmedValue(); |
| 103 | return; |
Chris Lattner | f8bafe8 | 2002-12-01 23:25:59 +0000 | [diff] [blame] | 104 | case MachineOperand::MO_PCRelativeDisp: |
Chris Lattner | ea1ddab | 2002-12-03 06:34:06 +0000 | [diff] [blame] | 105 | O << "<" << MO.getVRegValue()->getName() << ">"; |
Chris Lattner | f8bafe8 | 2002-12-01 23:25:59 +0000 | [diff] [blame] | 106 | return; |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 107 | default: |
| 108 | O << "<unknown op ty>"; return; |
| 109 | } |
| 110 | } |
| 111 | |
Brian Gaeke | 86764d7 | 2002-12-05 08:30:40 +0000 | [diff] [blame] | 112 | static const std::string sizePtr (const MachineInstrDescriptor &Desc) { |
Chris Lattner | a0f38c8 | 2002-12-13 03:51:55 +0000 | [diff] [blame] | 113 | switch (Desc.TSFlags & X86II::ArgMask) { |
Chris Lattner | eca1f63 | 2002-12-25 05:09:01 +0000 | [diff] [blame^] | 114 | default: assert(0 && "Unknown arg size!"); |
Chris Lattner | a0f38c8 | 2002-12-13 03:51:55 +0000 | [diff] [blame] | 115 | case X86II::Arg8: return "BYTE PTR"; |
| 116 | case X86II::Arg16: return "WORD PTR"; |
| 117 | case X86II::Arg32: return "DWORD PTR"; |
Chris Lattner | eca1f63 | 2002-12-25 05:09:01 +0000 | [diff] [blame^] | 118 | case X86II::ArgF32: return "DWORD PTR"; |
| 119 | case X86II::ArgF64: return "QWORD PTR"; |
| 120 | case X86II::ArgF80: return "XWORD PTR"; |
Brian Gaeke | 86764d7 | 2002-12-05 08:30:40 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 124 | static void printMemReference(std::ostream &O, const MachineInstr *MI, |
| 125 | unsigned Op, const MRegisterInfo &RI) { |
| 126 | assert(isMem(MI, Op) && "Invalid memory reference!"); |
| 127 | const MachineOperand &BaseReg = MI->getOperand(Op); |
| 128 | const MachineOperand &Scale = MI->getOperand(Op+1); |
| 129 | const MachineOperand &IndexReg = MI->getOperand(Op+2); |
| 130 | const MachineOperand &Disp = MI->getOperand(Op+3); |
| 131 | |
| 132 | O << "["; |
| 133 | bool NeedPlus = false; |
| 134 | if (BaseReg.getReg()) { |
| 135 | printOp(O, BaseReg, RI); |
| 136 | NeedPlus = true; |
| 137 | } |
| 138 | |
| 139 | if (IndexReg.getReg()) { |
| 140 | if (NeedPlus) O << " + "; |
Brian Gaeke | 95780cc | 2002-12-13 07:56:18 +0000 | [diff] [blame] | 141 | if (Scale.getImmedValue() != 1) |
| 142 | O << Scale.getImmedValue() << "*"; |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 143 | printOp(O, IndexReg, RI); |
| 144 | NeedPlus = true; |
| 145 | } |
| 146 | |
| 147 | if (Disp.getImmedValue()) { |
| 148 | if (NeedPlus) O << " + "; |
| 149 | printOp(O, Disp, RI); |
| 150 | } |
| 151 | O << "]"; |
| 152 | } |
| 153 | |
Chris Lattner | dbb61c6 | 2002-11-17 22:53:13 +0000 | [diff] [blame] | 154 | // print - Print out an x86 instruction in intel syntax |
Chris Lattner | 927dd09 | 2002-11-17 23:20:37 +0000 | [diff] [blame] | 155 | void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O, |
| 156 | const TargetMachine &TM) const { |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 157 | unsigned Opcode = MI->getOpcode(); |
| 158 | const MachineInstrDescriptor &Desc = get(Opcode); |
| 159 | |
Chris Lattner | eca1f63 | 2002-12-25 05:09:01 +0000 | [diff] [blame^] | 160 | switch (Desc.TSFlags & X86II::FormMask) { |
| 161 | case X86II::Pseudo: |
| 162 | if (Opcode == X86::PHI) { |
| 163 | printOp(O, MI->getOperand(0), RI); |
| 164 | O << " = phi "; |
| 165 | for (unsigned i = 1, e = MI->getNumOperands(); i != e; i+=2) { |
| 166 | if (i != 1) O << ", "; |
| 167 | O << "["; |
| 168 | printOp(O, MI->getOperand(i), RI); |
| 169 | O << ", "; |
| 170 | printOp(O, MI->getOperand(i+1), RI); |
| 171 | O << "]"; |
| 172 | } |
| 173 | } else { |
| 174 | unsigned i = 0; |
| 175 | if (MI->getNumOperands() && MI->getOperand(0).opIsDef()) { |
| 176 | printOp(O, MI->getOperand(0), RI); |
| 177 | O << " = "; |
| 178 | ++i; |
| 179 | } |
| 180 | O << getName(MI->getOpcode()); |
| 181 | |
| 182 | for (unsigned e = MI->getNumOperands(); i != e; ++i) { |
| 183 | O << " "; |
| 184 | if (MI->getOperand(i).opIsDef()) O << "*"; |
| 185 | printOp(O, MI->getOperand(i), RI); |
| 186 | if (MI->getOperand(i).opIsDef()) O << "*"; |
| 187 | } |
Chris Lattner | 3faae2d | 2002-12-13 09:59:26 +0000 | [diff] [blame] | 188 | } |
| 189 | O << "\n"; |
| 190 | return; |
Chris Lattner | 3faae2d | 2002-12-13 09:59:26 +0000 | [diff] [blame] | 191 | |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 192 | case X86II::RawFrm: |
Chris Lattner | f8bafe8 | 2002-12-01 23:25:59 +0000 | [diff] [blame] | 193 | // The accepted forms of Raw instructions are: |
| 194 | // 1. nop - No operand required |
| 195 | // 2. jmp foo - PC relative displacement operand |
| 196 | // |
| 197 | assert(MI->getNumOperands() == 0 || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 198 | (MI->getNumOperands() == 1 && MI->getOperand(0).isPCRelativeDisp())&& |
Chris Lattner | f8bafe8 | 2002-12-01 23:25:59 +0000 | [diff] [blame] | 199 | "Illegal raw instruction!"); |
Chris Lattner | eca1f63 | 2002-12-25 05:09:01 +0000 | [diff] [blame^] | 200 | O << getName(MI->getOpcode()) << " "; |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 201 | |
Chris Lattner | f8bafe8 | 2002-12-01 23:25:59 +0000 | [diff] [blame] | 202 | if (MI->getNumOperands() == 1) { |
| 203 | printOp(O, MI->getOperand(0), RI); |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 204 | } |
| 205 | O << "\n"; |
| 206 | return; |
| 207 | |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 208 | case X86II::AddRegFrm: { |
| 209 | // There are currently two forms of acceptable AddRegFrm instructions. |
| 210 | // Either the instruction JUST takes a single register (like inc, dec, etc), |
| 211 | // or it takes a register and an immediate of the same size as the register |
Chris Lattner | dbf30f7 | 2002-12-04 06:45:19 +0000 | [diff] [blame] | 212 | // (move immediate f.e.). Note that this immediate value might be stored as |
| 213 | // an LLVM value, to represent, for example, loading the address of a global |
Chris Lattner | facc9fb | 2002-12-23 23:46:00 +0000 | [diff] [blame] | 214 | // into a register. The initial register might be duplicated if this is a |
| 215 | // M_2_ADDR_REG instruction |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 216 | // |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 217 | assert(MI->getOperand(0).isRegister() && |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 218 | (MI->getNumOperands() == 1 || |
Chris Lattner | dbf30f7 | 2002-12-04 06:45:19 +0000 | [diff] [blame] | 219 | (MI->getNumOperands() == 2 && |
Chris Lattner | 6d66944 | 2002-12-04 17:28:40 +0000 | [diff] [blame] | 220 | (MI->getOperand(1).getVRegValueOrNull() || |
Chris Lattner | facc9fb | 2002-12-23 23:46:00 +0000 | [diff] [blame] | 221 | MI->getOperand(1).isImmediate() || |
| 222 | MI->getOperand(1).isRegister()))) && |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 223 | "Illegal form for AddRegFrm instruction!"); |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 224 | |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 225 | unsigned Reg = MI->getOperand(0).getReg(); |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 227 | O << getName(MI->getOpCode()) << " "; |
| 228 | printOp(O, MI->getOperand(0), RI); |
Chris Lattner | facc9fb | 2002-12-23 23:46:00 +0000 | [diff] [blame] | 229 | if (MI->getNumOperands() == 2 && !MI->getOperand(1).isRegister()) { |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 230 | O << ", "; |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 231 | printOp(O, MI->getOperand(1), RI); |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 232 | } |
| 233 | O << "\n"; |
| 234 | return; |
| 235 | } |
Chris Lattner | 233ad71 | 2002-11-21 01:33:44 +0000 | [diff] [blame] | 236 | case X86II::MRMDestReg: { |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 237 | // There are two acceptable forms of MRMDestReg instructions, those with 3 |
| 238 | // and 2 operands: |
| 239 | // |
| 240 | // 3 Operands: in this form, the first two registers (the destination, and |
| 241 | // the first operand) should be the same, post register allocation. The 3rd |
| 242 | // operand is an additional input. This should be for things like add |
| 243 | // instructions. |
| 244 | // |
| 245 | // 2 Operands: this is for things like mov that do not read a second input |
| 246 | // |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 247 | assert(MI->getOperand(0).isRegister() && |
Chris Lattner | 644e1ab | 2002-11-21 00:30:01 +0000 | [diff] [blame] | 248 | (MI->getNumOperands() == 2 || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 249 | (MI->getNumOperands() == 3 && MI->getOperand(1).isRegister())) && |
| 250 | MI->getOperand(MI->getNumOperands()-1).isRegister() |
Misha Brukman | e1f0d81 | 2002-11-20 18:56:41 +0000 | [diff] [blame] | 251 | && "Bad format for MRMDestReg!"); |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 252 | if (MI->getNumOperands() == 3 && |
| 253 | MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) |
| 254 | O << "**"; |
| 255 | |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 256 | O << getName(MI->getOpCode()) << " "; |
| 257 | printOp(O, MI->getOperand(0), RI); |
| 258 | O << ", "; |
| 259 | printOp(O, MI->getOperand(MI->getNumOperands()-1), RI); |
| 260 | O << "\n"; |
| 261 | return; |
Chris Lattner | 233ad71 | 2002-11-21 01:33:44 +0000 | [diff] [blame] | 262 | } |
Chris Lattner | 1804233 | 2002-11-21 21:03:39 +0000 | [diff] [blame] | 263 | |
| 264 | case X86II::MRMDestMem: { |
| 265 | // These instructions are the same as MRMDestReg, but instead of having a |
| 266 | // register reference for the mod/rm field, it's a memory reference. |
| 267 | // |
| 268 | assert(isMem(MI, 0) && MI->getNumOperands() == 4+1 && |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 269 | MI->getOperand(4).isRegister() && "Bad format for MRMDestMem!"); |
Chris Lattner | 1804233 | 2002-11-21 21:03:39 +0000 | [diff] [blame] | 270 | |
Brian Gaeke | 86764d7 | 2002-12-05 08:30:40 +0000 | [diff] [blame] | 271 | O << getName(MI->getOpCode()) << " " << sizePtr (Desc) << " "; |
Chris Lattner | 1804233 | 2002-11-21 21:03:39 +0000 | [diff] [blame] | 272 | printMemReference(O, MI, 0, RI); |
| 273 | O << ", "; |
| 274 | printOp(O, MI->getOperand(4), RI); |
| 275 | O << "\n"; |
| 276 | return; |
| 277 | } |
| 278 | |
Chris Lattner | 233ad71 | 2002-11-21 01:33:44 +0000 | [diff] [blame] | 279 | case X86II::MRMSrcReg: { |
Chris Lattner | 644e1ab | 2002-11-21 00:30:01 +0000 | [diff] [blame] | 280 | // There is a two forms that are acceptable for MRMSrcReg instructions, |
| 281 | // those with 3 and 2 operands: |
| 282 | // |
| 283 | // 3 Operands: in this form, the last register (the second input) is the |
| 284 | // ModR/M input. The first two operands should be the same, post register |
| 285 | // allocation. This is for things like: add r32, r/m32 |
| 286 | // |
| 287 | // 2 Operands: this is for things like mov that do not read a second input |
| 288 | // |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 289 | assert(MI->getOperand(0).isRegister() && |
| 290 | MI->getOperand(1).isRegister() && |
Chris Lattner | 644e1ab | 2002-11-21 00:30:01 +0000 | [diff] [blame] | 291 | (MI->getNumOperands() == 2 || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 292 | (MI->getNumOperands() == 3 && MI->getOperand(2).isRegister())) |
Chris Lattner | 644e1ab | 2002-11-21 00:30:01 +0000 | [diff] [blame] | 293 | && "Bad format for MRMDestReg!"); |
| 294 | if (MI->getNumOperands() == 3 && |
| 295 | MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) |
| 296 | O << "**"; |
| 297 | |
Chris Lattner | 644e1ab | 2002-11-21 00:30:01 +0000 | [diff] [blame] | 298 | O << getName(MI->getOpCode()) << " "; |
| 299 | printOp(O, MI->getOperand(0), RI); |
| 300 | O << ", "; |
| 301 | printOp(O, MI->getOperand(MI->getNumOperands()-1), RI); |
| 302 | O << "\n"; |
| 303 | return; |
Chris Lattner | 233ad71 | 2002-11-21 01:33:44 +0000 | [diff] [blame] | 304 | } |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 305 | |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 306 | case X86II::MRMSrcMem: { |
| 307 | // These instructions are the same as MRMSrcReg, but instead of having a |
| 308 | // register reference for the mod/rm field, it's a memory reference. |
Chris Lattner | 1804233 | 2002-11-21 21:03:39 +0000 | [diff] [blame] | 309 | // |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 310 | assert(MI->getOperand(0).isRegister() && |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 311 | (MI->getNumOperands() == 1+4 && isMem(MI, 1)) || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 312 | (MI->getNumOperands() == 2+4 && MI->getOperand(1).isRegister() && |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 313 | isMem(MI, 2)) |
| 314 | && "Bad format for MRMDestReg!"); |
| 315 | if (MI->getNumOperands() == 2+4 && |
| 316 | MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) |
| 317 | O << "**"; |
| 318 | |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 319 | O << getName(MI->getOpCode()) << " "; |
| 320 | printOp(O, MI->getOperand(0), RI); |
Brian Gaeke | 86764d7 | 2002-12-05 08:30:40 +0000 | [diff] [blame] | 321 | O << ", " << sizePtr (Desc) << " "; |
Chris Lattner | 3d3067b | 2002-11-21 20:44:15 +0000 | [diff] [blame] | 322 | printMemReference(O, MI, MI->getNumOperands()-4, RI); |
| 323 | O << "\n"; |
| 324 | return; |
| 325 | } |
| 326 | |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 327 | case X86II::MRMS0r: case X86II::MRMS1r: |
| 328 | case X86II::MRMS2r: case X86II::MRMS3r: |
| 329 | case X86II::MRMS4r: case X86II::MRMS5r: |
| 330 | case X86II::MRMS6r: case X86II::MRMS7r: { |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 331 | // In this form, the following are valid formats: |
| 332 | // 1. sete r |
Chris Lattner | 1d53ce4 | 2002-11-21 23:30:00 +0000 | [diff] [blame] | 333 | // 2. cmp reg, immediate |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 334 | // 2. shl rdest, rinput <implicit CL or 1> |
| 335 | // 3. sbb rdest, rinput, immediate [rdest = rinput] |
| 336 | // |
| 337 | assert(MI->getNumOperands() > 0 && MI->getNumOperands() < 4 && |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 338 | MI->getOperand(0).isRegister() && "Bad MRMSxR format!"); |
Chris Lattner | 1d53ce4 | 2002-11-21 23:30:00 +0000 | [diff] [blame] | 339 | assert((MI->getNumOperands() != 2 || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 340 | MI->getOperand(1).isRegister() || MI->getOperand(1).isImmediate())&& |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 341 | "Bad MRMSxR format!"); |
Chris Lattner | 1d53ce4 | 2002-11-21 23:30:00 +0000 | [diff] [blame] | 342 | assert((MI->getNumOperands() < 3 || |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 343 | (MI->getOperand(1).isRegister() && MI->getOperand(2).isImmediate())) && |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 344 | "Bad MRMSxR format!"); |
| 345 | |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 346 | if (MI->getNumOperands() > 1 && MI->getOperand(1).isRegister() && |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 347 | MI->getOperand(0).getReg() != MI->getOperand(1).getReg()) |
| 348 | O << "**"; |
| 349 | |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 350 | O << getName(MI->getOpCode()) << " "; |
| 351 | printOp(O, MI->getOperand(0), RI); |
Chris Lattner | d909683 | 2002-12-15 08:01:39 +0000 | [diff] [blame] | 352 | if (MI->getOperand(MI->getNumOperands()-1).isImmediate()) { |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 353 | O << ", "; |
Chris Lattner | 1d53ce4 | 2002-11-21 23:30:00 +0000 | [diff] [blame] | 354 | printOp(O, MI->getOperand(MI->getNumOperands()-1), RI); |
Chris Lattner | 675dd2c | 2002-11-21 17:09:01 +0000 | [diff] [blame] | 355 | } |
| 356 | O << "\n"; |
| 357 | |
| 358 | return; |
| 359 | } |
| 360 | |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 361 | default: |
Chris Lattner | 77875d8 | 2002-11-21 02:00:20 +0000 | [diff] [blame] | 362 | O << "\t\t\t-"; MI->print(O, TM); break; |
Chris Lattner | f9f6088 | 2002-11-18 06:56:51 +0000 | [diff] [blame] | 363 | } |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 364 | } |