[llvm] r207343 - MC: rename WinCOFFStreamer and move declaration out-of-line
Saleem Abdulrasool
compnerd at compnerd.org
Sun Apr 27 09:20:30 PDT 2014
On Sun, Apr 27, 2014 at 7:06 AM, Rafael EspĂndola <
rafael.espindola at gmail.com> wrote:
> While this is fine and matches what we did first for ELF, the current
> strategy on the ELF side is to put target specific bits in the target
> streamer interface. Do you think that would work in here?
I don't immediately see why it wouldn't. It would certainly be nicer.
I'll see if I can wrangle COFF into using MCTargetStreamer.
> On 26 April 2014 23:48, Saleem Abdulrasool <compnerd at compnerd.org> wrote:
> > Author: compnerd
> > Date: Sat Apr 26 22:48:05 2014
> > New Revision: 207343
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=207343&view=rev
> > Log:
> > MC: rename WinCOFFStreamer and move declaration out-of-line
> >
> > This is in preparation for promoting WinCOFFStreamer to a base class
> which will
> > be shared by the X86 and ARM specific target COFF streamers. Also add a
> new
> > getOrCreateSymbolData interface (like MCELFStreamer) for the ARM COFF
> Streamer.
> > This makes the COFFStreamer more similar to the ELFStreamer.
> >
> > Added:
> > llvm/trunk/include/llvm/MC/MCWinCOFFStreamer.h
> > Modified:
> > llvm/trunk/lib/MC/WinCOFFStreamer.cpp
> >
> > Added: llvm/trunk/include/llvm/MC/MCWinCOFFStreamer.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCWinCOFFStreamer.h?rev=207343&view=auto
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/MC/MCWinCOFFStreamer.h (added)
> > +++ llvm/trunk/include/llvm/MC/MCWinCOFFStreamer.h Sat Apr 26 22:48:05
> 2014
> > @@ -0,0 +1,74 @@
> > +//===- MCWinCOFFStreamer.h - COFF Object File Interface ---------*- C++
> -*-===//
> > +//
> > +// The LLVM Compiler Infrastructure
> > +//
> > +// This file is distributed under the University of Illinois Open Source
> > +// License. See LICENSE.TXT for details.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +
> > +#ifndef LLVM_MC_MCWINCOFFSTREAMER_H
> > +#define LLVM_MC_MCWINCOFFSTREAMER_H
> > +
> > +#include "llvm/MC/MCDirectives.h"
> > +#include "llvm/MC/MCObjectStreamer.h"
> > +
> > +namespace llvm {
> > +class MCAsmBackend;
> > +class MCContext;
> > +class MCCodeEmitter;
> > +class MCExpr;
> > +class MCInst;
> > +class MCSection;
> > +class MCSubtargetInfo;
> > +class MCSymbol;
> > +class StringRef;
> > +class raw_ostream;
> > +
> > +class MCWinCOFFStreamer : public MCObjectStreamer {
> > +public:
> > + MCWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
> MCCodeEmitter &CE,
> > + raw_ostream &OS);
> > +
> > + /// \name MCStreamer interface
> > + /// \{
> > +
> > + void InitSections() override;
> > + void EmitLabel(MCSymbol *Symbol) override;
> > + void EmitDebugLabel(MCSymbol *Symbol) override;
> > + void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
> > + void EmitThumbFunc(MCSymbol *Func) override;
> > + bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)
> override;
> > + void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
> > + void BeginCOFFSymbolDef(MCSymbol const *Symbol) override;
> > + void EmitCOFFSymbolStorageClass(int StorageClass) override;
> > + void EmitCOFFSymbolType(int Type) override;
> > + void EndCOFFSymbolDef() override;
> > + void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
> > + void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
> > + void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
> > + void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
> > + unsigned ByteAlignment) override;
> > + void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
> > + unsigned ByteAlignment) override;
> > + void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size,
> > + unsigned ByteAlignment) override;
> > + void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size,
> > + unsigned ByteAlignment) override;
> > + void EmitFileDirective(StringRef Filename) override;
> > + void EmitIdent(StringRef IdentString) override;
> > + void EmitWin64EHHandlerData() override;
> > + void FinishImpl() override;
> > +
> > + /// \}
> > +
> > + MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol);
> > +
> > +protected:
> > + const MCSymbol *CurSymbol;
> > + void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI)
> override;
> > +};
> > +}
> > +
> > +#endif
> > +
> >
> > Modified: llvm/trunk/lib/MC/WinCOFFStreamer.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFStreamer.cpp?rev=207343&r1=207342&r2=207343&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/MC/WinCOFFStreamer.cpp (original)
> > +++ llvm/trunk/lib/MC/WinCOFFStreamer.cpp Sat Apr 26 22:48:05 2014
> > @@ -7,7 +7,7 @@
> > //
> >
> //===----------------------------------------------------------------------===//
> > //
> > -// This file contains an implementation of a Win32 COFF object file
> streamer.
> > +// This file contains an implementation of a Windows COFF object file
> streamer.
> > //
> >
> //===----------------------------------------------------------------------===//
> >
> > @@ -25,6 +25,7 @@
> > #include "llvm/MC/MCSymbol.h"
> > #include "llvm/MC/MCValue.h"
> > #include "llvm/MC/MCWin64EH.h"
> > +#include "llvm/MC/MCWinCOFFStreamer.h"
> > #include "llvm/Support/COFF.h"
> > #include "llvm/Support/Debug.h"
> > #include "llvm/Support/ErrorHandling.h"
> > @@ -35,70 +36,31 @@ using namespace llvm;
> >
> > #define DEBUG_TYPE "WinCOFFStreamer"
> >
> > -namespace {
> > -class WinCOFFStreamer : public MCObjectStreamer {
> > -public:
> > - MCSymbol const *CurSymbol;
> > -
> > - WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, MCCodeEmitter
> &CE,
> > - raw_ostream &OS);
> > -
> > - // MCStreamer interface
> > -
> > - void InitSections() override;
> > - void EmitLabel(MCSymbol *Symbol) override;
> > - void EmitDebugLabel(MCSymbol *Symbol) override;
> > - void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
> > - void EmitThumbFunc(MCSymbol *Func) override;
> > - bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)
> override;
> > - void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
> > - void BeginCOFFSymbolDef(MCSymbol const *Symbol) override;
> > - void EmitCOFFSymbolStorageClass(int StorageClass) override;
> > - void EmitCOFFSymbolType(int Type) override;
> > - void EndCOFFSymbolDef() override;
> > - void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
> > - void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
> > - void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
> > - void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
> > - unsigned ByteAlignment) override;
> > - void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
> > - unsigned ByteAlignment) override;
> > - void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size,
> > - unsigned ByteAlignment) override;
> > - void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size,
> > - unsigned ByteAlignment) override;
> > - void EmitFileDirective(StringRef Filename) override;
> > - void EmitIdent(StringRef IdentString) override;
> > - void EmitWin64EHHandlerData() override;
> > - void FinishImpl() override;
> > -
> > -private:
> > - void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI)
> override {
> > - MCDataFragment *DF = getOrCreateDataFragment();
> > -
> > - SmallVector<MCFixup, 4> Fixups;
> > - SmallString<256> Code;
> > - raw_svector_ostream VecOS(Code);
> > - getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups,
> STI);
> > - VecOS.flush();
> > -
> > - // Add the fixups and data.
> > - for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
> > - Fixups[i].setOffset(Fixups[i].getOffset() +
> DF->getContents().size());
> > - DF->getFixups().push_back(Fixups[i]);
> > - }
> > - DF->getContents().append(Code.begin(), Code.end());
> > - }
> > -};
> > -} // end anonymous namespace.
> > -
> > -WinCOFFStreamer::WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
> > - MCCodeEmitter &CE, raw_ostream &OS)
> > +namespace llvm {
> > +MCWinCOFFStreamer::MCWinCOFFStreamer(MCContext &Context, MCAsmBackend
> &MAB,
> > + MCCodeEmitter &CE, raw_ostream &OS)
> > : MCObjectStreamer(Context, MAB, OS, &CE), CurSymbol(nullptr) {}
> >
> > -// MCStreamer interface
> > +void MCWinCOFFStreamer::EmitInstToData(const MCInst &Inst,
> > + const MCSubtargetInfo &STI) {
> > + MCDataFragment *DF = getOrCreateDataFragment();
> >
> > -void WinCOFFStreamer::InitSections() {
> > + SmallVector<MCFixup, 4> Fixups;
> > + SmallString<256> Code;
> > + raw_svector_ostream VecOS(Code);
> > + getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups,
> STI);
> > + VecOS.flush();
> > +
> > + // Add the fixups and data.
> > + for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
> > + Fixups[i].setOffset(Fixups[i].getOffset() +
> DF->getContents().size());
> > + DF->getFixups().push_back(Fixups[i]);
> > + }
> > +
> > + DF->getContents().append(Code.begin(), Code.end());
> > +}
> > +
> > +void MCWinCOFFStreamer::InitSections() {
> > // FIXME: this is identical to the ELF one.
> > // This emulates the same behavior of GNU as. This makes it easier
> > // to compare the output as the major sections are in the same order.
> > @@ -114,25 +76,25 @@ void WinCOFFStreamer::InitSections() {
> > SwitchSection(getContext().getObjectFileInfo()->getTextSection());
> > }
> >
> > -void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
> > +void MCWinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
> > assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
> > MCObjectStreamer::EmitLabel(Symbol);
> > }
> >
> > -void WinCOFFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
> > +void MCWinCOFFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
> > EmitLabel(Symbol);
> > }
> >
> > -void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
> > +void MCWinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
> > +void MCWinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -bool WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
> > - MCSymbolAttr Attribute) {
> > +bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
> > + MCSymbolAttr Attribute) {
> > assert(Symbol && "Symbol must be non-null!");
> > assert((!Symbol->isInSection() ||
> > Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
> > @@ -155,11 +117,11 @@ bool WinCOFFStreamer::EmitSymbolAttribut
> > return true;
> > }
> >
> > -void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned
> DescValue) {
> > +void MCWinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned
> DescValue) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
> > +void MCWinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
> > assert((!Symbol->isInSection() ||
> > Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
> > "Got non-COFF section in the COFF backend!");
> > @@ -167,7 +129,7 @@ void WinCOFFStreamer::BeginCOFFSymbolDef
> > CurSymbol = Symbol;
> > }
> >
> > -void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
> > +void MCWinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
> > assert(CurSymbol && "StorageClass specified outside of symbol
> definition");
> > assert((StorageClass & ~0xFF) == 0 &&
> > "StorageClass must only have data in the first byte!");
> > @@ -176,7 +138,7 @@ void WinCOFFStreamer::EmitCOFFSymbolStor
> > SD.modifyFlags(StorageClass << COFF::SF_ClassShift,
> COFF::SF_ClassMask);
> > }
> >
> > -void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
> > +void MCWinCOFFStreamer::EmitCOFFSymbolType(int Type) {
> > assert(CurSymbol && "SymbolType specified outside of a symbol
> definition");
> > assert((Type & ~0xFFFF) == 0 &&
> > "Type must only have data in the first 2 bytes");
> > @@ -185,12 +147,12 @@ void WinCOFFStreamer::EmitCOFFSymbolType
> > SD.modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask);
> > }
> >
> > -void WinCOFFStreamer::EndCOFFSymbolDef() {
> > +void MCWinCOFFStreamer::EndCOFFSymbolDef() {
> > assert(CurSymbol && "ending symbol definition without beginning one");
> > CurSymbol = nullptr;
> > }
> >
> > -void WinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
> > +void MCWinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
> > MCDataFragment *DF = getOrCreateDataFragment();
> > const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol,
> getContext());
> > MCFixup Fixup = MCFixup::Create(DF->getContents().size(), SRE,
> FK_SecRel_2);
> > @@ -198,7 +160,7 @@ void WinCOFFStreamer::EmitCOFFSectionInd
> > DF->getContents().resize(DF->getContents().size() + 4, 0);
> > }
> >
> > -void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
> > +void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
> > MCDataFragment *DF = getOrCreateDataFragment();
> > const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol,
> getContext());
> > MCFixup Fixup = MCFixup::Create(DF->getContents().size(), SRE,
> FK_SecRel_4);
> > @@ -206,12 +168,12 @@ void WinCOFFStreamer::EmitCOFFSecRel32(M
> > DF->getContents().resize(DF->getContents().size() + 4, 0);
> > }
> >
> > -void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr
> *Value) {
> > +void MCWinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr
> *Value) {
> > llvm_unreachable("not supported");
> > }
> >
> > -void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
> > - unsigned ByteAlignment) {
> > +void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t
> Size,
> > + unsigned ByteAlignment) {
> > assert((!Symbol->isInSection() ||
> > Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
> > "Got non-COFF section in the COFF backend!");
> > @@ -226,8 +188,8 @@ void WinCOFFStreamer::EmitCommonSymbol(M
> > SD.setCommon(Size, ByteAlignment);
> > }
> >
> > -void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
> Size,
> > - unsigned ByteAlignment) {
> > +void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol,
> uint64_t Size,
> > + unsigned ByteAlignment) {
> > assert(!Symbol->isInSection() && "Symbol must not already have a
> section!");
> >
> > const MCSection *Section =
> getContext().getObjectFileInfo()->getBSSSection();
> > @@ -249,26 +211,28 @@ void WinCOFFStreamer::EmitLocalCommonSym
> > SD.setFragment(Fragment);
> > }
> >
> > -void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol
> *Symbol,
> > - uint64_t Size, unsigned
> ByteAlignment) {
> > +void MCWinCOFFStreamer::EmitZerofill(const MCSection *Section,
> > + MCSymbol *Symbol, uint64_t Size,
> > + unsigned ByteAlignment) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol
> *Symbol,
> > - uint64_t Size, unsigned
> ByteAlignment) {
> > +void MCWinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section,
> > + MCSymbol *Symbol, uint64_t Size,
> > + unsigned ByteAlignment) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
> > +void MCWinCOFFStreamer::EmitFileDirective(StringRef Filename) {
> > getAssembler().addFileName(Filename);
> > }
> >
> > // TODO: Implement this if you want to emit .comment section in COFF
> obj files.
> > -void WinCOFFStreamer::EmitIdent(StringRef IdentString) {
> > +void MCWinCOFFStreamer::EmitIdent(StringRef IdentString) {
> > llvm_unreachable("not implemented");
> > }
> >
> > -void WinCOFFStreamer::EmitWin64EHHandlerData() {
> > +void MCWinCOFFStreamer::EmitWin64EHHandlerData() {
> > MCStreamer::EmitWin64EHHandlerData();
> >
> > // We have to emit the unwind info now, because this directive
> > @@ -276,17 +240,20 @@ void WinCOFFStreamer::EmitWin64EHHandler
> > MCWin64EHUnwindEmitter::EmitUnwindInfo(*this,
> getCurrentW64UnwindInfo());
> > }
> >
> > -void WinCOFFStreamer::FinishImpl() {
> > +void MCWinCOFFStreamer::FinishImpl() {
> > EmitFrames(nullptr, true);
> > EmitW64Tables();
> > MCObjectStreamer::FinishImpl();
> > }
> >
> > -namespace llvm {
> > +MCSymbolData &MCWinCOFFStreamer::getOrCreateSymbolData(const MCSymbol
> *Symbol) {
> > + return getAssembler().getOrCreateSymbolData(*Symbol);
> > +}
> > +
> > MCStreamer *createWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
> > MCCodeEmitter &CE, raw_ostream &OS,
> > bool RelaxAll) {
> > - WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
> > + MCWinCOFFStreamer *S = new MCWinCOFFStreamer(Context, MAB, CE, OS);
> > S->getAssembler().setRelaxAll(RelaxAll);
> > return S;
> > }
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140427/7b266cfc/attachment.html>
More information about the llvm-commits
mailing list