aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2009-10-21 00:12:08 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2009-10-21 00:12:08 +0000
commitbaffc35d25adf06f1e50d722523376eee7b31152 (patch)
tree298c3c15e7f001a3d159171072e753a5c0fdccff
parent8a50ba5671ff1b454db4f22d8b5d22b4354d272b (diff)
downloadexternal_llvm-baffc35d25adf06f1e50d722523376eee7b31152.zip
external_llvm-baffc35d25adf06f1e50d722523376eee7b31152.tar.gz
external_llvm-baffc35d25adf06f1e50d722523376eee7b31152.tar.bz2
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
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp2
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp26
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h4
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp70
-rw-r--r--lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h15
5 files changed, 106 insertions, 11 deletions
diff --git a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
index e2f521f..baaf929 100644
--- a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
+++ b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
@@ -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:
diff --git a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
index 243a5e1..84a2e02 100644
--- a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
+++ b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
@@ -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");
+ }
+
+}
diff --git a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
index 1047f48..b6281cc 100644
--- a/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
+++ b/lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
@@ -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) {
}
diff --git a/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp b/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
index b839ac5..e9b0c92 100644
--- a/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
+++ b/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
@@ -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);
}
-
}
diff --git a/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h b/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h
index c6b0c3e..d2a76b9 100644
--- a/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h
+++ b/lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.h
@@ -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;
};
}