Plug in basic hooks for an autogenerated asm printer to fill in.

llvm-svn: 24739
This commit is contained in:
Chris Lattner 2005-12-16 06:34:17 +00:00
parent 34e80f0114
commit 4870224a56
2 changed files with 19 additions and 14 deletions

View File

@ -13,7 +13,7 @@ TARGET = SparcV8
# Make sure that tblgen is run, first thing.
BUILT_SOURCES = SparcV8GenRegisterInfo.h.inc SparcV8GenRegisterNames.inc \
SparcV8GenRegisterInfo.inc SparcV8GenInstrNames.inc \
SparcV8GenInstrInfo.inc
SparcV8GenInstrInfo.inc SparcV8GenAsmWriter.inc
include $(LEVEL)/Makefile.common

View File

@ -33,7 +33,7 @@ using namespace llvm;
namespace {
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
struct V8Printer : public MachineFunctionPass {
struct SparcV8AsmPrinter : public MachineFunctionPass {
/// Output stream on which we're printing assembly code.
///
std::ostream &O;
@ -47,7 +47,7 @@ namespace {
///
Mangler *Mang;
V8Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) { }
SparcV8AsmPrinter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) { }
/// We name each basic block in a Function with a unique number, so
/// that we can consistently refer to them later. This is cleared
@ -72,12 +72,15 @@ namespace {
void printOperand(const MachineInstr *MI, int opNum);
void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true);
void printMachineInstruction(const MachineInstr *MI);
bool printInstruction(const MachineInstr *MI); // autogenerated.
bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M);
bool doFinalization(Module &M);
};
} // end of anonymous namespace
#include "SparcV8GenAsmWriter.inc"
/// createSparcV8CodePrinterPass - Returns a pass that prints the SparcV8
/// assembly code for a MachineFunction to the given output stream,
/// using the given target machine description. This should work
@ -85,7 +88,7 @@ namespace {
///
FunctionPass *llvm::createSparcV8CodePrinterPass (std::ostream &o,
TargetMachine &tm) {
return new V8Printer(o, tm);
return new SparcV8AsmPrinter(o, tm);
}
/// toOctal - Convert the low order bits of X into an octal digit.
@ -131,7 +134,7 @@ static void printAsCString(std::ostream &O, const ConstantArray *CVA) {
// Print out the specified constant, without a storage class. Only the
// constants valid in constant expressions can occur here.
void V8Printer::emitConstantValueOnly(const Constant *CV) {
void SparcV8AsmPrinter::emitConstantValueOnly(const Constant *CV) {
if (CV->isNullValue() || isa<UndefValue> (CV))
O << "0";
else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
@ -204,7 +207,7 @@ void V8Printer::emitConstantValueOnly(const Constant *CV) {
// Print a constant value or values, with the appropriate storage class as a
// prefix.
void V8Printer::emitGlobalConstant(const Constant *CV) {
void SparcV8AsmPrinter::emitGlobalConstant(const Constant *CV) {
const TargetData &TD = TM.getTargetData();
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
@ -299,7 +302,7 @@ void V8Printer::emitGlobalConstant(const Constant *CV) {
/// used to print out constants which have been "spilled to memory" by
/// the code generator.
///
void V8Printer::printConstantPool(MachineConstantPool *MCP) {
void SparcV8AsmPrinter::printConstantPool(MachineConstantPool *MCP) {
const std::vector<Constant*> &CP = MCP->getConstants();
const TargetData &TD = TM.getTargetData();
@ -318,7 +321,7 @@ void V8Printer::printConstantPool(MachineConstantPool *MCP) {
/// runOnMachineFunction - This uses the printMachineInstruction()
/// method to print assembly for each instruction.
///
bool V8Printer::runOnMachineFunction(MachineFunction &MF) {
bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// BBNumber is used here so that a given Printer will never give two
// BBs the same name. (If you have a better way, please let me know!)
static unsigned BBNumber = 0;
@ -355,7 +358,6 @@ bool V8Printer::runOnMachineFunction(MachineFunction &MF) {
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) {
// Print the assembly for the instruction.
O << "\t";
printMachineInstruction(II);
}
}
@ -364,7 +366,7 @@ bool V8Printer::runOnMachineFunction(MachineFunction &MF) {
return false;
}
void V8Printer::printOperand(const MachineInstr *MI, int opNum) {
void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
const MachineOperand &MO = MI->getOperand (opNum);
const MRegisterInfo &RI = *TM.getRegisterInfo();
bool CloseParen = false;
@ -472,7 +474,7 @@ static bool isPseudoInstruction (const MachineInstr *MI) {
/// brackets is true, or may be in the form base - constant, if offset is a
/// negative constant).
///
void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i,
void SparcV8AsmPrinter::printBaseOffsetPair (const MachineInstr *MI, int i,
bool brackets) {
if (brackets) O << "[";
printOperand (MI, i);
@ -492,7 +494,10 @@ void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i,
/// printMachineInstruction -- Print out a single SparcV8 LLVM instruction
/// MI in GAS syntax to the current output stream.
///
void V8Printer::printMachineInstruction(const MachineInstr *MI) {
void SparcV8AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
if (printInstruction(MI)) return;
O << "\t";
unsigned Opcode = MI->getOpcode();
const TargetInstrInfo &TII = *TM.getInstrInfo();
const TargetInstrDescriptor &Desc = TII.get(Opcode);
@ -549,7 +554,7 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) {
O << "\n";
}
bool V8Printer::doInitialization(Module &M) {
bool SparcV8AsmPrinter::doInitialization(Module &M) {
Mang = new Mangler(M);
return false; // success
}
@ -566,7 +571,7 @@ static void SwitchSection(std::ostream &OS, std::string &CurSection,
}
}
bool V8Printer::doFinalization(Module &M) {
bool SparcV8AsmPrinter::doFinalization(Module &M) {
const TargetData &TD = TM.getTargetData();
std::string CurSection;