Correct asmprinting of memory operands
[oota-llvm.git] / lib / Target / MSP430 / MSP430AsmPrinter.cpp
index a9a27110296ccd8daae0f2084930079724acce31..fb642835c12e4ae5936648c54c0e34aa6e36f8ef 100644 (file)
@@ -162,17 +162,23 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
 void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
                                           const char* Modifier) {
   const MachineOperand &Disp = MI->getOperand(OpNum);
-  assert(Disp.isImm() && "Displacement can be only immediate!");
-
-  // Special case: 0(Reg) -> @Reg
-  if (Disp.getImm() == 0) {
-    O << "@";
-    printOperand(MI, OpNum + 1);
-  } else {
-    printOperand(MI, OpNum, "nohash");
-    O << '(';
-    printOperand(MI, OpNum + 1);
-    O << ')';
-  }
+  const MachineOperand &Base = MI->getOperand(OpNum+1);
+
+  if (Disp.isGlobal())
+    printOperand(MI, OpNum, "mem");
+  else if (Disp.isImm() && !Base.getReg())
+    printOperand(MI, OpNum);
+  else if (Base.getReg()) {
+    if (Disp.getImm()) {
+      printOperand(MI, OpNum, "nohash");
+      O << '(';
+      printOperand(MI, OpNum + 1);
+      O << ')';
+    } else {
+      O << '@';
+      printOperand(MI, OpNum + 1);
+    }
+  } else
+    assert(0 && "Unsupported memory operand");
 }