MC: style tweaks to WinCOFFStreamer

Stylistic changes to prepare for splitting up the COFFStreamer into target
specific streamers.  Tweak some assertion messages.  No functional change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207342 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool 2014-04-27 03:48:01 +00:00
parent 2c2af22832
commit 31c99ddfbd

View File

@ -40,9 +40,7 @@ class WinCOFFStreamer : public MCObjectStreamer {
public:
MCSymbol const *CurSymbol;
WinCOFFStreamer(MCContext &Context,
MCAsmBackend &MAB,
MCCodeEmitter &CE,
WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, MCCodeEmitter &CE,
raw_ostream &OS);
// MCStreamer interface
@ -65,10 +63,10 @@ public:
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 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;
@ -124,6 +122,7 @@ void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
void WinCOFFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
EmitLabel(Symbol);
}
void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
llvm_unreachable("not implemented");
}
@ -135,24 +134,22 @@ void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
bool WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) {
assert(Symbol && "Symbol must be non-null!");
assert((Symbol->isInSection()
? Symbol->getSection().getVariant() == MCSection::SV_COFF
: true) && "Got non-COFF section in the COFF backend!");
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
switch (Attribute) {
default: return false;
case MCSA_WeakReference:
case MCSA_Weak: {
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
SD.setExternal(true);
}
case MCSA_Weak:
SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
SD.setExternal(true);
break;
case MCSA_Global:
getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
SD.setExternal(true);
break;
default:
return false;
}
return true;
@ -163,68 +160,64 @@ void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
}
void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
assert((Symbol->isInSection()
? Symbol->getSection().getVariant() == MCSection::SV_COFF
: true) && "Got non-COFF section in the COFF backend!");
assert(!CurSymbol && "EndCOFFSymbolDef must be called between calls "
"to BeginCOFFSymbolDef!");
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
assert(!CurSymbol && "starting new symbol definition in a symbol definition");
CurSymbol = Symbol;
}
void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
assert(CurSymbol && "BeginCOFFSymbolDef must be called first!");
assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
"the first byte!");
assert(CurSymbol && "StorageClass specified outside of symbol definition");
assert((StorageClass & ~0xFF) == 0 &&
"StorageClass must only have data in the first byte!");
getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
StorageClass << COFF::SF_ClassShift,
COFF::SF_ClassMask);
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*CurSymbol);
SD.modifyFlags(StorageClass << COFF::SF_ClassShift, COFF::SF_ClassMask);
}
void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
assert(CurSymbol && "BeginCOFFSymbolDef must be called first!");
assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
"bytes");
assert(CurSymbol && "SymbolType specified outside of a symbol definition");
assert((Type & ~0xFFFF) == 0 &&
"Type must only have data in the first 2 bytes");
getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
Type << COFF::SF_TypeShift,
COFF::SF_TypeMask);
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*CurSymbol);
SD.modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask);
}
void WinCOFFStreamer::EndCOFFSymbolDef() {
assert(CurSymbol && "BeginCOFFSymbolDef must be called first!");
assert(CurSymbol && "ending symbol definition without beginning one");
CurSymbol = nullptr;
}
void WinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
MCDataFragment *DF = getOrCreateDataFragment();
DF->getFixups().push_back(MCFixup::Create(
DF->getContents().size(), MCSymbolRefExpr::Create(Symbol, getContext()),
FK_SecRel_2));
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol, getContext());
MCFixup Fixup = MCFixup::Create(DF->getContents().size(), SRE, FK_SecRel_2);
DF->getFixups().push_back(Fixup);
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
MCDataFragment *DF = getOrCreateDataFragment();
DF->getFixups().push_back(MCFixup::Create(
DF->getContents().size(), MCSymbolRefExpr::Create(Symbol, getContext()),
FK_SecRel_4));
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::Create(Symbol, getContext());
MCFixup Fixup = MCFixup::Create(DF->getContents().size(), SRE, FK_SecRel_4);
DF->getFixups().push_back(Fixup);
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
llvm_unreachable("not implemented");
llvm_unreachable("not supported");
}
void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert((Symbol->isInSection()
? Symbol->getSection().getVariant() == MCSection::SV_COFF
: true) && "Got non-COFF section in the COFF backend!");
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
if (ByteAlignment > 32)
report_fatal_error(
"The linker won't align common symbols beyond 32 bytes.");
report_fatal_error("alignment is limited to 32-bytes");
AssignSection(Symbol, nullptr);
@ -251,12 +244,13 @@ void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
new MCAlignFragment(ByteAlignment, /*_Value=*/0, /*_ValueSize=*/0,
ByteAlignment, &SectionData);
SD.setFragment(
new MCFillFragment(/*_Value=*/0, /*_ValueSize=*/0, Size, &SectionData));
MCFillFragment *Fragment =
new MCFillFragment(/*_Value=*/0, /*_ValueSize=*/0, Size, &SectionData);
SD.setFragment(Fragment);
}
void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
uint64_t Size,unsigned ByteAlignment) {
uint64_t Size, unsigned ByteAlignment) {
llvm_unreachable("not implemented");
}
@ -271,7 +265,7 @@ void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
// TODO: Implement this if you want to emit .comment section in COFF obj files.
void WinCOFFStreamer::EmitIdent(StringRef IdentString) {
llvm_unreachable("unsupported directive");
llvm_unreachable("not implemented");
}
void WinCOFFStreamer::EmitWin64EHHandlerData() {
@ -288,15 +282,13 @@ void WinCOFFStreamer::FinishImpl() {
MCObjectStreamer::FinishImpl();
}
namespace llvm
{
MCStreamer *createWinCOFFStreamer(MCContext &Context,
MCAsmBackend &MAB,
MCCodeEmitter &CE,
raw_ostream &OS,
bool RelaxAll) {
WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
S->getAssembler().setRelaxAll(RelaxAll);
return S;
}
namespace llvm {
MCStreamer *createWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
MCCodeEmitter &CE, raw_ostream &OS,
bool RelaxAll) {
WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
S->getAssembler().setRelaxAll(RelaxAll);
return S;
}
}