[llvm] r179534 - Remove getters now that we can specialize structs on the host endianness.

Rafael Espindola rafael.espindola at gmail.com
Mon Apr 15 09:08:02 PDT 2013


Author: rafael
Date: Mon Apr 15 11:08:02 2013
New Revision: 179534

URL: http://llvm.org/viewvc/llvm-project?rev=179534&view=rev
Log:
Remove getters now that we can specialize structs on the host endianness.

Modified:
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/tools/llvm-readobj/MachODumper.cpp

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=179534&r1=179533&r2=179534&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Mon Apr 15 11:08:02 2013
@@ -148,91 +148,96 @@ namespace MachOFormat {
     }
   };
 
-  template<endianness TargetEndianness>
+  template<bool HostIsLittleEndian, endianness TargetEndianness>
   struct RelocationEntry;
 
   template<>
-  struct RelocationEntry<support::little> {
+  struct RelocationEntry<true, support::little> {
     LLVM_MACHOB_IMPORT_TYPES(support::little)
     MachOInt32 Address;
     MachOInt24 SymbolNum;
-    uint8_t Bits;
+    unsigned PCRel : 1;
+    unsigned Length : 2;
+    unsigned External : 1;
+    unsigned Type : 4;
+  };
 
-    unsigned getPCRel() const {
-      return Bits & 0x1;
-    }
-    unsigned getLength() const {
-      return (Bits >> 1) & 0x3;
-    }
-    unsigned getExternal() const {
-      return (Bits >> 3) & 0x1;
-    }
-    unsigned getType() const {
-      return Bits >> 4;
-    }
+  template<>
+  struct RelocationEntry<false, support::little> {
+    LLVM_MACHOB_IMPORT_TYPES(support::little)
+    MachOInt32 Address;
+    MachOInt24 SymbolNum;
+    unsigned Type : 4;
+    unsigned External : 1;
+    unsigned Length : 2;
+    unsigned PCRel : 1;
   };
 
   template<>
-  struct RelocationEntry<support::big> {
+  struct RelocationEntry<true, support::big> {
     LLVM_MACHOB_IMPORT_TYPES(support::big)
     MachOInt32 Address;
     MachOInt24 SymbolNum;
-    uint8_t Bits;
+    unsigned Type : 4;
+    unsigned External : 1;
+    unsigned Length : 2;
+    unsigned PCRel : 1;
+  };
 
-    unsigned getType() const {
-      return Bits &0xf;
-    }
-    unsigned getExternal() const {
-      return (Bits >> 4) & 0x1;
-    }
-    unsigned getLength() const {
-      return (Bits >> 5) & 0x3;
-    }
-    unsigned getPCRel() const {
-      return Bits >> 7;
-    }
+  template<>
+  struct RelocationEntry<false, support::big> {
+    LLVM_MACHOB_IMPORT_TYPES(support::big)
+    MachOInt32 Address;
+    MachOInt24 SymbolNum;
+    unsigned PCRel : 1;
+    unsigned Length : 2;
+    unsigned External : 1;
+    unsigned Type : 4;
   };
 
-  template<endianness TargetEndianness>
+  template<bool HostIsLittleEndian, endianness TargetEndianness>
   struct ScatteredRelocationEntry;
 
   template<>
-  struct ScatteredRelocationEntry<support::little> {
+  struct ScatteredRelocationEntry<true, support::little> {
     LLVM_MACHOB_IMPORT_TYPES(support::little)
     MachOInt24 Address;
-    uint8_t Bits;
+    unsigned Type : 4;
+    unsigned Length : 2;
+    unsigned PCRel : 1;
+    unsigned Scattered : 1;
     MachOInt32 Value;
+  };
 
-    unsigned getType() const {
-      return Bits & 0xf;
-    }
-    unsigned getLength() const {
-      return (Bits >> 4) & 0x3;
-    }
-    unsigned getPCRel() const {
-      return (Bits >> 6) & 0x1;
-    }
-    unsigned getScattered() const {
-      return Bits >> 7;
-    }
+  template<>
+  struct ScatteredRelocationEntry<false, support::little> {
+    LLVM_MACHOB_IMPORT_TYPES(support::little)
+    MachOInt24 Address;
+    unsigned Scattered : 1;
+    unsigned PCRel : 1;
+    unsigned Length : 2;
+    unsigned Type : 4;
+    MachOInt32 Value;
   };
 
   template<>
-  struct ScatteredRelocationEntry<support::big> {
+  struct ScatteredRelocationEntry<true, support::big> {
     LLVM_MACHOB_IMPORT_TYPES(support::big)
-    uint8_t Bits;
-    unsigned getType() const {
-      return Bits & 0xf;
-    }
-    unsigned getLength() const {
-      return (Bits >> 4) & 0x3;
-    }
-    unsigned getPCRel() const {
-      return (Bits >> 6) & 0x1;
-    }
-    unsigned getScattered() const {
-      return Bits >> 7;
-    }
+    unsigned Type : 4;
+    unsigned Length : 2;
+    unsigned PCRel : 1;
+    unsigned Scattered : 1;
+    MachOInt24 Address;
+    MachOInt32 Value;
+  };
+
+  template<>
+  struct ScatteredRelocationEntry<false, support::big> {
+    LLVM_MACHOB_IMPORT_TYPES(support::big)
+    unsigned Scattered : 1;
+    unsigned PCRel : 1;
+    unsigned Length : 2;
+    unsigned Type : 4;
     MachOInt24 Address;
     MachOInt32 Value;
   };
@@ -378,8 +383,8 @@ public:
     LinkeditDataLoadCommand;
   typedef MachOFormat::Header<TargetEndianness> Header;
   typedef MachOFormat::SymtabLoadCommand<TargetEndianness> SymtabLoadCommand;
-  typedef MachOFormat::RelocationEntry<TargetEndianness> RelocationEntry;
-  typedef MachOFormat::ScatteredRelocationEntry<TargetEndianness>
+  typedef MachOFormat::RelocationEntry<sys::IsLittleEndianHost, TargetEndianness> RelocationEntry;
+  typedef MachOFormat::ScatteredRelocationEntry<sys::IsLittleEndianHost, TargetEndianness>
     ScatteredRelocationEntry;
   typedef MachOFormat::LoadCommand<TargetEndianness> LoadCommand;
 
@@ -606,9 +611,9 @@ MachOObjectFileMiddle<E>::isRelocationPC
   if (isRelocationScattered(RE)) {
     const typename MachOObjectFileMiddle<E>::ScatteredRelocationEntry *SRE =
       reinterpret_cast<const typename ObjType::ScatteredRelocationEntry *>(RE);
-    return SRE->getPCRel();
+    return SRE->PCRel;
   }
-  return RE->getPCRel();
+  return RE->PCRel;
 }
 
 template<endianness E>
@@ -618,9 +623,9 @@ MachOObjectFileMiddle<E>::getRelocationL
   if (isRelocationScattered(RE)) {
     const typename ObjType::ScatteredRelocationEntry *SRE =
       reinterpret_cast<const typename ObjType::ScatteredRelocationEntry *>(RE);
-    return SRE->getLength();
+    return SRE->Length;
   }
-  return RE->getLength();
+  return RE->Length;
 }
 
 template<endianness E>
@@ -631,9 +636,9 @@ MachOObjectFileMiddle<E>::getRelocationT
   if (isRelocationScattered(RE)) {
     const typename ObjType::ScatteredRelocationEntry *SRE =
       reinterpret_cast<const typename ObjType::ScatteredRelocationEntry *>(RE);
-    return SRE->getType();
+    return SRE->Type;
   }
-  return RE->getType();
+  return RE->Type;
 }
 
 // Helper to advance a section or symbol iterator multiple increments at a time.
@@ -707,7 +712,7 @@ MachOObjectFileMiddle<E>::printRelocatio
   }
 
   StringRef S;
