Factor out asmprinter out of ppc

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54887 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2008-08-17 13:54:28 +00:00
parent 3c3bc48d33
commit 06be997654
5 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,15 @@
##===- lib/Target/X86/Makefile -----------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL = ../../../..
LIBRARYNAME = LLVMPowerPCAsmPrinter
# Hack: we need to include 'main' x86 target directory to grab private headers
CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
include $(LEVEL)/Makefile.common

View File

@ -1117,3 +1117,11 @@ FunctionPass *llvm::createPPCAsmPrinterPass(std::ostream &o,
return new PPCLinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
}
}
namespace {
static struct Register {
Register() {
PPCTargetMachine::registerAsmPrinter(createPPCAsmPrinterPass);
}
} Registrator;
}

View File

@ -7,7 +7,7 @@
#
##===----------------------------------------------------------------------===##
LEVEL = ../../..
LIBRARYNAME = LLVMPowerPC
LIBRARYNAME = LLVMPowerPCCodegen
TARGET = PPC
# Make sure that tblgen is run, first thing.
@ -17,4 +17,6 @@ BUILT_SOURCES = PPCGenInstrNames.inc PPCGenRegisterNames.inc \
PPCGenInstrInfo.inc PPCGenDAGISel.inc \
PPCGenSubtarget.inc PPCGenCallingConv.inc
DIRS = AsmPrinter
include $(LEVEL)/Makefile.common

View File

@ -26,6 +26,9 @@ X("ppc32", " PowerPC 32");
static RegisterTarget<PPC64TargetMachine>
Y("ppc64", " PowerPC 64");
// No assembler printer by default
PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;
const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
if (Subtarget.isDarwin())
return new PPCDarwinTargetAsmInfo(*this);
@ -132,7 +135,10 @@ bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
std::ostream &Out) {
PM.add(createPPCAsmPrinterPass(Out, *this));
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
if (AsmPrinterCtor)
PM.add(AsmPrinterCtor(Out, *this));
return false;
}
@ -158,8 +164,12 @@ bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
// Machine code emitter pass for PowerPC.
PM.add(createPPCCodeEmitterPass(*this, MCE));
if (DumpAsm)
PM.add(createPPCAsmPrinterPass(*cerr.stream(), *this));
if (DumpAsm) {
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
if (AsmPrinterCtor)
PM.add(AsmPrinterCtor(*cerr.stream(), *this));
}
return false;
}
@ -167,7 +177,11 @@ bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
bool DumpAsm, MachineCodeEmitter &MCE) {
// Machine code emitter pass for PowerPC.
PM.add(createPPCCodeEmitterPass(*this, MCE));
if (DumpAsm)
PM.add(createPPCAsmPrinterPass(*cerr.stream(), *this));
if (DumpAsm) {
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
if (AsmPrinterCtor)
PM.add(AsmPrinterCtor(*cerr.stream(), *this));
}
return false;
}

View File

@ -41,7 +41,13 @@ class PPCTargetMachine : public LLVMTargetMachine {
protected:
virtual const TargetAsmInfo *createTargetAsmInfo() const;
// To avoid having target depend on the asmprinter stuff libraries, asmprinter
// set this functions to ctor pointer at startup time if they are linked in.
typedef FunctionPass *(*AsmPrinterCtorFn)(std::ostream &o,
PPCTargetMachine &tm);
static AsmPrinterCtorFn AsmPrinterCtor;
public:
PPCTargetMachine(const Module &M, const std::string &FS, bool is64Bit);
@ -63,7 +69,11 @@ public:
virtual const PPCMachOWriterInfo *getMachOWriterInfo() const {
return &MachOWriterInfo;
}
static void registerAsmPrinter(AsmPrinterCtorFn F) {
AsmPrinterCtor = F;
}
// Pass Pipeline Configuration
virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);