[llvm-commits] [llvm] r84706 - in /llvm/trunk/lib/Target/MSP430/AsmPrinter: MSP430AsmPrinter.cpp MSP430InstPrinter.cpp MSP430InstPrinter.h MSP430MCInstLower.cpp MSP430MCInstLower.h
Anton Korobeynikov
asl at math.spbu.ru
Tue Oct 20 17:12:08 PDT 2009
Author: asl
Date: Tue Oct 20 19:12:08 2009
New Revision: 84706
URL: http://llvm.org/viewvc/llvm-project?rev=84706&view=rev
Log:
Checkpoint MCInst printer. We (almostly) able to print global / JT / constpool entries
Modified:
llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h
Modified: llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp?rev=84706&r1=84705&r2=84706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp Tue Oct 20 19:12:08 2009
@@ -295,7 +295,7 @@
void MSP430AsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI)
{
- MSP430MCInstLower MCInstLowering(OutContext, Mang);
+ MSP430MCInstLower MCInstLowering(OutContext, *Mang, getFunctionNumber(), *MAI);
switch (MI->getOpcode()) {
case TargetInstrInfo::DBG_LABEL:
Modified: llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp?rev=84706&r1=84705&r2=84706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp Tue Oct 20 19:12:08 2009
@@ -45,6 +45,30 @@
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");
+ }
+
+}
Modified: llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h?rev=84706&r1=84705&r2=84706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h (original)
+++ llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h Tue Oct 20 19:12:08 2009
@@ -37,8 +37,8 @@
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) {
}
Modified: llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp?rev=84706&r1=84705&r2=84706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp Tue Oct 20 19:12:08 2009
@@ -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 @@
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);
}
-
}
Modified: llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h?rev=84706&r1=84705&r2=84706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h (original)
+++ llvm/trunk/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h Tue Oct 20 19:12:08 2009
@@ -27,17 +27,22 @@
/// 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;
};
}
More information about the llvm-commits
mailing list