[llvm] r239077 - [Object, MachO] Remove some code duplication. NFC.

Alexey Samsonov vonosmas at gmail.com
Thu Jun 4 12:34:14 PDT 2015


Author: samsonov
Date: Thu Jun  4 14:34:14 2015
New Revision: 239077

URL: http://llvm.org/viewvc/llvm-project?rev=239077&view=rev
Log:
[Object, MachO] Remove some code duplication. NFC.

Modified:
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/lib/Object/MachOObjectFile.cpp

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=239077&r1=239076&r2=239077&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Thu Jun  4 14:34:14 2015
@@ -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;

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=239077&r1=239076&r2=239077&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Thu Jun  4 14:34:14 2015
@@ -180,6 +180,29 @@ static uint32_t getSectionFlags(const Ma
   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(MemoryB
   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(MemoryB
       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]);





More information about the llvm-commits mailing list