-  bool isExtern = RE->getExternal();
+  bool isExtern = RE->External;
   uint64_t Val = RE->Address;
 
   if (isExtern) {
@@ -1137,7 +1142,7 @@ MachOObjectFile<MachOT>::getRelocationSy
                                              SymbolRef &Res) const {
   const RelocationEntry *RE = getRelocation(Rel);
   uint32_t SymbolIdx = RE->SymbolNum;
-  bool isExtern = RE->getExternal();
+  bool isExtern = RE->External;
 
   DataRefImpl Sym;
   this->moveToNextSymbol(Sym);
@@ -1277,7 +1282,7 @@ MachOObjectFile<MachOT>::getRelocationVa
 
   // X86_64 has entirely custom relocation types.
   if (Arch == Triple::x86_64) {
-    bool isPCRel = RE->getPCRel();
+    bool isPCRel = RE->PCRel;
 
     switch (Type) {
       case macho::RIT_X86_64_GOTLoad:   // X86_64_RELOC_GOT_LOAD
@@ -1295,7 +1300,7 @@ MachOObjectFile<MachOT>::getRelocationVa
         // X86_64_SUBTRACTOR must be followed by a relocation of type
         // X86_64_RELOC_UNSIGNED.
         // NOTE: Scattered relocations don't exist on x86_64.
-        unsigned RType = RENext->getType();
+        unsigned RType = RENext->Type;
         if (RType != 0)
           report_fatal_error("Expected X86_64_RELOC_UNSIGNED after "
                              "X86_64_RELOC_SUBTRACTOR.");
@@ -1347,7 +1352,7 @@ MachOObjectFile<MachOT>::getRelocationVa
         if (isNextScattered)
           RType = (RENext->Address >> 24) & 0xF;
         else
-          RType = RENext->getType();
+          RType = RENext->Type;
         if (RType != 1)
           report_fatal_error("Expected GENERIC_RELOC_PAIR after "
                              "GENERIC_RELOC_SECTDIFF.");
@@ -1376,7 +1381,7 @@ MachOObjectFile<MachOT>::getRelocationVa
           if (isNextScattered)
             RType = (RENext->Address >> 24) & 0xF;
           else
-            RType = RENext->getType();
+            RType = RENext->Type;
           if (RType != 1)
             report_fatal_error("Expected GENERIC_RELOC_PAIR after "
                                "GENERIC_RELOC_LOCAL_SECTDIFF.");
@@ -1405,7 +1410,7 @@ MachOObjectFile<MachOT>::getRelocationVa
           if (IsScattered)
             isUpper = (RE->Address >> 28) & 1;
           else
-            isUpper = (RE->getLength() >> 1) & 1;
+            isUpper = (RE->Length >> 1) & 1;
 
           if (isUpper)
             fmt << ":upper16:(";
@@ -1425,7 +1430,7 @@ MachOObjectFile<MachOT>::getRelocationVa
           if (isNextScattered)
             RType = (RENext->Address >> 24) & 0xF;
           else
-            RType = RENext->getType();
+            RType = RENext->Type;
 
           if (RType != 1)
             report_fatal_error("Expected ARM_RELOC_PAIR after "
@@ -1481,7 +1486,7 @@ MachOObjectFile<MachOT>::getRelocationHi
       RelPrev.d.a--;
       const RelocationEntry *REPrev = this->getRelocation(RelPrev);
 
-      unsigned PrevType = REPrev->getType();
+      unsigned PrevType = REPrev->Type;
 
       if (PrevType == macho::RIT_X86_64_Subtractor) Result = true;
     }

Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/MachODumper.cpp?rev=179534&r1=179533&r2=179534&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Mon Apr 15 11:08:02 2013
@@ -376,8 +376,8 @@ void MachODumper::printRelocation(const
     if (IsScattered)
       W.printString("Extern", StringRef("N/A"));
     else
-      W.printNumber("Extern", RE->getExternal());
-    W.printNumber("Type", RelocName, RE->getType());
+      W.printNumber("Extern", RE->External);
+    W.printNumber("Type", RelocName, RE->Type);
     W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
     W.printNumber("Scattered", IsScattered);
   } else {
@@ -388,7 +388,7 @@ void MachODumper::printRelocation(const
     if (IsScattered)
       OS << " n/a";
     else
-      OS << " " << RE->getExternal();
+      OS << " " << RE->External;
     OS << " " << RelocName
        << " " << IsScattered
        << " " << (SymbolName.size() > 0 ? SymbolName : "-")





More information about the llvm-commits mailing list