From ceb224148e8425334e46fed686f911bbc99b5c98 Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Fri, 18 Jun 2004 06:27:59 +0000 Subject: [PATCH] Support printing base+offset pairs where the offset is a register. Use this for printing the jmpl indirect-call instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14224 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Sparc/SparcAsmPrinter.cpp | 35 +++++++++++++++++------- lib/Target/SparcV8/SparcV8AsmPrinter.cpp | 35 +++++++++++++++++------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp index e40ba75326b..09d61b7b2d9 100644 --- a/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -69,7 +69,7 @@ namespace { void emitGlobalConstant(const Constant *CV); void printConstantPool(MachineConstantPool *MCP); void printOperand(const MachineInstr *MI, int opNum); - void printBaseOffsetPair (const MachineInstr *MI, int i); + void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true); void printMachineInstruction(const MachineInstr *MI); bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); @@ -455,17 +455,26 @@ static bool isStoreInstruction (const MachineInstr *MI) { } } -void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i) { - O << "["; +/// printBaseOffsetPair - Print two consecutive operands of MI, starting at #i, +/// which form a base + offset pair (which may have brackets around it, if +/// brackets is true, or may be in the form base - constant, if offset is a +/// negative constant). +/// +void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i, + bool brackets) { + if (brackets) O << "["; printOperand (MI, i); - assert (MI->getOperand (i + 1).isImmediate() - && "2nd half of base-offset pair must be immediate-value machine operand"); - int Val = (int) MI->getOperand (i + 1).getImmedValue (); - if (Val != 0) { - O << ((Val >= 0) ? " + " : " - "); - O << ((Val >= 0) ? Val : -Val); + if (MI->getOperand (i + 1).isImmediate()) { + int Val = (int) MI->getOperand (i + 1).getImmedValue (); + if (Val != 0) { + O << ((Val >= 0) ? " + " : " - "); + O << ((Val >= 0) ? Val : -Val); + } + } else { + O << " + "; + printOperand (MI, i + 1); } - O << "]"; + if (brackets) O << "]"; } /// printMachineInstruction -- Print out a single SparcV8 LLVM instruction @@ -492,6 +501,12 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) { printBaseOffsetPair (MI, 0); O << "\n"; return; + } else if (Opcode == V8::JMPLrr) { + printBaseOffsetPair (MI, 1, false); + O << ", "; + printOperand (MI, 0); + O << "\n"; + return; } // print non-immediate, non-register-def operands diff --git a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp index e40ba75326b..09d61b7b2d9 100644 --- a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp +++ b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp @@ -69,7 +69,7 @@ namespace { void emitGlobalConstant(const Constant *CV); void printConstantPool(MachineConstantPool *MCP); void printOperand(const MachineInstr *MI, int opNum); - void printBaseOffsetPair (const MachineInstr *MI, int i); + void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true); void printMachineInstruction(const MachineInstr *MI); bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); @@ -455,17 +455,26 @@ static bool isStoreInstruction (const MachineInstr *MI) { } } -void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i) { - O << "["; +/// printBaseOffsetPair - Print two consecutive operands of MI, starting at #i, +/// which form a base + offset pair (which may have brackets around it, if +/// brackets is true, or may be in the form base - constant, if offset is a +/// negative constant). +/// +void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i, + bool brackets) { + if (brackets) O << "["; printOperand (MI, i); - assert (MI->getOperand (i + 1).isImmediate() - && "2nd half of base-offset pair must be immediate-value machine operand"); - int Val = (int) MI->getOperand (i + 1).getImmedValue (); - if (Val != 0) { - O << ((Val >= 0) ? " + " : " - "); - O << ((Val >= 0) ? Val : -Val); + if (MI->getOperand (i + 1).isImmediate()) { + int Val = (int) MI->getOperand (i + 1).getImmedValue (); + if (Val != 0) { + O << ((Val >= 0) ? " + " : " - "); + O << ((Val >= 0) ? Val : -Val); + } + } else { + O << " + "; + printOperand (MI, i + 1); } - O << "]"; + if (brackets) O << "]"; } /// printMachineInstruction -- Print out a single SparcV8 LLVM instruction @@ -492,6 +501,12 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) { printBaseOffsetPair (MI, 0); O << "\n"; return; + } else if (Opcode == V8::JMPLrr) { + printBaseOffsetPair (MI, 1, false); + O << ", "; + printOperand (MI, 0); + O << "\n"; + return; } // print non-immediate, non-register-def operands