From 8ecaf237e024723ed3e01a500a5e8c42dc050cec Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Wed, 21 Oct 2009 00:13:25 +0000 Subject: [PATCH] Distinguish between pcrel imm operands and 'normal' ones. Fix fixes gross weirdness of asmprinting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84710 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../MSP430/AsmPrinter/MSP430AsmPrinter.cpp | 3 +++ .../MSP430/AsmPrinter/MSP430InstPrinter.cpp | 22 ++++++++++++++----- .../MSP430/AsmPrinter/MSP430InstPrinter.h | 3 +-- lib/Target/MSP430/MSP430InstrInfo.td | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp index 73368803c07..4f5879a3472 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp +++ b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp @@ -65,6 +65,9 @@ namespace { } void printOperand(const MachineInstr *MI, int OpNum, const char* Modifier = 0); + void printPCRelImmOperand(const MachineInstr *MI, int OpNum) { + printOperand(MI, OpNum); + } void printSrcMemOperand(const MachineInstr *MI, int OpNum, const char* Modifier = 0); void printCCOperand(const MachineInstr *MI, int OpNum); diff --git a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp index 8fcbab58c96..59b448aa872 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp +++ b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp @@ -35,6 +35,16 @@ void MSP430InstPrinter::printInst(const MCInst *MI) { printInstruction(MI); } +void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) { + const MCOperand &Op = MI->getOperand(OpNo); + if (Op.isImm()) + O << Op.getImm(); + else { + assert(Op.isExpr() && "unknown pcrel immediate operand"); + Op.getExpr()->print(O, &MAI); + } +} + void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo, const char *Modifier) { const MCOperand &Op = MI->getOperand(OpNo); @@ -44,8 +54,7 @@ void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo, O << '#' << Op.getImm(); } else { assert(Op.isExpr() && "unknown operand kind in printOperand"); - bool isMemOp = Modifier && !strcmp(Modifier, "mem"); - O << (isMemOp ? '&' : '#'); + O << '#'; Op.getExpr()->print(O, &MAI); } } @@ -56,9 +65,10 @@ void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo, const MCOperand &Disp = MI->getOperand(OpNo+1); // FIXME: move global to displacement field! - if (Base.isExpr()) - printOperand(MI, OpNo, "mem"); - else if (Disp.isImm() && !Base.isReg()) + if (Base.isExpr()) { + O << '&'; + Base.getExpr()->print(O, &MAI); + } else if (Disp.isImm() && !Base.isReg()) printOperand(MI, OpNo); else if (Base.isReg()) { if (Disp.getImm()) { @@ -74,8 +84,8 @@ void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo, Disp.dump(); llvm_unreachable("Unsupported memory operand"); } - } + void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo) { unsigned CC = MI->getOperand(OpNo).getImm(); diff --git a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h index 3d4b931cdb6..2fac800fcd7 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h +++ b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h @@ -35,10 +35,9 @@ namespace llvm void printOperand(const MCInst *MI, unsigned OpNo, const char *Modifier = 0); - + void printPCRelImmOperand(const MCInst *MI, unsigned OpNo); void printSrcMemOperand(const MCInst *MI, unsigned OpNo, const char *Modifier = 0); - void printCCOperand(const MCInst *MI, unsigned OpNo); }; diff --git a/lib/Target/MSP430/MSP430InstrInfo.td b/lib/Target/MSP430/MSP430InstrInfo.td index f7e0d2bad63..e202175561c 100644 --- a/lib/Target/MSP430/MSP430InstrInfo.td +++ b/lib/Target/MSP430/MSP430InstrInfo.td @@ -71,7 +71,9 @@ def memdst : Operand { } // Branch targets have OtherVT type. -def brtarget : Operand; +def brtarget : Operand { + let PrintMethod = "printPCRelImmOperand"; +} // Operand for printing out a condition code. def cc : Operand { -- 2.34.1