mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +00:00
MC: range-loopify
Use C++11 range-based loops rather than explicit constructors. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207393 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
98e5006d92
commit
1c5e4e5021
@ -662,8 +662,8 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MCAssembler::const_iterator i = Asm.begin(), e = Asm.end(); i != e; i++)
|
for (const auto & Section : Asm)
|
||||||
DefineSection(*i);
|
DefineSection(Section);
|
||||||
|
|
||||||
for (MCSymbolData &SD : Asm.symbols())
|
for (MCSymbolData &SD : Asm.symbols())
|
||||||
if (ExportSymbol(SD, Asm))
|
if (ExportSymbol(SD, Asm))
|
||||||
@ -808,77 +808,71 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
Header.NumberOfSections = 0;
|
Header.NumberOfSections = 0;
|
||||||
|
|
||||||
DenseMap<COFFSection *, uint16_t> SectionIndices;
|
DenseMap<COFFSection *, uint16_t> SectionIndices;
|
||||||
for (sections::iterator i = Sections.begin(),
|
for (auto & Section : Sections) {
|
||||||
e = Sections.end(); i != e; i++) {
|
if (Layout.getSectionAddressSize(Section->MCData) > 0) {
|
||||||
if (Layout.getSectionAddressSize((*i)->MCData) > 0) {
|
|
||||||
size_t Number = ++Header.NumberOfSections;
|
size_t Number = ++Header.NumberOfSections;
|
||||||
SectionIndices[i->get()] = Number;
|
SectionIndices[Section.get()] = Number;
|
||||||
MakeSectionReal(**i, Number);
|
MakeSectionReal(*Section, Number);
|
||||||
} else {
|
} else {
|
||||||
(*i)->Number = -1;
|
Section->Number = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Header.NumberOfSymbols = 0;
|
Header.NumberOfSymbols = 0;
|
||||||
|
|
||||||
for (symbols::iterator i = Symbols.begin(), e = Symbols.end(); i != e; i++) {
|
for (auto & Symbol : Symbols) {
|
||||||
COFFSymbol &coff_symbol = **i;
|
MCSymbolData const *SymbolData = Symbol->MCData;
|
||||||
MCSymbolData const *SymbolData = coff_symbol.MCData;
|
|
||||||
|
|
||||||
// Update section number & offset for symbols that have them.
|
// Update section number & offset for symbols that have them.
|
||||||
if (SymbolData && SymbolData->Fragment) {
|
if (SymbolData && SymbolData->Fragment) {
|
||||||
assert(coff_symbol.Section != nullptr);
|
assert(Symbol->Section != nullptr);
|
||||||
|
|
||||||
coff_symbol.Data.SectionNumber = coff_symbol.Section->Number;
|
Symbol->Data.SectionNumber = Symbol->Section->Number;
|
||||||
coff_symbol.Data.Value = Layout.getFragmentOffset(SymbolData->Fragment)
|
Symbol->Data.Value = Layout.getFragmentOffset(SymbolData->Fragment)
|
||||||
+ SymbolData->Offset;
|
+ SymbolData->Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coff_symbol.should_keep()) {
|
if (Symbol->should_keep()) {
|
||||||
MakeSymbolReal(coff_symbol, Header.NumberOfSymbols++);
|
MakeSymbolReal(*Symbol, Header.NumberOfSymbols++);
|
||||||
|
|
||||||
// Update auxiliary symbol info.
|
// Update auxiliary symbol info.
|
||||||
coff_symbol.Data.NumberOfAuxSymbols = coff_symbol.Aux.size();
|
Symbol->Data.NumberOfAuxSymbols = Symbol->Aux.size();
|
||||||
Header.NumberOfSymbols += coff_symbol.Data.NumberOfAuxSymbols;
|
Header.NumberOfSymbols += Symbol->Data.NumberOfAuxSymbols;
|
||||||
} else
|
} else
|
||||||
coff_symbol.Index = -1;
|
Symbol->Index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixup weak external references.
|
// Fixup weak external references.
|
||||||
for (symbols::iterator i = Symbols.begin(), e = Symbols.end(); i != e; i++) {
|
for (auto & Symbol : Symbols) {
|
||||||
COFFSymbol &coff_symbol = **i;
|
if (Symbol->Other) {
|
||||||
if (coff_symbol.Other) {
|
assert(Symbol->Index != -1);
|
||||||
assert(coff_symbol.Index != -1);
|
assert(Symbol->Aux.size() == 1 && "Symbol must contain one aux symbol!");
|
||||||
assert(coff_symbol.Aux.size() == 1 &&
|
assert(Symbol->Aux[0].AuxType == ATWeakExternal &&
|
||||||
"Symbol must contain one aux symbol!");
|
|
||||||
assert(coff_symbol.Aux[0].AuxType == ATWeakExternal &&
|
|
||||||
"Symbol's aux symbol must be a Weak External!");
|
"Symbol's aux symbol must be a Weak External!");
|
||||||
coff_symbol.Aux[0].Aux.WeakExternal.TagIndex = coff_symbol.Other->Index;
|
Symbol->Aux[0].Aux.WeakExternal.TagIndex = Symbol->Other->Index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixup associative COMDAT sections.
|
// Fixup associative COMDAT sections.
|
||||||
for (sections::iterator i = Sections.begin(),
|
for (auto & Section : Sections) {
|
||||||
e = Sections.end(); i != e; i++) {
|
if (Section->Symbol->Aux[0].Aux.SectionDefinition.Selection !=
|
||||||
if ((*i)->Symbol->Aux[0].Aux.SectionDefinition.Selection !=
|
|
||||||
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE)
|
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const MCSectionCOFF &MCSec = static_cast<const MCSectionCOFF &>(
|
const MCSectionCOFF &MCSec =
|
||||||
(*i)->MCData->getSection());
|
static_cast<const MCSectionCOFF &>(Section->MCData->getSection());
|
||||||
|
|
||||||
COFFSection *Assoc = SectionMap.lookup(MCSec.getAssocSection());
|
COFFSection *Assoc = SectionMap.lookup(MCSec.getAssocSection());
|
||||||
if (!Assoc) {
|
if (!Assoc)
|
||||||
report_fatal_error(Twine("Missing associated COMDAT section ") +
|
report_fatal_error(Twine("Missing associated COMDAT section ") +
|
||||||
MCSec.getAssocSection()->getSectionName() +
|
MCSec.getAssocSection()->getSectionName() +
|
||||||
" for section " + MCSec.getSectionName());
|
" for section " + MCSec.getSectionName());
|
||||||
}
|
|
||||||
|
|
||||||
// Skip this section if the associated section is unused.
|
// Skip this section if the associated section is unused.
|
||||||
if (Assoc->Number == -1)
|
if (Assoc->Number == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
(*i)->Symbol->Aux[0].Aux.SectionDefinition.Number = SectionIndices[Assoc];
|
Section->Symbol->Aux[0].Aux.SectionDefinition.Number = SectionIndices[Assoc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -889,15 +883,13 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
offset += COFF::HeaderSize;
|
offset += COFF::HeaderSize;
|
||||||
offset += COFF::SectionSize * Header.NumberOfSections;
|
offset += COFF::SectionSize * Header.NumberOfSections;
|
||||||
|
|
||||||
for (MCAssembler::const_iterator i = Asm.begin(),
|
for (const auto & Section : Asm) {
|
||||||
e = Asm.end();
|
COFFSection *Sec = SectionMap[&Section.getSection()];
|
||||||
i != e; i++) {
|
|
||||||
COFFSection *Sec = SectionMap[&i->getSection()];
|
|
||||||
|
|
||||||
if (Sec->Number == -1)
|
if (Sec->Number == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(i);
|
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
|
||||||
|
|
||||||
if (IsPhysicalSection(Sec)) {
|
if (IsPhysicalSection(Sec)) {
|
||||||
Sec->Header.PointerToRawData = offset;
|
Sec->Header.PointerToRawData = offset;
|
||||||
@ -924,16 +916,14 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
|
|
||||||
offset += COFF::RelocationSize * Sec->Relocations.size();
|
offset += COFF::RelocationSize * Sec->Relocations.size();
|
||||||
|
|
||||||
for (relocations::iterator cr = Sec->Relocations.begin(),
|
for (auto & Relocation : Sec->Relocations) {
|
||||||
er = Sec->Relocations.end();
|
assert(Relocation.Symb->Index != -1);
|
||||||
cr != er; ++cr) {
|
Relocation.Data.SymbolTableIndex = Relocation.Symb->Index;
|
||||||
assert((*cr).Symb->Index != -1);
|
|
||||||
(*cr).Data.SymbolTableIndex = (*cr).Symb->Index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(Sec->Symbol->Aux.size() == 1
|
assert(Sec->Symbol->Aux.size() == 1 &&
|
||||||
&& "Section's symbol must have one aux!");
|
"Section's symbol must have one aux!");
|
||||||
AuxSymbol &Aux = Sec->Symbol->Aux[0];
|
AuxSymbol &Aux = Sec->Symbol->Aux[0];
|
||||||
assert(Aux.AuxType == ATSectionDefinition &&
|
assert(Aux.AuxType == ATSectionDefinition &&
|
||||||
"Section's symbol's aux symbol must be a Section Definition!");
|
"Section's symbol's aux symbol must be a Section Definition!");
|
||||||
@ -956,13 +946,13 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
sections::iterator i, ie;
|
sections::iterator i, ie;
|
||||||
MCAssembler::const_iterator j, je;
|
MCAssembler::const_iterator j, je;
|
||||||
|
|
||||||
for (i = Sections.begin(), ie = Sections.end(); i != ie; i++)
|
for (auto & Section : Sections) {
|
||||||
if ((*i)->Number != -1) {
|
if (Section->Number != -1) {
|
||||||
if ((*i)->Relocations.size() >= 0xffff) {
|
if (Section->Relocations.size() >= 0xffff)
|
||||||
(*i)->Header.Characteristics |= COFF::IMAGE_SCN_LNK_NRELOC_OVFL;
|
Section->Header.Characteristics |= COFF::IMAGE_SCN_LNK_NRELOC_OVFL;
|
||||||
}
|
WriteSectionHeader(Section->Header);
|
||||||
WriteSectionHeader((*i)->Header);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = Sections.begin(), ie = Sections.end(),
|
for (i = Sections.begin(), ie = Sections.end(),
|
||||||
j = Asm.begin(), je = Asm.end();
|
j = Asm.begin(), je = Asm.end();
|
||||||
@ -992,11 +982,8 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
WriteRelocation(r);
|
WriteRelocation(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (relocations::const_iterator k = (*i)->Relocations.begin(),
|
for (const auto & Relocation : (*i)->Relocations)
|
||||||
ke = (*i)->Relocations.end();
|
WriteRelocation(Relocation.Data);
|
||||||
k != ke; k++) {
|
|
||||||
WriteRelocation(k->Data);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
assert((*i)->Header.PointerToRelocations == 0 &&
|
assert((*i)->Header.PointerToRelocations == 0 &&
|
||||||
"Section::PointerToRelocations is insane!");
|
"Section::PointerToRelocations is insane!");
|
||||||
@ -1006,9 +993,9 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
assert(OS.tell() == Header.PointerToSymbolTable &&
|
assert(OS.tell() == Header.PointerToSymbolTable &&
|
||||||
"Header::PointerToSymbolTable is insane!");
|
"Header::PointerToSymbolTable is insane!");
|
||||||
|
|
||||||
for (symbols::iterator i = Symbols.begin(), e = Symbols.end(); i != e; i++)
|
for (auto & Symbol : Symbols)
|
||||||
if ((*i)->Index != -1)
|
if (Symbol->Index != -1)
|
||||||
WriteSymbol(**i);
|
WriteSymbol(*Symbol);
|
||||||
|
|
||||||
OS.write((char const *)&Strings.Data.front(), Strings.Data.size());
|
OS.write((char const *)&Strings.Data.front(), Strings.Data.size());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user