From 745dacc91d7ee9531bfba76b21beb5d4eef93a7d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 16 Dec 2010 03:05:59 +0000 Subject: [PATCH] MC: Make TargetAsmBackend available to the AsmStreamer. - Treaty talks on the non-proliferation of MC objects broke down. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121949 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCStreamer.h | 5 +++++ include/llvm/Target/TargetRegistry.h | 5 ++++- lib/CodeGen/LLVMTargetMachine.cpp | 7 +++++-- lib/MC/MCAsmStreamer.cpp | 18 +++++++++++------- lib/Target/PTX/PTXMCAsmStreamer.cpp | 3 ++- lib/Target/PTX/PTXTargetMachine.cpp | 1 + tools/llvm-mc/llvm-mc.cpp | 8 ++++++-- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 00c1600b324..b85ea3fae11 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -426,6 +426,10 @@ namespace llvm { /// \param CE - If given, a code emitter to use to show the instruction /// encoding inline with the assembly. This method takes ownership of \arg CE. /// + /// \param TAB - If given, a target asm backend to use to show the fixup + /// information in conjunction with encoding information. This method takes + /// ownership of \arg TAB. + /// /// \param ShowInst - Whether to show the MCInst representation inline with /// the assembly. MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, @@ -433,6 +437,7 @@ namespace llvm { bool useLoc, MCInstPrinter *InstPrint = 0, MCCodeEmitter *CE = 0, + TargetAsmBackend *TAB = 0, bool ShowInst = false); /// createMachOStreamer - Create a machine code streamer which will generate diff --git a/include/llvm/Target/TargetRegistry.h b/include/llvm/Target/TargetRegistry.h index fe2146b8d8f..6cdb68f1348 100644 --- a/include/llvm/Target/TargetRegistry.h +++ b/include/llvm/Target/TargetRegistry.h @@ -46,6 +46,7 @@ namespace llvm { bool useLoc, MCInstPrinter *InstPrint, MCCodeEmitter *CE, + TargetAsmBackend *TAB, bool ShowInst); /// Target - Wrapper for Target specific information. @@ -95,6 +96,7 @@ namespace llvm { bool useLoc, MCInstPrinter *InstPrint, MCCodeEmitter *CE, + TargetAsmBackend *TAB, bool ShowInst); private: @@ -323,10 +325,11 @@ namespace llvm { bool useLoc, MCInstPrinter *InstPrint, MCCodeEmitter *CE, + TargetAsmBackend *TAB, bool ShowInst) const { // AsmStreamerCtorFn is default to llvm::createAsmStreamer return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, - InstPrint, CE, ShowInst); + InstPrint, CE, TAB, ShowInst); } /// @} diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index af94365218c..564d593d7a5 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -143,14 +143,17 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, // Create a code emitter if asked to show the encoding. MCCodeEmitter *MCE = 0; - if (ShowMCEncoding) + TargetAsmBackend *TAB = 0; + if (ShowMCEncoding) { MCE = getTarget().createCodeEmitter(*this, *Context); + TAB = getTarget().createAsmBackend(TargetTriple); + } MCStreamer *S = getTarget().createAsmStreamer(*Context, Out, getVerboseAsm(), hasMCUseLoc(), InstPrinter, - MCE, + MCE, TAB, ShowMCInst); AsmStreamer.reset(S); break; diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index a1c02208a0b..3d041cbac28 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -23,8 +23,9 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetAsmBackend.h" #include "llvm/Target/TargetAsmInfo.h" +#include "llvm/Target/TargetLoweringObjectFile.h" using namespace llvm; namespace { @@ -34,6 +35,7 @@ class MCAsmStreamer : public MCStreamer { const MCAsmInfo &MAI; OwningPtr InstPrinter; OwningPtr Emitter; + OwningPtr AsmBackend; SmallString<128> CommentToEmit; raw_svector_ostream CommentStream; @@ -48,10 +50,12 @@ public: MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os, bool isVerboseAsm, bool useLoc, - MCInstPrinter *printer, MCCodeEmitter *emitter, bool showInst) + MCInstPrinter *printer, MCCodeEmitter *emitter, + TargetAsmBackend *asmbackend, + bool showInst) : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), - InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit), - IsVerboseAsm(isVerboseAsm), + InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend), + CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm), ShowInst(showInst), UseLoc(useLoc) { if (InstPrinter && IsVerboseAsm) InstPrinter->setCommentStream(CommentStream); @@ -893,8 +897,8 @@ void MCAsmStreamer::Finish() { MCStreamer *llvm::createAsmStreamer(MCContext &Context, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, - MCInstPrinter *IP, - MCCodeEmitter *CE, bool ShowInst) { + MCInstPrinter *IP, MCCodeEmitter *CE, + TargetAsmBackend *TAB, bool ShowInst) { return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, - IP, CE, ShowInst); + IP, CE, TAB, ShowInst); } diff --git a/lib/Target/PTX/PTXMCAsmStreamer.cpp b/lib/Target/PTX/PTXMCAsmStreamer.cpp index ec9dc960be7..313647c48ba 100644 --- a/lib/Target/PTX/PTXMCAsmStreamer.cpp +++ b/lib/Target/PTX/PTXMCAsmStreamer.cpp @@ -540,7 +540,8 @@ namespace llvm { formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, MCInstPrinter *IP, - MCCodeEmitter *CE, bool ShowInst) { + MCCodeEmitter *CE, TargetAsmBackend *TAB, + bool ShowInst) { return new PTXMCAsmStreamer(Context, OS, isVerboseAsm, useLoc, IP, CE, ShowInst); } diff --git a/lib/Target/PTX/PTXTargetMachine.cpp b/lib/Target/PTX/PTXTargetMachine.cpp index 0e9f5181ed5..a041d07ec1c 100644 --- a/lib/Target/PTX/PTXTargetMachine.cpp +++ b/lib/Target/PTX/PTXTargetMachine.cpp @@ -24,6 +24,7 @@ namespace llvm { bool isVerboseAsm, bool useLoc, MCInstPrinter *InstPrint, MCCodeEmitter *CE, + TargetAsmBackend *TAB, bool ShowInst); } diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index c59c80a0501..6bf4931cac3 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -340,10 +340,14 @@ static int AssembleInput(const char *ProgName) { MCInstPrinter *IP = TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI); MCCodeEmitter *CE = 0; - if (ShowEncoding) + TargetAsmBackend *TAB = 0; + if (ShowEncoding) { CE = TheTarget->createCodeEmitter(*TM, Ctx); + TAB = TheTarget->createAsmBackend(TripleName); + } Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true, - /*useLoc*/ true, IP, CE, ShowInst)); + /*useLoc*/ true, IP, CE, TAB, + ShowInst)); } else if (FileType == OFT_Null) { Str.reset(createNullStreamer(Ctx)); } else {