diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 7090022d692a..2ad993c9e14c 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -29,16 +29,15 @@ class raw_ostream; class MCELFStreamer : public MCObjectStreamer { public: - MCELFStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, TargetStreamer, TAB, OS, Emitter), - SeenIdent(false) {} + MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, + MCCodeEmitter *Emitter) + : MCObjectStreamer(Context, TAB, OS, Emitter), + SeenIdent(false) {} - MCELFStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter, - MCAssembler *Assembler) - : MCObjectStreamer(Context, TargetStreamer, TAB, OS, Emitter, Assembler), - SeenIdent(false) {} + MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, + MCCodeEmitter *Emitter, MCAssembler *Assembler) + : MCObjectStreamer(Context, TAB, OS, Emitter, Assembler), + SeenIdent(false) {} virtual ~MCELFStreamer(); diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 56675443015e..f6a7e713c4c1 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -40,12 +40,10 @@ class MCObjectStreamer : public MCStreamer { virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame); protected: - MCObjectStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &_OS, + MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS, MCCodeEmitter *_Emitter); - MCObjectStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &_OS, MCCodeEmitter *_Emitter, - MCAssembler *_Assembler); + MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS, + MCCodeEmitter *_Emitter, MCAssembler *_Assembler); ~MCObjectStreamer(); public: diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index eb68be77c2d0..4055d2b1d621 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -67,11 +67,11 @@ typedef std::pair MCSectionSubPair; /// be treated differently. Callers should always talk to a FooTargetStreamer. class MCTargetStreamer { protected: - MCStreamer *Streamer; + MCStreamer &Streamer; public: + MCTargetStreamer(MCStreamer &S); virtual ~MCTargetStreamer(); - void setStreamer(MCStreamer *S) { Streamer = S; } // Allow a target to add behavior to the EmitLabel of MCStreamer. virtual void emitLabel(MCSymbol *Symbol); @@ -82,6 +82,8 @@ public: class ARMTargetStreamer : public MCTargetStreamer { virtual void anchor(); public: + ARMTargetStreamer(MCStreamer &S); + virtual void emitFnStart() = 0; virtual void emitFnEnd() = 0; virtual void emitCantUnwind() = 0; @@ -147,7 +149,7 @@ class MCStreamer { SmallVector, 4> SectionStack; protected: - MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer); + MCStreamer(MCContext &Ctx); const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A, const MCSymbol *B); @@ -170,6 +172,10 @@ protected: public: virtual ~MCStreamer(); + void setTargetStreamer(MCTargetStreamer *TS) { + TargetStreamer.reset(TS); + } + /// State management /// virtual void reset(); @@ -708,9 +714,9 @@ MCStreamer *createNullStreamer(MCContext &Ctx); /// /// \param ShowInst - Whether to show the MCInst representation inline with /// the assembly. -MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer, - formatted_raw_ostream &OS, bool isVerboseAsm, - bool useLoc, bool useCFI, bool useDwarfDirectory, +MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, + bool isVerboseAsm, bool useLoc, bool useCFI, + bool useDwarfDirectory, MCInstPrinter *InstPrint = 0, MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0, bool ShowInst = false); @@ -733,9 +739,8 @@ MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB, /// createELFStreamer - Create a machine code streamer which will generate /// ELF format object files. -MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, - MCCodeEmitter *CE, bool RelaxAll, +MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, + raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll, bool NoExecStack); /// createPureStreamer - Create a machine code streamer which will generate diff --git a/llvm/include/llvm/Support/TargetRegistry.h b/llvm/include/llvm/Support/TargetRegistry.h index c52d6b41ab59..0f63b4c94541 100644 --- a/llvm/include/llvm/Support/TargetRegistry.h +++ b/llvm/include/llvm/Support/TargetRegistry.h @@ -46,13 +46,11 @@ namespace llvm { class MCRelocationInfo; class MCTargetAsmParser; class TargetMachine; - class MCTargetStreamer; class TargetOptions; class raw_ostream; class formatted_raw_ostream; MCStreamer *createAsmStreamer(MCContext &Ctx, - MCTargetStreamer *TargetStreamer, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, @@ -443,7 +441,7 @@ namespace llvm { return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI, useDwarfDirectory, InstPrint, CE, TAB, ShowInst); - return llvm::createAsmStreamer(Ctx, 0, OS, isVerboseAsm, useLoc, useCFI, + return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI, useDwarfDirectory, InstPrint, CE, TAB, ShowInst); } diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index c5c817c2a1d4..c1a9f80b5287 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -623,7 +623,7 @@ namespace { return Symbols.end(); } - RecordStreamer(MCContext &Context) : MCStreamer(Context, 0) {} + RecordStreamer(MCContext &Context) : MCStreamer(Context) {} virtual void EmitInstruction(const MCInst &Inst) { // Scan for values. diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index f586db34e92f..12bcb68dd8ad 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -66,11 +66,11 @@ private: virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame); public: - MCAsmStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - formatted_raw_ostream &os, bool isVerboseAsm, bool useLoc, - bool useCFI, bool useDwarfDirectory, MCInstPrinter *printer, + MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os, + bool isVerboseAsm, bool useLoc, bool useCFI, + bool useDwarfDirectory, MCInstPrinter *printer, MCCodeEmitter *emitter, MCAsmBackend *asmbackend, bool showInst) - : MCStreamer(Context, TargetStreamer), OS(os), MAI(Context.getAsmInfo()), + : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend), CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm), ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI), @@ -1381,12 +1381,11 @@ void MCAsmStreamer::FinishImpl() { } MCStreamer *llvm::createAsmStreamer(MCContext &Context, - MCTargetStreamer *TargetStreamer, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *IP, MCCodeEmitter *CE, MCAsmBackend *MAB, bool ShowInst) { - return new MCAsmStreamer(Context, TargetStreamer, OS, isVerboseAsm, useLoc, + return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, useCFI, useDwarfDirectory, IP, CE, MAB, ShowInst); } diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 8c9ad632135c..1f87f3dc5d8a 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -543,12 +543,10 @@ void MCELFStreamer::FinishImpl() { this->MCObjectStreamer::FinishImpl(); } -MCStreamer *llvm::createELFStreamer(MCContext &Context, - MCTargetStreamer *Streamer, - MCAsmBackend &MAB, raw_ostream &OS, - MCCodeEmitter *CE, bool RelaxAll, - bool NoExecStack) { - MCELFStreamer *S = new MCELFStreamer(Context, Streamer, MAB, OS, CE); +MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, + raw_ostream &OS, MCCodeEmitter *CE, + bool RelaxAll, bool NoExecStack) { + MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE); if (RelaxAll) S->getAssembler().setRelaxAll(true); if (NoExecStack) diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index d32c7fa8f164..41b87452e345 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -38,7 +38,7 @@ private: public: MCMachOStreamer(MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS, MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, 0, MAB, OS, Emitter) {} + : MCObjectStreamer(Context, MAB, OS, Emitter) {} /// @name MCStreamer Interface /// @{ diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp index 60ee930d19da..21339078063a 100644 --- a/llvm/lib/MC/MCNullStreamer.cpp +++ b/llvm/lib/MC/MCNullStreamer.cpp @@ -19,7 +19,7 @@ namespace { class MCNullStreamer : public MCStreamer { public: - MCNullStreamer(MCContext &Context) : MCStreamer(Context, 0) {} + MCNullStreamer(MCContext &Context) : MCStreamer(Context) {} /// @name MCStreamer Interface /// @{ diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 5c08610657e4..22f565f34e01 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -22,22 +22,17 @@ #include "llvm/Support/ErrorHandling.h" using namespace llvm; -MCObjectStreamer::MCObjectStreamer(MCContext &Context, - MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, - MCCodeEmitter *Emitter_) - : MCStreamer(Context, TargetStreamer), +MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, + raw_ostream &OS, MCCodeEmitter *Emitter_) + : MCStreamer(Context), Assembler(new MCAssembler(Context, TAB, *Emitter_, *TAB.createObjectWriter(OS), OS)), CurSectionData(0) {} -MCObjectStreamer::MCObjectStreamer(MCContext &Context, - MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, - MCCodeEmitter *Emitter_, +MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, + raw_ostream &OS, MCCodeEmitter *Emitter_, MCAssembler *_Assembler) - : MCStreamer(Context, TargetStreamer), Assembler(_Assembler), - CurSectionData(0) {} + : MCStreamer(Context), Assembler(_Assembler), CurSectionData(0) {} MCObjectStreamer::~MCObjectStreamer() { delete &Assembler->getBackend(); diff --git a/llvm/lib/MC/MCPureStreamer.cpp b/llvm/lib/MC/MCPureStreamer.cpp index 179ed1e0e82a..1fd83379bbec 100644 --- a/llvm/lib/MC/MCPureStreamer.cpp +++ b/llvm/lib/MC/MCPureStreamer.cpp @@ -29,7 +29,7 @@ private: public: MCPureStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, 0, TAB, OS, Emitter) {} + : MCObjectStreamer(Context, TAB, OS, Emitter) {} /// @name MCStreamer Interface /// @{ diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 0b7c90671908..8cbfc5c83e51 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -25,14 +25,17 @@ using namespace llvm; // Pin the vtables to this file. MCTargetStreamer::~MCTargetStreamer() {} + +MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) { + S.setTargetStreamer(this); +} + void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {} -MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer) - : Context(Ctx), TargetStreamer(TargetStreamer), EmitEHFrame(true), - EmitDebugFrame(false), CurrentW64UnwindInfo(0), LastSymbol(0) { +MCStreamer::MCStreamer(MCContext &Ctx) + : Context(Ctx), EmitEHFrame(true), EmitDebugFrame(false), + CurrentW64UnwindInfo(0), LastSymbol(0) { SectionStack.push_back(std::pair()); - if (TargetStreamer) - TargetStreamer->setStreamer(this); } MCStreamer::~MCStreamer() { diff --git a/llvm/lib/MC/WinCOFFStreamer.cpp b/llvm/lib/MC/WinCOFFStreamer.cpp index 3f7baf9038e5..e3dd03ced55e 100644 --- a/llvm/lib/MC/WinCOFFStreamer.cpp +++ b/llvm/lib/MC/WinCOFFStreamer.cpp @@ -99,7 +99,7 @@ private: WinCOFFStreamer::WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, MCCodeEmitter &CE, raw_ostream &OS) - : MCObjectStreamer(Context, 0, MAB, OS, &CE), CurSymbol(NULL) {} + : MCObjectStreamer(Context, MAB, OS, &CE), CurSymbol(NULL) {} void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, bool External) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index a64c463f9e5c..6e680bdabbc0 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -57,7 +57,7 @@ class AArch64ELFStreamer : public MCELFStreamer { public: AArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter) - : MCELFStreamer(Context, 0, TAB, OS, Emitter), MappingSymbolCounter(0), + : MCELFStreamer(Context, TAB, OS, Emitter), MappingSymbolCounter(0), LastEMS(EMS_None) {} ~AArch64ELFStreamer() {} diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index abacc1e3126d..707a3d3f2ed8 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -105,6 +105,7 @@ static unsigned GetArchDefaultCPUArch(unsigned ID) { } void ARMTargetStreamer::anchor() {} +ARMTargetStreamer::ARMTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} namespace { @@ -139,14 +140,16 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer { virtual void finishAttributeSection(); public: - ARMTargetAsmStreamer(formatted_raw_ostream &OS, MCInstPrinter &InstPrinter, - bool VerboseAsm); + ARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS, + MCInstPrinter &InstPrinter, bool VerboseAsm); }; -ARMTargetAsmStreamer::ARMTargetAsmStreamer(formatted_raw_ostream &OS, +ARMTargetAsmStreamer::ARMTargetAsmStreamer(MCStreamer &S, + formatted_raw_ostream &OS, MCInstPrinter &InstPrinter, bool VerboseAsm) - : OS(OS), InstPrinter(InstPrinter), IsVerboseAsm(VerboseAsm) {} + : ARMTargetStreamer(S), OS(OS), InstPrinter(InstPrinter), + IsVerboseAsm(VerboseAsm) {} void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; } void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; } void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; } @@ -397,10 +400,9 @@ private: size_t calculateContentSize() const; public: - ARMTargetELFStreamer() - : ARMTargetStreamer(), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU), - Arch(ARM::INVALID_ARCH), AttributeSection(0) { - } + ARMTargetELFStreamer(MCStreamer &S) + : ARMTargetStreamer(S), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU), + Arch(ARM::INVALID_ARCH), AttributeSection(0) {} }; /// Extend the generic ELFStreamer class so that it can emit mapping symbols at @@ -419,11 +421,10 @@ class ARMELFStreamer : public MCELFStreamer { public: friend class ARMTargetELFStreamer; - ARMELFStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer, - MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter, - bool IsThumb) - : MCELFStreamer(Context, TargetStreamer, TAB, OS, Emitter), - IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None) { + ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, + MCCodeEmitter *Emitter, bool IsThumb) + : MCELFStreamer(Context, TAB, OS, Emitter), IsThumb(IsThumb), + MappingSymbolCounter(0), LastEMS(EMS_None) { Reset(); } @@ -627,8 +628,7 @@ private: } // end anonymous namespace ARMELFStreamer &ARMTargetELFStreamer::getStreamer() { - ARMELFStreamer *S = static_cast(Streamer); - return *S; + return static_cast(Streamer); } void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); } @@ -1237,21 +1237,19 @@ MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) { - ARMTargetAsmStreamer *S = new ARMTargetAsmStreamer(OS, *InstPrint, - isVerboseAsm); - - return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI, - useDwarfDirectory, InstPrint, CE, TAB, - ShowInst); + MCStreamer *S = + llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI, + useDwarfDirectory, InstPrint, CE, TAB, ShowInst); + new ARMTargetAsmStreamer(*S, OS, *InstPrint, isVerboseAsm); + return S; } MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack, bool IsThumb) { - ARMTargetELFStreamer *TS = new ARMTargetELFStreamer(); - ARMELFStreamer *S = - new ARMELFStreamer(Context, TS, TAB, OS, Emitter, IsThumb); + ARMELFStreamer *S = new ARMELFStreamer(Context, TAB, OS, Emitter, IsThumb); + new ARMTargetELFStreamer(*S); // FIXME: This should eventually end up somewhere else where more // intelligent flag decisions can be made. For now we are just maintaining // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default. diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp index add6e4b751be..2dea1fd1687d 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp @@ -131,8 +131,10 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack) { - MipsTargetELFStreamer *S = new MipsTargetELFStreamer(); - return createELFStreamer(Context, S, MAB, OS, Emitter, RelaxAll, NoExecStack); + MCStreamer *S = + createELFStreamer(Context, MAB, OS, Emitter, RelaxAll, NoExecStack); + new MipsTargetELFStreamer(*S); + return S; } static MCStreamer * @@ -140,11 +142,11 @@ createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) { - MipsTargetAsmStreamer *S = new MipsTargetAsmStreamer(OS); - - return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI, - useDwarfDirectory, InstPrint, CE, TAB, - ShowInst); + MCStreamer *S = + llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI, + useDwarfDirectory, InstPrint, CE, TAB, ShowInst); + new MipsTargetAsmStreamer(*S, OS); + return S; } extern "C" void LLVMInitializeMipsTargetMC() { diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index f4304cf6e4f7..d635bbf80f3c 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -27,8 +27,11 @@ static cl::opt PrintHackDirectives("print-hack-directives", // Pin vtable to this file. void MipsTargetStreamer::anchor() {} -MipsTargetAsmStreamer::MipsTargetAsmStreamer(formatted_raw_ostream &OS) - : OS(OS) {} +MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} + +MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S, + formatted_raw_ostream &OS) + : MipsTargetStreamer(S), OS(OS) {} void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) { if (!PrintHackDirectives) @@ -93,7 +96,8 @@ void MipsTargetAsmStreamer::emitDirectiveOptionPic0() { } // This part is for ELF object output. -MipsTargetELFStreamer::MipsTargetELFStreamer() : MicroMipsEnabled(false) {} +MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S) + : MipsTargetStreamer(S), MicroMipsEnabled(false) {} void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) { if (!isMicroMipsEnabled()) @@ -110,7 +114,7 @@ void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) { } MCELFStreamer &MipsTargetELFStreamer::getStreamer() { - return static_cast(*Streamer); + return static_cast(Streamer); } void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) { diff --git a/llvm/lib/Target/Mips/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MipsTargetStreamer.h index 0080f26088c2..b9272dc28587 100644 --- a/llvm/lib/Target/Mips/MipsTargetStreamer.h +++ b/llvm/lib/Target/Mips/MipsTargetStreamer.h @@ -18,6 +18,7 @@ class MipsTargetStreamer : public MCTargetStreamer { virtual void anchor(); public: + MipsTargetStreamer(MCStreamer &S); virtual void emitMipsHackELFFlags(unsigned Flags) = 0; virtual void emitDirectiveSetMicroMips() = 0; virtual void emitDirectiveSetNoMicroMips() = 0; @@ -42,7 +43,7 @@ class MipsTargetAsmStreamer : public MipsTargetStreamer { formatted_raw_ostream &OS; public: - MipsTargetAsmStreamer(formatted_raw_ostream &OS); + MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); virtual void emitMipsHackELFFlags(unsigned Flags); virtual void emitDirectiveSetMicroMips(); virtual void emitDirectiveSetNoMicroMips(); @@ -69,7 +70,7 @@ class MipsTargetELFStreamer : public MipsTargetStreamer { public: bool isMicroMipsEnabled() const { return MicroMipsEnabled; } MCELFStreamer &getStreamer(); - MipsTargetELFStreamer(); + MipsTargetELFStreamer(MCStreamer &S); virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE; diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp index 5dea2bf3e07c..bb01e15b248d 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -39,6 +39,7 @@ using namespace llvm; // Pin the vtable to this file. PPCTargetStreamer::~PPCTargetStreamer() {} +PPCTargetStreamer::PPCTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} static MCInstrInfo *createPPCMCInstrInfo() { MCInstrInfo *X = new MCInstrInfo(); @@ -112,7 +113,8 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer { formatted_raw_ostream &OS; public: - PPCTargetAsmStreamer(formatted_raw_ostream &OS) : OS(OS) {} + PPCTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS) + : PPCTargetStreamer(S), OS(OS) {} virtual void emitTCEntry(const MCSymbol &S) { OS << "\t.tc "; OS << S.getName(); @@ -126,9 +128,11 @@ public: }; class PPCTargetELFStreamer : public PPCTargetStreamer { +public: + PPCTargetELFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {} virtual void emitTCEntry(const MCSymbol &S) { // Creates a R_PPC64_TOC relocation - Streamer->EmitSymbolValue(&S, 8); + Streamer.EmitSymbolValue(&S, 8); } virtual void emitMachine(StringRef CPU) { // FIXME: Is there anything to do in here or does this directive only @@ -147,8 +151,10 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, if (Triple(TT).isOSDarwin()) return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll); - PPCTargetStreamer *S = new PPCTargetELFStreamer(); - return createELFStreamer(Ctx, S, MAB, OS, Emitter, RelaxAll, NoExecStack); + MCStreamer *S = + createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack); + new PPCTargetELFStreamer(*S); + return S; } static MCStreamer * @@ -156,11 +162,12 @@ createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) { - PPCTargetStreamer *S = new PPCTargetAsmStreamer(OS); - return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI, - useDwarfDirectory, InstPrint, CE, TAB, - ShowInst); + MCStreamer *S = + llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI, + useDwarfDirectory, InstPrint, CE, TAB, ShowInst); + new PPCTargetAsmStreamer(*S, OS); + return S; } static MCInstPrinter *createPPCMCInstPrinter(const Target &T, diff --git a/llvm/lib/Target/PowerPC/PPCTargetStreamer.h b/llvm/lib/Target/PowerPC/PPCTargetStreamer.h index 6f0125f2a868..74b5f4584525 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetStreamer.h +++ b/llvm/lib/Target/PowerPC/PPCTargetStreamer.h @@ -15,6 +15,7 @@ namespace llvm { class PPCTargetStreamer : public MCTargetStreamer { public: + PPCTargetStreamer(MCStreamer &S); virtual ~PPCTargetStreamer(); virtual void emitTCEntry(const MCSymbol &S) = 0; virtual void emitMachine(StringRef CPU) = 0; diff --git a/llvm/lib/Target/R600/MCTargetDesc/AMDGPUMCTargetDesc.cpp b/llvm/lib/Target/R600/MCTargetDesc/AMDGPUMCTargetDesc.cpp index a1bec2827646..61d70bb34292 100644 --- a/llvm/lib/Target/R600/MCTargetDesc/AMDGPUMCTargetDesc.cpp +++ b/llvm/lib/Target/R600/MCTargetDesc/AMDGPUMCTargetDesc.cpp @@ -88,7 +88,7 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, MCCodeEmitter *_Emitter, bool RelaxAll, bool NoExecStack) { - return createELFStreamer(Ctx, 0, MAB, _OS, _Emitter, false, false); + return createELFStreamer(Ctx, MAB, _OS, _Emitter, false, false); } extern "C" void LLVMInitializeR600TargetMC() { diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp index 2dbfff2014ae..97d1dae4c807 100644 --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp @@ -105,8 +105,10 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack) { - SparcTargetELFStreamer *S = new SparcTargetELFStreamer(); - return createELFStreamer(Context, S, MAB, OS, Emitter, RelaxAll, NoExecStack); + MCStreamer *S = + createELFStreamer(Context, MAB, OS, Emitter, RelaxAll, NoExecStack); + new SparcTargetELFStreamer(*S); + return S; } static MCStreamer * @@ -114,11 +116,12 @@ createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) { - SparcTargetAsmStreamer *S = new SparcTargetAsmStreamer(OS); - return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI, - useDwarfDirectory, InstPrint, CE, TAB, - ShowInst); + MCStreamer *S = + llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI, + useDwarfDirectory, InstPrint, CE, TAB, ShowInst); + new SparcTargetAsmStreamer(*S, OS); + return S; } static MCInstPrinter *createSparcMCInstPrinter(const Target &T, diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp index 01043aed5eee..94af791e0e75 100644 --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp @@ -18,10 +18,13 @@ using namespace llvm; // pin vtable to this file +SparcTargetStreamer::SparcTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} + void SparcTargetStreamer::anchor() {} -SparcTargetAsmStreamer::SparcTargetAsmStreamer(formatted_raw_ostream &OS) - : OS(OS) {} +SparcTargetAsmStreamer::SparcTargetAsmStreamer(MCStreamer &S, + formatted_raw_ostream &OS) + : SparcTargetStreamer(S), OS(OS) {} void SparcTargetAsmStreamer::emitSparcRegisterIgnore(unsigned reg) { OS << "\t.register " @@ -35,6 +38,9 @@ void SparcTargetAsmStreamer::emitSparcRegisterScratch(unsigned reg) { << ", #scratch\n"; } +SparcTargetELFStreamer::SparcTargetELFStreamer(MCStreamer &S) + : SparcTargetStreamer(S) {} + MCELFStreamer &SparcTargetELFStreamer::getStreamer() { - return static_cast(*Streamer); + return static_cast(Streamer); } diff --git a/llvm/lib/Target/Sparc/SparcTargetStreamer.h b/llvm/lib/Target/Sparc/SparcTargetStreamer.h index 73339acf8dfa..503ebd969c1f 100644 --- a/llvm/lib/Target/Sparc/SparcTargetStreamer.h +++ b/llvm/lib/Target/Sparc/SparcTargetStreamer.h @@ -18,6 +18,7 @@ class SparcTargetStreamer : public MCTargetStreamer { virtual void anchor(); public: + SparcTargetStreamer(MCStreamer &S); /// Emit ".register , #ignore". virtual void emitSparcRegisterIgnore(unsigned reg) = 0; /// Emit ".register , #scratch". @@ -29,7 +30,7 @@ class SparcTargetAsmStreamer : public SparcTargetStreamer { formatted_raw_ostream &OS; public: - SparcTargetAsmStreamer(formatted_raw_ostream &OS); + SparcTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); virtual void emitSparcRegisterIgnore(unsigned reg); virtual void emitSparcRegisterScratch(unsigned reg); @@ -38,6 +39,7 @@ public: // This part is for ELF object output class SparcTargetELFStreamer : public SparcTargetStreamer { public: + SparcTargetELFStreamer(MCStreamer &S); MCELFStreamer &getStreamer(); virtual void emitSparcRegisterIgnore(unsigned reg) {} virtual void emitSparcRegisterScratch(unsigned reg) {} diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp index 9e1296b912a0..19b2bcb921e4 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp @@ -187,7 +187,7 @@ static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack) { - return createELFStreamer(Ctx, 0, MAB, OS, Emitter, RelaxAll, NoExecStack); + return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack); } extern "C" void LLVMInitializeSystemZTargetMC() { diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index fd79c6aea2e0..65557de2e015 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -371,7 +371,7 @@ static MCStreamer *createMCStreamer(const Target &T, StringRef TT, if (TheTriple.isOSWindows() && TheTriple.getEnvironment() != Triple::ELF) return createWinCOFFStreamer(Ctx, MAB, *_Emitter, _OS, RelaxAll); - return createELFStreamer(Ctx, 0, MAB, _OS, _Emitter, RelaxAll, NoExecStack); + return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack); } static MCInstPrinter *createX86MCInstPrinter(const Target &T,