diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index 0a296cd29740..ffd77c51eb42 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -28,6 +28,7 @@ class MCFragment; class MCSection; class MCSectionData; class MCSymbol; +class TargetAsmBackend; /// MCAsmFixup - Represent a fixed size region of bytes inside some fragment /// which needs to be rewritten. This region will either be rewritten by the @@ -582,6 +583,8 @@ private: MCContext &Context; + TargetAsmBackend &Backend; + raw_ostream &OS; iplist Sections; @@ -617,7 +620,7 @@ public: // concrete and require clients to pass in a target like object. The other // option is to make this abstract, and have targets provide concrete // implementations as we do with AsmParser. - MCAssembler(MCContext &_Context, raw_ostream &OS); + MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, raw_ostream &OS); ~MCAssembler(); MCContext &getContext() const { return Context; } diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 6359ccefe63a..2f5f82853260 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -27,6 +27,7 @@ namespace llvm { class MCSection; class MCSymbol; class StringRef; +class TargetAsmBackend; class Twine; class raw_ostream; class formatted_raw_ostream; @@ -304,18 +305,10 @@ namespace llvm { MCCodeEmitter *CE = 0, bool ShowInst = false); - // FIXME: These two may end up getting rolled into a single - // createObjectStreamer interface, which implements the assembler backend, and - // is parameterized on an output object file writer. - /// createMachOStream - Create a machine code streamer which will generative /// Mach-O format object files. - MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS, - MCCodeEmitter *CE); - - /// createELFStreamer - Create a machine code streamer which will generative - /// ELF format object files. - MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS); + MCStreamer *createMachOStreamer(MCContext &Ctx, TargetAsmBackend &TAB, + raw_ostream &OS, MCCodeEmitter *CE); } // end namespace llvm diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h index a7062ac94f35..4ab2e5cf3d23 100644 --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -224,6 +224,8 @@ public: /// implemented with the LLVM target-independent code generator. /// class LLVMTargetMachine : public TargetMachine { + std::string TargetTriple; + protected: // Can only create subclasses. LLVMTargetMachine(const Target &T, const std::string &TargetTriple); diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp index 9bc0b7121d72..23ef8ba7ce44 100644 --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -94,8 +94,8 @@ static cl::opt EnableSplitGEPGVN("split-gep-gvn", cl::Hidden, cl::desc("Split GEPs and run no-load GVN")); LLVMTargetMachine::LLVMTargetMachine(const Target &T, - const std::string &TargetTriple) - : TargetMachine(T) { + const std::string &Triple) + : TargetMachine(T), TargetTriple(Triple) { AsmInfo = T.createAsmInfo(TargetTriple); } @@ -143,10 +143,11 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, // Create the code emitter for the target if it exists. If not, .o file // emission fails. MCCodeEmitter *MCE = getTarget().createCodeEmitter(*this, *Context); - if (MCE == 0) + TargetAsmBackend *TAB = getTarget().createAsmBackend(TargetTriple); + if (MCE == 0 || TAB == 0) return true; - AsmStreamer.reset(createMachOStreamer(*Context, Out, MCE)); + AsmStreamer.reset(createMachOStreamer(*Context, *TAB, Out, MCE)); // Any output to the asmprinter's "O" stream is bad and needs to be fixed, // force it to come out stderr. diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index f51be42cc9d4..277cf921254a 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -991,8 +991,9 @@ MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, /* *** */ -MCAssembler::MCAssembler(MCContext &_Context, raw_ostream &_OS) - : Context(_Context), OS(_OS), SubsectionsViaSymbols(false) +MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, + raw_ostream &_OS) + : Context(_Context), Backend(_Backend), OS(_OS), SubsectionsViaSymbols(false) { } diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index a35aae29a8ce..1a6fa4116921 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -59,8 +59,9 @@ private: } public: - MCMachOStreamer(MCContext &Context, raw_ostream &_OS, MCCodeEmitter *_Emitter) - : MCStreamer(Context), Assembler(Context, _OS), Emitter(_Emitter), + MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB, + raw_ostream &_OS, MCCodeEmitter *_Emitter) + : MCStreamer(Context), Assembler(Context, TAB, _OS), Emitter(_Emitter), CurSectionData(0) {} ~MCMachOStreamer() {} @@ -398,7 +399,7 @@ void MCMachOStreamer::Finish() { Assembler.Finish(); } -MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS, - MCCodeEmitter *CE) { - return new MCMachOStreamer(Context, OS, CE); +MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB, + raw_ostream &OS, MCCodeEmitter *CE) { + return new MCMachOStreamer(Context, TAB, OS, CE); } diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 76ce080caea5..fa87238a029e 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Signals.h" +#include "llvm/Target/TargetAsmBackend.h" #include "llvm/Target/TargetAsmParser.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetRegistry.h" @@ -259,6 +260,7 @@ static int AssembleInput(const char *ProgName) { OwningPtr IP; OwningPtr CE; OwningPtr Str; + OwningPtr TAB; const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); assert(MAI && "Unable to create target asm info!"); @@ -274,7 +276,8 @@ static int AssembleInput(const char *ProgName) { } else { assert(FileType == OFT_ObjectFile && "Invalid file type!"); CE.reset(TheTarget->createCodeEmitter(*TM, Ctx)); - Str.reset(createMachOStreamer(Ctx, *Out, CE.get())); + TAB.reset(TheTarget->createAsmBackend(TripleName)); + Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get())); } AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);