mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-03 14:08:57 +00:00
[Object, MachO] Remove some code duplication. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239077 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fbfbe05819
commit
00faba70cc
@ -429,10 +429,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// Walk load commands.
|
||||
LoadCommandInfo getFirstLoadCommandInfo() const;
|
||||
LoadCommandInfo getNextLoadCommandInfo(const LoadCommandInfo &L) const;
|
||||
|
||||
MachO::mach_header_64 Header64;
|
||||
typedef SmallVector<const char*, 1> SectionList;
|
||||
SectionList Sections;
|
||||
|
@ -180,6 +180,29 @@ static uint32_t getSectionFlags(const MachOObjectFile *O,
|
||||
return Sect.flags;
|
||||
}
|
||||
|
||||
static MachOObjectFile::LoadCommandInfo
|
||||
getLoadCommandInfo(const MachOObjectFile *Obj, const char *Ptr) {
|
||||
MachOObjectFile::LoadCommandInfo Load;
|
||||
Load.Ptr = Ptr;
|
||||
Load.C = getStruct<MachO::load_command>(Obj, Load.Ptr);
|
||||
if (Load.C.cmdsize < 8)
|
||||
report_fatal_error("Load command with size < 8 bytes.");
|
||||
return Load;
|
||||
}
|
||||
|
||||
static MachOObjectFile::LoadCommandInfo
|
||||
getFirstLoadCommandInfo(const MachOObjectFile *Obj) {
|
||||
unsigned HeaderSize = Obj->is64Bit() ? sizeof(MachO::mach_header_64)
|
||||
: sizeof(MachO::mach_header);
|
||||
return getLoadCommandInfo(Obj, getPtr(Obj, HeaderSize));
|
||||
}
|
||||
|
||||
static MachOObjectFile::LoadCommandInfo
|
||||
getNextLoadCommandInfo(const MachOObjectFile *Obj,
|
||||
const MachOObjectFile::LoadCommandInfo &L) {
|
||||
return getLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize);
|
||||
}
|
||||
|
||||
MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
|
||||
bool Is64bits, std::error_code &EC)
|
||||
: ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
|
||||
@ -203,7 +226,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
|
||||
MachO::LoadCommandType SegmentLoadType = is64Bit() ?
|
||||
MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT;
|
||||
|
||||
LoadCommandInfo Load = getFirstLoadCommandInfo();
|
||||
LoadCommandInfo Load = getFirstLoadCommandInfo(this);
|
||||
for (unsigned I = 0; I < LoadCommandCount; ++I) {
|
||||
LoadCommands.push_back(Load);
|
||||
if (Load.C.cmd == MachO::LC_SYMTAB) {
|
||||
@ -271,7 +294,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
|
||||
Libraries.push_back(Load.Ptr);
|
||||
}
|
||||
if (I < LoadCommandCount - 1)
|
||||
Load = getNextLoadCommandInfo(Load);
|
||||
Load = getNextLoadCommandInfo(this, Load);
|
||||
}
|
||||
assert(LoadCommands.size() == LoadCommandCount);
|
||||
}
|
||||
@ -1974,29 +1997,6 @@ MachOObjectFile::getAnyRelocationSection(
|
||||
return SectionRef(DRI, this);
|
||||
}
|
||||
|
||||
MachOObjectFile::LoadCommandInfo
|
||||
MachOObjectFile::getFirstLoadCommandInfo() const {
|
||||
MachOObjectFile::LoadCommandInfo Load;
|
||||
|
||||
unsigned HeaderSize = is64Bit() ? sizeof(MachO::mach_header_64) :
|
||||
sizeof(MachO::mach_header);
|
||||
Load.Ptr = getPtr(this, HeaderSize);
|
||||
Load.C = getStruct<MachO::load_command>(this, Load.Ptr);
|
||||
if (Load.C.cmdsize < 8)
|
||||
report_fatal_error("Load command with size < 8 bytes.");
|
||||
return Load;
|
||||
}
|
||||
|
||||
MachOObjectFile::LoadCommandInfo
|
||||
MachOObjectFile::getNextLoadCommandInfo(const LoadCommandInfo &L) const {
|
||||
MachOObjectFile::LoadCommandInfo Next;
|
||||
Next.Ptr = L.Ptr + L.C.cmdsize;
|
||||
Next.C = getStruct<MachO::load_command>(this, Next.Ptr);
|
||||
if (Next.C.cmdsize < 8)
|
||||
report_fatal_error("Load command with size < 8 bytes.");
|
||||
return Next;
|
||||
}
|
||||
|
||||
MachO::section MachOObjectFile::getSection(DataRefImpl DRI) const {
|
||||
assert(DRI.d.a < Sections.size() && "Should have detected this earlier");
|
||||
return getStruct<MachO::section>(this, Sections[DRI.d.a]);
|
||||
|
Loading…
Reference in New Issue
Block a user