Give the X86 asm printer the ability to print out addressing modes that have

constant displacements from global variables.  Patch by Jeff Cohen!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17009 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-10-15 04:44:53 +00:00
parent fb3d844e50
commit d416f086cc

View File

@ -61,7 +61,8 @@ static bool isMem(const MachineInstr *MI, unsigned Op) {
if (MI->getOperand(Op).isConstantPoolIndex()) return true; if (MI->getOperand(Op).isConstantPoolIndex()) return true;
return Op+4 <= MI->getNumOperands() && return Op+4 <= MI->getNumOperands() &&
MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) && MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
MI->getOperand(Op+2).isRegister() && MI->getOperand(Op+3).isImmediate(); MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate() ||
MI->getOperand(Op+3).isGlobalAddress());
} }
// SwitchSection - Switch to the specified section of the executable if we are // SwitchSection - Switch to the specified section of the executable if we are
@ -289,11 +290,17 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs"; std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
abort (); abort ();
return; return;
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress: {
if (!elideOffsetKeyword) if (!elideOffsetKeyword)
O << "OFFSET "; O << "OFFSET ";
O << Mang->getValueName(MO.getGlobal()); O << Mang->getValueName(MO.getGlobal());
int Offset = MO.getOffset();
if (Offset > 0)
O << " + " << Offset;
else if (Offset < 0)
O << " - " << -Offset;
return; return;
}
case MachineOperand::MO_ExternalSymbol: case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName(); O << MO.getSymbolName();
return; return;
@ -323,12 +330,12 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){
const MachineOperand &BaseReg = MI->getOperand(Op); const MachineOperand &BaseReg = MI->getOperand(Op);
int ScaleVal = MI->getOperand(Op+1).getImmedValue(); int ScaleVal = MI->getOperand(Op+1).getImmedValue();
const MachineOperand &IndexReg = MI->getOperand(Op+2); const MachineOperand &IndexReg = MI->getOperand(Op+2);
int DispVal = MI->getOperand(Op+3).getImmedValue(); const MachineOperand &DispSpec = MI->getOperand(Op+3);
O << "["; O << "[";
bool NeedPlus = false; bool NeedPlus = false;
if (BaseReg.getReg()) { if (BaseReg.getReg()) {
printOp(BaseReg); printOp(BaseReg, true);
NeedPlus = true; NeedPlus = true;
} }
@ -340,15 +347,22 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){
NeedPlus = true; NeedPlus = true;
} }
if (DispVal) { if (DispSpec.isGlobalAddress()) {
if (NeedPlus) if (NeedPlus)
if (DispVal > 0) O << " + ";
O << " + "; printOp(DispSpec, true);
else { } else {
O << " - "; int DispVal = DispSpec.getImmedValue();
DispVal = -DispVal; if (DispVal) {
} if (NeedPlus)
O << DispVal; if (DispVal > 0)
O << " + ";
else {
O << " - ";
DispVal = -DispVal;
}
O << DispVal;
}
} }
O << "]"; O << "]";
} }
@ -484,10 +498,16 @@ void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) {
std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs"; std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
abort (); abort ();
return; return;
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress: {
if (!isCallOp) O << '$'; if (!isCallOp) O << '$';
O << Mang->getValueName(MO.getGlobal()); O << Mang->getValueName(MO.getGlobal());
int Offset = MO.getOffset();
if (Offset > 0)
O << "+" << Offset;
else if (Offset < 0)
O << Offset;
return; return;
}
case MachineOperand::MO_ExternalSymbol: case MachineOperand::MO_ExternalSymbol:
if (!isCallOp) O << '$'; if (!isCallOp) O << '$';
O << MO.getSymbolName(); O << MO.getSymbolName();
@ -517,22 +537,30 @@ void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){
const MachineOperand &BaseReg = MI->getOperand(Op); const MachineOperand &BaseReg = MI->getOperand(Op);
int ScaleVal = MI->getOperand(Op+1).getImmedValue(); int ScaleVal = MI->getOperand(Op+1).getImmedValue();
const MachineOperand &IndexReg = MI->getOperand(Op+2); const MachineOperand &IndexReg = MI->getOperand(Op+2);
int DispVal = MI->getOperand(Op+3).getImmedValue(); const MachineOperand &DispSpec = MI->getOperand(Op+3);
if (DispVal) O << DispVal; if (DispSpec.isGlobalAddress()) {
printOp(DispSpec, true);
O << "("; } else {
if (BaseReg.getReg()) int DispVal = DispSpec.getImmedValue();
printOp(BaseReg); if (DispVal)
O << DispVal;
if (IndexReg.getReg()) {
O << ",";
printOp(IndexReg);
if (ScaleVal != 1)
O << "," << ScaleVal;
} }
O << ")"; if (IndexReg.getReg() || BaseReg.getReg()) {
O << "(";
if (BaseReg.getReg())
printOp(BaseReg);
if (IndexReg.getReg()) {
O << ",";
printOp(IndexReg);
if (ScaleVal != 1)
O << "," << ScaleVal;
}
O << ")";
}
} }