fix a circular dependency between the mips code generator

and its asmprinter.

llvm-svn: 73573
This commit is contained in:
Chris Lattner 2009-06-16 22:38:04 +00:00
parent 4533a55696
commit ca52e86346
3 changed files with 28 additions and 4 deletions

View File

@ -579,6 +579,14 @@ doFinalization(Module &M)
return AsmPrinter::doFinalization(M); return AsmPrinter::doFinalization(M);
} }
namespace {
static struct Register {
Register() {
MipsTargetMachine::registerAsmPrinter(createMipsCodePrinterPass);
}
} Registrator;
}
// Force static initialization when called from // Force static initialization when called from
// llvm/InitializeAllAsmPrinters.h // llvm/InitializeAllAsmPrinters.h
namespace llvm { namespace llvm {

View File

@ -31,6 +31,9 @@ int MipsTargetMachineModule = 0;
static RegisterTarget<MipsTargetMachine> X("mips", "Mips"); static RegisterTarget<MipsTargetMachine> X("mips", "Mips");
static RegisterTarget<MipselTargetMachine> Y("mipsel", "Mipsel"); static RegisterTarget<MipselTargetMachine> Y("mipsel", "Mipsel");
MipsTargetMachine::AsmPrinterCtorFn MipsTargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization when called from llvm/InitializeAllTargets.h
namespace llvm { namespace llvm {
void InitializeMipsTarget() { } void InitializeMipsTarget() { }
@ -130,9 +133,9 @@ addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
// true if AssemblyEmitter is supported // true if AssemblyEmitter is supported
bool MipsTargetMachine:: bool MipsTargetMachine::
addAssemblyEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, addAssemblyEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
bool Verbose, raw_ostream &Out) bool Verbose, raw_ostream &Out) {
{
// Output assembly language. // Output assembly language.
PM.add(createMipsCodePrinterPass(Out, *this, OptLevel, Verbose)); assert(AsmPrinterCtor && "AsmPrinter was not linked in");
PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
return false; return false;
} }

View File

@ -33,10 +33,23 @@ namespace llvm {
protected: protected:
virtual const TargetAsmInfo *createTargetAsmInfo() const; virtual const TargetAsmInfo *createTargetAsmInfo() const;
protected:
// 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)(raw_ostream &o,
MipsTargetMachine &tm,
CodeGenOpt::Level OptLevel,
bool verbose);
static AsmPrinterCtorFn AsmPrinterCtor;
public: public:
MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle); MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle);
static void registerAsmPrinter(AsmPrinterCtorFn F) {
AsmPrinterCtor = F;
}
virtual const MipsInstrInfo *getInstrInfo() const virtual const MipsInstrInfo *getInstrInfo() const
{ return &InstrInfo; } { return &InstrInfo; }
virtual const TargetFrameInfo *getFrameInfo() const virtual const TargetFrameInfo *getFrameInfo() const