diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2008-08-17 13:54:28 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2008-08-17 13:54:28 +0000 |
commit | 06be997654120c92f99850bf1a1704a2042ef639 (patch) | |
tree | 1101fde06edb3351a7b9c66bce5419d762162b99 | |
parent | 3c3bc48d331db26aaff3ff4f7a61f60a17fea112 (diff) | |
download | external_llvm-06be997654120c92f99850bf1a1704a2042ef639.zip external_llvm-06be997654120c92f99850bf1a1704a2042ef639.tar.gz external_llvm-06be997654120c92f99850bf1a1704a2042ef639.tar.bz2 |
Factor out asmprinter out of ppc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54887 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/PowerPC/AsmPrinter/Makefile | 15 | ||||
-rw-r--r-- | lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (renamed from lib/Target/PowerPC/PPCAsmPrinter.cpp) | 8 | ||||
-rw-r--r-- | lib/Target/PowerPC/Makefile | 4 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCTargetMachine.cpp | 24 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCTargetMachine.h | 14 |
5 files changed, 57 insertions, 8 deletions
diff --git a/lib/Target/PowerPC/AsmPrinter/Makefile b/lib/Target/PowerPC/AsmPrinter/Makefile new file mode 100644 index 0000000..640bf02 --- /dev/null +++ b/lib/Target/PowerPC/AsmPrinter/Makefile @@ -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 diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 1c54590..c5ed305 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -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; +} diff --git a/lib/Target/PowerPC/Makefile b/lib/Target/PowerPC/Makefile index 6cf3fa3..2ec959c 100644 --- a/lib/Target/PowerPC/Makefile +++ b/lib/Target/PowerPC/Makefile @@ -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 diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp index 7c90eca..7857848 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -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; } diff --git a/lib/Target/PowerPC/PPCTargetMachine.h b/lib/Target/PowerPC/PPCTargetMachine.h index ac2c2aa..58fd55d 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.h +++ b/lib/Target/PowerPC/PPCTargetMachine.h @@ -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); |