mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-26 02:22:29 +00:00
[MachOWriter] Use for-range and roll some duplicated code into loops.
No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239096 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -299,15 +299,9 @@ void MachObjectWriter::WriteDysymtabLoadCommand(uint32_t FirstLocalSymbol,
|
|||||||
|
|
||||||
MachObjectWriter::MachSymbolData *
|
MachObjectWriter::MachSymbolData *
|
||||||
MachObjectWriter::findSymbolData(const MCSymbol &Sym) {
|
MachObjectWriter::findSymbolData(const MCSymbol &Sym) {
|
||||||
for (auto &Entry : LocalSymbolData)
|
for (auto *SymbolData :
|
||||||
if (Entry.Symbol == &Sym)
|
{&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})
|
||||||
return &Entry;
|
for (MachSymbolData &Entry : *SymbolData)
|
||||||
|
|
||||||
for (auto &Entry : ExternalSymbolData)
|
|
||||||
if (Entry.Symbol == &Sym)
|
|
||||||
return &Entry;
|
|
||||||
|
|
||||||
for (auto &Entry : UndefinedSymbolData)
|
|
||||||
if (Entry.Symbol == &Sym)
|
if (Entry.Symbol == &Sym)
|
||||||
return &Entry;
|
return &Entry;
|
||||||
|
|
||||||
@@ -427,8 +421,8 @@ static unsigned ComputeLinkerOptionsLoadCommandSize(
|
|||||||
const std::vector<std::string> &Options, bool is64Bit)
|
const std::vector<std::string> &Options, bool is64Bit)
|
||||||
{
|
{
|
||||||
unsigned Size = sizeof(MachO::linker_option_command);
|
unsigned Size = sizeof(MachO::linker_option_command);
|
||||||
for (unsigned i = 0, e = Options.size(); i != e; ++i)
|
for (const std::string &Option : Options)
|
||||||
Size += Options[i].size() + 1;
|
Size += Option.size() + 1;
|
||||||
return RoundUpToAlignment(Size, is64Bit ? 8 : 4);
|
return RoundUpToAlignment(Size, is64Bit ? 8 : 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,9 +437,8 @@ void MachObjectWriter::WriteLinkerOptionsLoadCommand(
|
|||||||
Write32(Size);
|
Write32(Size);
|
||||||
Write32(Options.size());
|
Write32(Options.size());
|
||||||
uint64_t BytesWritten = sizeof(MachO::linker_option_command);
|
uint64_t BytesWritten = sizeof(MachO::linker_option_command);
|
||||||
for (unsigned i = 0, e = Options.size(); i != e; ++i) {
|
for (const std::string &Option : Options) {
|
||||||
// Write each string, including the null byte.
|
// Write each string, including the null byte.
|
||||||
const std::string &Option = Options[i];
|
|
||||||
WriteBytes(Option.c_str(), Option.size() + 1);
|
WriteBytes(Option.c_str(), Option.size() + 1);
|
||||||
BytesWritten += Option.size() + 1;
|
BytesWritten += Option.size() + 1;
|
||||||
}
|
}
|
||||||
@@ -607,16 +600,13 @@ void MachObjectWriter::ComputeSymbolTable(
|
|||||||
|
|
||||||
// Set the symbol indices.
|
// Set the symbol indices.
|
||||||
Index = 0;
|
Index = 0;
|
||||||
for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
|
for (auto *SymbolData :
|
||||||
LocalSymbolData[i].Symbol->setIndex(Index++);
|
{&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})
|
||||||
for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
|
for (MachSymbolData &Entry : *SymbolData)
|
||||||
ExternalSymbolData[i].Symbol->setIndex(Index++);
|
Entry.Symbol->setIndex(Index++);
|
||||||
for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
|
|
||||||
UndefinedSymbolData[i].Symbol->setIndex(Index++);
|
|
||||||
|
|
||||||
for (const MCSection &Section : Asm) {
|
for (const MCSection &Section : Asm) {
|
||||||
std::vector<RelAndSymbol> &Relocs = Relocations[&Section];
|
for (RelAndSymbol &Rel : Relocations[&Section]) {
|
||||||
for (RelAndSymbol &Rel : Relocs) {
|
|
||||||
if (!Rel.Sym)
|
if (!Rel.Sym)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -634,9 +624,7 @@ void MachObjectWriter::ComputeSymbolTable(
|
|||||||
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
||||||
const MCAsmLayout &Layout) {
|
const MCAsmLayout &Layout) {
|
||||||
uint64_t StartAddress = 0;
|
uint64_t StartAddress = 0;
|
||||||
const SmallVectorImpl<MCSection *> &Order = Layout.getSectionOrder();
|
for (const MCSection *Sec : Layout.getSectionOrder()) {
|
||||||
for (int i = 0, n = Order.size(); i != n ; ++i) {
|
|
||||||
const MCSection *Sec = Order[i];
|
|
||||||
StartAddress = RoundUpToAlignment(StartAddress, Sec->getAlignment());
|
StartAddress = RoundUpToAlignment(StartAddress, Sec->getAlignment());
|
||||||
SectionAddress[Sec] = StartAddress;
|
SectionAddress[Sec] = StartAddress;
|
||||||
StartAddress += Layout.getSectionAddressSize(Sec);
|
StartAddress += Layout.getSectionAddressSize(Sec);
|
||||||
@@ -771,12 +759,9 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the linker option load commands sizes.
|
// Add the linker option load commands sizes.
|
||||||
const std::vector<std::vector<std::string> > &LinkerOptions =
|
for (const auto &Option : Asm.getLinkerOptions()) {
|
||||||
Asm.getLinkerOptions();
|
|
||||||
for (unsigned i = 0, e = LinkerOptions.size(); i != e; ++i) {
|
|
||||||
++NumLoadCommands;
|
++NumLoadCommands;
|
||||||
LoadCommandsSize += ComputeLinkerOptionsLoadCommandSize(LinkerOptions[i],
|
LoadCommandsSize += ComputeLinkerOptionsLoadCommandSize(Option, is64Bit());
|
||||||
is64Bit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the total size of the section data, as well as its file size and vm
|
// Compute the total size of the section data, as well as its file size and vm
|
||||||
@@ -888,9 +873,8 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the linker options load commands.
|
// Write the linker options load commands.
|
||||||
for (unsigned i = 0, e = LinkerOptions.size(); i != e; ++i) {
|
for (const auto &Option : Asm.getLinkerOptions())
|
||||||
WriteLinkerOptionsLoadCommand(LinkerOptions[i]);
|
WriteLinkerOptionsLoadCommand(Option);
|
||||||
}
|
|
||||||
|
|
||||||
// Write the actual section data.
|
// Write the actual section data.
|
||||||
for (const MCSection &Sec : Asm) {
|
for (const MCSection &Sec : Asm) {
|
||||||
@@ -908,9 +892,9 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
// Write the section relocation entries, in reverse order to match 'as'
|
// Write the section relocation entries, in reverse order to match 'as'
|
||||||
// (approximately, the exact algorithm is more complicated than this).
|
// (approximately, the exact algorithm is more complicated than this).
|
||||||
std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
|
std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
|
||||||
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
for (const RelAndSymbol &Rel : make_range(Relocs.rbegin(), Relocs.rend())) {
|
||||||
Write32(Relocs[e - i - 1].MRE.r_word0);
|
Write32(Rel.MRE.r_word0);
|
||||||
Write32(Relocs[e - i - 1].MRE.r_word1);
|
Write32(Rel.MRE.r_word1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,12 +953,10 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
// FIXME: Check that offsets match computed ones.
|
// FIXME: Check that offsets match computed ones.
|
||||||
|
|
||||||
// Write the symbol table entries.
|
// Write the symbol table entries.
|
||||||
for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
|
for (auto *SymbolData :
|
||||||
WriteNlist(LocalSymbolData[i], Layout);
|
{&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})
|
||||||
for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
|
for (MachSymbolData &Entry : *SymbolData)
|
||||||
WriteNlist(ExternalSymbolData[i], Layout);
|
WriteNlist(Entry, Layout);
|
||||||
for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
|
|
||||||
WriteNlist(UndefinedSymbolData[i], Layout);
|
|
||||||
|
|
||||||
// Write the string table.
|
// Write the string table.
|
||||||
OS << StringTable.data();
|
OS << StringTable.data();
|
||||||
|
|||||||
Reference in New Issue
Block a user