Implement cast bool to X
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.cpp
index ae14e41d731e4ded4ac2b2579c9423deb1deb8b0..a80e7d26642186632f6f0dd5afd9bf745d14157c 100644 (file)
@@ -96,7 +96,7 @@ static void printOp(std::ostream &O, const MachineOperand &MO,
                     const MRegisterInfo &RI) {
   switch (MO.getType()) {
   case MachineOperand::MO_VirtualRegister:
-    if (Value *V = MO.getVRegValue()) {
+    if (Value *V = MO.getVRegValueOrNull()) {
       O << "<" << V->getName() << ">";
       return;
     }
@@ -119,6 +119,18 @@ static void printOp(std::ostream &O, const MachineOperand &MO,
   }
 }
 
+static const std::string sizePtr (const MachineInstrDescriptor &Desc) {
+  switch (Desc.TSFlags & X86II::ArgMask) {
+    case X86II::Arg8:   return "BYTE PTR"; 
+    case X86II::Arg16:  return "WORD PTR"; 
+    case X86II::Arg32:  return "DWORD PTR"; 
+    case X86II::Arg64:  return "QWORD PTR"; 
+    case X86II::Arg80:  return "XWORD PTR"; 
+    case X86II::Arg128: return "128BIT PTR";  // dunno what the real one is
+    default: return "<SIZE?> PTR"; // crack being smoked
+  }
+}
+
 static void printMemReference(std::ostream &O, const MachineInstr *MI,
                               unsigned Op, const MRegisterInfo &RI) {
   assert(isMem(MI, Op) && "Invalid memory reference!");
@@ -136,8 +148,8 @@ static void printMemReference(std::ostream &O, const MachineInstr *MI,
 
   if (IndexReg.getReg()) {
     if (NeedPlus) O << " + ";
-    if (IndexReg.getImmedValue() != 1)
-      O << IndexReg.getImmedValue() << "*";
+    if (Scale.getImmedValue() != 1)
+      O << Scale.getImmedValue() << "*";
     printOp(O, IndexReg, RI);
     NeedPlus = true;
   }
@@ -155,6 +167,22 @@ void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O,
   unsigned Opcode = MI->getOpcode();
   const MachineInstrDescriptor &Desc = get(Opcode);
 
+  if (Opcode == X86::PHI) {
+    printOp(O, MI->getOperand(0), RI);
+    O << " = phi ";
+    for (unsigned i = 1, e = MI->getNumOperands(); i != e; i+=2) {
+      if (i != 1) O << ", ";
+      O << "[";
+      printOp(O, MI->getOperand(i), RI);
+      O << ", ";
+      printOp(O, MI->getOperand(i+1), RI);
+      O << "]";
+    }
+    O << "\n";
+    return;
+  }
+
+
   switch (Desc.TSFlags & X86II::FormMask) {
   case X86II::RawFrm:
     // The accepted forms of Raw instructions are:
@@ -233,7 +261,7 @@ void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O,
     assert(isMem(MI, 0) && MI->getNumOperands() == 4+1 &&
            isReg(MI->getOperand(4)) && "Bad format for MRMDestMem!");
 
-    O << getName(MI->getOpCode()) << " <SIZE> PTR ";
+    O << getName(MI->getOpCode()) << " " << sizePtr (Desc) << " ";
     printMemReference(O, MI, 0, RI);
     O << ", ";
     printOp(O, MI->getOperand(4), RI);
@@ -283,7 +311,7 @@ void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O,
 
     O << getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
-    O << ", <SIZE> PTR ";
+    O << ", " << sizePtr (Desc) << " ";
     printMemReference(O, MI, MI->getNumOperands()-4, RI);
     O << "\n";
     return;