Correct asmprinting of memory operands
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70732 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/MSP430/MSP430AsmPrinter.cpp b/lib/Target/MSP430/MSP430AsmPrinter.cpp
index a9a2711..fb64283 100644
--- a/lib/Target/MSP430/MSP430AsmPrinter.cpp
+++ b/lib/Target/MSP430/MSP430AsmPrinter.cpp
@@ -162,17 +162,23 @@
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!");
+ const MachineOperand &Base = MI->getOperand(OpNum+1);
- // 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 << ')';
- }
+ 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");
}