diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h index 2817b0c421e..abffb5852a6 100644 --- a/include/llvm/Target/TargetRegistry.h +++ b/include/llvm/Target/TargetRegistry.h @@ -39,6 +39,13 @@ namespace llvm { class TargetAsmParser; class TargetMachine; class raw_ostream; + class formatted_raw_ostream; + + MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, + bool isLittleEndian, bool isVerboseAsm, + MCInstPrinter *InstPrint, + MCCodeEmitter *CE, + bool ShowInst); /// Target - Wrapper for Target specific information. /// @@ -81,6 +88,13 @@ namespace llvm { raw_ostream &_OS, MCCodeEmitter *_Emitter, bool RelaxAll); + typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx, + formatted_raw_ostream &OS, + bool isLittleEndian, + bool isVerboseAsm, + MCInstPrinter *InstPrint, + MCCodeEmitter *CE, + bool ShowInst); private: /// Next - The next registered target in the linked list, maintained by the @@ -138,7 +152,13 @@ namespace llvm { /// ObjectStreamer, if registered. ObjectStreamerCtorTy ObjectStreamerCtorFn; + /// AsmStreamerCtorFn - Construction function for this target's + /// AsmStreamer, if registered (default = llvm::createAsmStreamer). + AsmStreamerCtorTy AsmStreamerCtorFn; + public: + Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {} + /// @name Target Information /// @{ @@ -185,6 +205,9 @@ namespace llvm { /// hasObjectStreamer - Check if this target supports streaming to files. bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; } + /// hasAsmStreamer - Check if this target supports streaming to files. + bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; } + /// @} /// @name Feature Constructors /// @{ @@ -292,6 +315,19 @@ namespace llvm { return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll); } + /// createAsmStreamer - Create a target specific MCStreamer. + MCStreamer *createAsmStreamer(MCContext &Ctx, + formatted_raw_ostream &OS, + bool isLittleEndian, + bool isVerboseAsm, + MCInstPrinter *InstPrint, + MCCodeEmitter *CE, + bool ShowInst) const { + // AsmStreamerCtorFn is default to llvm::createAsmStreamer + return AsmStreamerCtorFn(Ctx, OS, isLittleEndian, isVerboseAsm, + InstPrint, CE, ShowInst); + } + /// @} }; @@ -513,7 +549,7 @@ namespace llvm { T.CodeEmitterCtorFn = Fn; } - /// RegisterObjectStreamer - Register an MCStreamer implementation + /// RegisterObjectStreamer - Register a object code MCStreamer implementation /// for the given target. /// /// Clients are responsible for ensuring that registration doesn't occur @@ -527,6 +563,20 @@ namespace llvm { T.ObjectStreamerCtorFn = Fn; } + /// RegisterAsmStreamer - Register an assembly MCStreamer implementation + /// for the given target. + /// + /// Clients are responsible for ensuring that registration doesn't occur + /// while another thread is attempting to access the registry. Typically + /// this is done by initializing all targets at program startup. + /// + /// @param T - The target being registered. + /// @param Fn - A function to construct an MCStreamer for the target. + static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) { + if (T.AsmStreamerCtorFn == createAsmStreamer) + T.AsmStreamerCtorFn = Fn; + } + /// @} }; diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index 60aa1e5c984..3ba1b89a802 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -144,10 +144,11 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, if (ShowMCEncoding) MCE = getTarget().createCodeEmitter(*this, *Context); - AsmStreamer.reset(createAsmStreamer(*Context, Out, - getTargetData()->isLittleEndian(), - getVerboseAsm(), InstPrinter, - MCE, ShowMCInst)); + AsmStreamer.reset(getTarget().createAsmStreamer(*Context, Out, + getTargetData()->isLittleEndian(), + getVerboseAsm(), + InstPrinter, MCE, + ShowMCInst)); break; } case CGFT_ObjectFile: { diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 9710805f9f9..67bb06b797d 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -342,9 +342,9 @@ static int AssembleInput(const char *ProgName) { MCCodeEmitter *CE = 0; if (ShowEncoding) CE = TheTarget->createCodeEmitter(*TM, Ctx); - Str.reset(createAsmStreamer(Ctx, FOS, - TM->getTargetData()->isLittleEndian(), - /*asmverbose*/true, IP, CE, ShowInst)); + Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, + TM->getTargetData()->isLittleEndian(), + /*asmverbose*/true, IP, CE, ShowInst)); } else if (FileType == OFT_Null) { Str.reset(createNullStreamer(Ctx)); } else {