mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-13 09:33:50 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207343 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
31c99ddfbd
commit
d54ec77c0d
74
include/llvm/MC/MCWinCOFFStreamer.h
Normal file
74
include/llvm/MC/MCWinCOFFStreamer.h
Normal file
@ -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
|
||||
|
@ -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::EmitSymbolAttribute(MCSymbol *Symbol,
|
||||
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(MCSymbol const *Symbol) {
|
||||
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::EmitCOFFSymbolStorageClass(int StorageClass) {
|
||||
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(int Type) {
|
||||
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::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
|
||||
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(MCSymbol const *Symbol) {
|
||||
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(MCSymbol *Symbol, uint64_t Size,
|
||||
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::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
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::EmitWin64EHHandlerData() {
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user