mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
implement support for lowering references to global addresses. For example, we now
can asmprint: NEW: movl "L___stack_chk_guard$non_lazy_ptr", %eax OLD: movl L___stack_chk_guard$non_lazy_ptr, %eax where 'new' is coming out of the MCInst version of the printer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f5af556c18
commit
30c74a2429
@ -687,6 +687,43 @@ static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
|
||||||
|
/// MCOperand.
|
||||||
|
MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
|
||||||
|
//OutContext
|
||||||
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
|
|
||||||
|
const char *Suffix = "";
|
||||||
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
||||||
|
Suffix = "$stub";
|
||||||
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
||||||
|
Suffix = "$non_lazy_ptr";
|
||||||
|
|
||||||
|
std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
|
||||||
|
if (Subtarget->isTargetCygMing())
|
||||||
|
DecorateCygMingName(Name, GV);
|
||||||
|
|
||||||
|
// Handle dllimport linkage.
|
||||||
|
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
|
||||||
|
Name = "__imp_" + Name;
|
||||||
|
|
||||||
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
|
||||||
|
GVStubs[Name] = Mang->getMangledName(GV);
|
||||||
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
||||||
|
HiddenGVStubs[Name] = Mang->getMangledName(GV);
|
||||||
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
||||||
|
FnStubs[Name] = Mang->getMangledName(GV);
|
||||||
|
|
||||||
|
// Create a symbol for the name.
|
||||||
|
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
|
||||||
|
return MCOperand::CreateMCValue(MCValue::get(Sym, 0, MO.getOffset()));
|
||||||
|
}
|
||||||
|
|
||||||
/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
|
/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
|
||||||
/// AT&T syntax to the current output stream.
|
/// AT&T syntax to the current output stream.
|
||||||
///
|
///
|
||||||
@ -718,15 +755,24 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|||||||
const MachineOperand &MO = MI->getOperand(i);
|
const MachineOperand &MO = MI->getOperand(i);
|
||||||
|
|
||||||
MCOperand MCOp;
|
MCOperand MCOp;
|
||||||
if (MO.isReg()) {
|
switch (MO.getType()) {
|
||||||
|
default:
|
||||||
|
O.flush();
|
||||||
|
errs() << "Cannot lower operand #" << i << " of :" << *MI;
|
||||||
|
llvm_unreachable("Unimp");
|
||||||
|
case MachineOperand::MO_Register:
|
||||||
MCOp = MCOperand::CreateReg(MO.getReg());
|
MCOp = MCOperand::CreateReg(MO.getReg());
|
||||||
} else if (MO.isImm()) {
|
break;
|
||||||
|
case MachineOperand::MO_Immediate:
|
||||||
MCOp = MCOperand::CreateImm(MO.getImm());
|
MCOp = MCOperand::CreateImm(MO.getImm());
|
||||||
} else if (MO.isMBB()) {
|
break;
|
||||||
|
case MachineOperand::MO_MachineBasicBlock:
|
||||||
MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
|
MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
|
||||||
MO.getMBB()->getNumber());
|
MO.getMBB()->getNumber());
|
||||||
} else {
|
break;
|
||||||
llvm_unreachable("Unimp");
|
case MachineOperand::MO_GlobalAddress:
|
||||||
|
MCOp = LowerGlobalAddressOperand(MO);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TmpInst.addOperand(MCOp);
|
TmpInst.addOperand(MCOp);
|
||||||
|
@ -29,6 +29,7 @@ namespace llvm {
|
|||||||
class MachineJumpTableInfo;
|
class MachineJumpTableInfo;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
|
class MCOperand;
|
||||||
class MCStreamer;
|
class MCStreamer;
|
||||||
|
|
||||||
class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
|
class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
|
||||||
@ -66,6 +67,7 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
|
|||||||
|
|
||||||
// New MCInst printing stuff.
|
// New MCInst printing stuff.
|
||||||
void printInstruction(const MCInst *MI);
|
void printInstruction(const MCInst *MI);
|
||||||
|
MCOperand LowerGlobalAddressOperand(const MachineOperand &MO);
|
||||||
|
|
||||||
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
|
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user