Checkpoint MCInst printer. We (almostly) able to print global / JT / constpool entries

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84706 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2009-10-21 00:12:08 +00:00
parent a3da7c3ca8
commit 9b0b852698
5 changed files with 106 additions and 11 deletions

View File

@ -295,7 +295,7 @@ bool MSP430AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
void MSP430AsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI)
{
MSP430MCInstLower MCInstLowering(OutContext, Mang);
MSP430MCInstLower MCInstLowering(OutContext, *Mang, getFunctionNumber(), *MAI);
switch (MI->getOpcode()) {
case TargetInstrInfo::DBG_LABEL:

View File

@ -45,6 +45,30 @@ void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
O << '#' << Op.getImm();
} else {
assert(Op.isExpr() && "unknown operand kind in printOperand");
assert(0 && "Unimplemented!");
Op.getExpr()->print(O, &MAI);
}
}
void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
const char *Modifier) {
const MCOperand &Base = MI->getOperand(OpNo);
const MCOperand &Disp = MI->getOperand(OpNo+1);
if (Disp.isImm() && !Base.isReg())
printOperand(MI, OpNo);
else if (Base.isReg()) {
if (Disp.getImm()) {
O << Disp.getImm() << '(';
printOperand(MI, OpNo);
O << ')';
} else {
O << '@';
printOperand(MI, OpNo);
}
} else {
Base.dump();
Disp.dump();
llvm_unreachable("Unsupported memory operand");
}
}

View File

@ -37,8 +37,8 @@ namespace llvm
const char *Modifier = 0);
void printSrcMemOperand(const MCInst *MI, unsigned OpNo,
const char *Modifier = 0) {
}
const char *Modifier = 0);
void printCCOperand(const MCInst *MI, unsigned OpNo) {
}

View File

@ -19,10 +19,75 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mangler.h"
#include "llvm/ADT/SmallString.h"
using namespace llvm;
MCSymbol *MSP430MCInstLower::
GetGlobalAddressSymbol(const MachineOperand &MO) const {
const GlobalValue *GV = MO.getGlobal();
SmallString<128> Name;
Mang.getNameWithPrefix(Name, GV, false);
switch (MO.getTargetFlags()) {
default: llvm_unreachable(0 && "Unknown target flag on GV operand");
case 0: break;
}
return Ctx.GetOrCreateSymbol(Name.str());
}
MCSymbol *MSP430MCInstLower::
GetJumpTableSymbol(const MachineOperand &MO) const {
SmallString<256> Name;
raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "JTI"
<< CurFunctionNumber << '_' << MO.getIndex();
switch (MO.getTargetFlags()) {
default: llvm_unreachable("Unknown target flag on GV operand");
case 0: break;
}
// Create a symbol for the name.
return Ctx.GetOrCreateSymbol(Name.str());
}
MCSymbol *MSP430MCInstLower::
GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
SmallString<256> Name;
raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "CPI"
<< CurFunctionNumber << '_' << MO.getIndex();
switch (MO.getTargetFlags()) {
default: llvm_unreachable("Unknown target flag on GV operand");
case 0: break;
}
// Create a symbol for the name.
return Ctx.GetOrCreateSymbol(Name.str());
}
MCOperand MSP430MCInstLower::
LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const {
// FIXME: We would like an efficient form for this, so we don't have to do a
// lot of extra uniquing.
const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, Ctx);
switch (MO.getTargetFlags()) {
default: llvm_unreachable("Unknown target flag on GV operand");
case 0: break;
}
if (!MO.isJTI() && MO.getOffset())
Expr = MCBinaryExpr::CreateAdd(Expr,
MCConstantExpr::Create(MO.getOffset(), Ctx),
Ctx);
return MCOperand::CreateExpr(Expr);
}
void MSP430MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
OutMI.setOpcode(MI->getOpcode());
@ -45,22 +110,23 @@ void MSP430MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
break;
#endif
case MachineOperand::MO_GlobalAddress:
MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
break;
#if 0
case MachineOperand::MO_ExternalSymbol:
MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
break;
#endif
case MachineOperand::MO_JumpTableIndex:
MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
break;
case MachineOperand::MO_ConstantPoolIndex:
MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
break;
#endif
}
OutMI.addOperand(MCOp);
}
}

View File

@ -27,17 +27,22 @@ namespace llvm {
/// into an MCInst.
class VISIBILITY_HIDDEN MSP430MCInstLower {
MCContext &Ctx;
Mangler *Mang;
Mangler &Mang;
#if 0
const unsigned CurFunctionNumber;
const MCAsmInfo &MAI;
#endif
public:
MSP430MCInstLower(MCContext &ctx, Mangler *mang) : Ctx(ctx), Mang(mang) {}
MSP430MCInstLower(MCContext &ctx, Mangler &mang, unsigned FuncNum,
const MCAsmInfo &mai)
: Ctx(ctx), Mang(mang), CurFunctionNumber(FuncNum), MAI(mai) {}
void Lower(const MachineInstr *MI, MCInst &OutMI) const;
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
};
}