Distinguish between pcrel imm operands and 'normal' ones. Fix fixes gross weirdness...
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 21 Oct 2009 00:13:25 +0000 (00:13 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 21 Oct 2009 00:13:25 +0000 (00:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84710 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
lib/Target/MSP430/MSP430InstrInfo.td

index 73368803c0738c867e5f4a073423cf16ed93c956..4f5879a3472c12573fff9fa6675f3966b4fc9242 100644 (file)
@@ -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);
index 8fcbab58c96a5af5264bba1fe1fa718c298ea321..59b448aa8727c7b037f7dba8436e359a89f2a428 100644 (file)
@@ -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();
 
index 3d4b931cdb6bf1b2a6c56ebd28e3d1c80f9c90d8..2fac800fcd79639a85172c75667a930005737753 100644 (file)
@@ -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);
 
   };
index f7e0d2bad6382b41b419b615afd32a37e513869f..e202175561cb7bd37b4227cfda118f5aacb486a2 100644 (file)
@@ -71,7 +71,9 @@ def memdst : Operand<i16> {
 }
 
 // Branch targets have OtherVT type.
-def brtarget : Operand<OtherVT>;
+def brtarget : Operand<OtherVT> {
+  let PrintMethod = "printPCRelImmOperand";
+}
 
 // Operand for printing out a condition code.
 def cc : Operand<i8> {