From: Rafael Espindola Date: Mon, 15 Apr 2013 16:08:02 +0000 (+0000) Subject: Remove getters now that we can specialize structs on the host endianness. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c7f424d338754836906833b69da1ca56843feb71;p=oota-llvm.git Remove getters now that we can specialize structs on the host endianness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179534 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 6964c2e4ca5..88670689856 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -148,91 +148,96 @@ namespace MachOFormat { } }; - template + template struct RelocationEntry; template<> - struct RelocationEntry { + struct RelocationEntry { 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 { + 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 { + struct RelocationEntry { 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 { + LLVM_MACHOB_IMPORT_TYPES(support::big) + MachOInt32 Address; + MachOInt24 SymbolNum; + unsigned PCRel : 1; + unsigned Length : 2; + unsigned External : 1; + unsigned Type : 4; }; - template + template struct ScatteredRelocationEntry; template<> - struct ScatteredRelocationEntry { + struct ScatteredRelocationEntry { 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 { + 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 { + struct ScatteredRelocationEntry { 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 { + 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 Header; typedef MachOFormat::SymtabLoadCommand SymtabLoadCommand; - typedef MachOFormat::RelocationEntry RelocationEntry; - typedef MachOFormat::ScatteredRelocationEntry + typedef MachOFormat::RelocationEntry RelocationEntry; + typedef MachOFormat::ScatteredRelocationEntry ScatteredRelocationEntry; typedef MachOFormat::LoadCommand LoadCommand; @@ -606,9 +611,9 @@ MachOObjectFileMiddle::isRelocationPCRel(const RelocationEntry *RE) const { if (isRelocationScattered(RE)) { const typename MachOObjectFileMiddle::ScatteredRelocationEntry *SRE = reinterpret_cast(RE); - return SRE->getPCRel(); + return SRE->PCRel; } - return RE->getPCRel(); + return RE->PCRel; } template @@ -618,9 +623,9 @@ MachOObjectFileMiddle::getRelocationLength(const RelocationEntry *RE) const { if (isRelocationScattered(RE)) { const typename ObjType::ScatteredRelocationEntry *SRE = reinterpret_cast(RE); - return SRE->getLength(); + return SRE->Length; } - return RE->getLength(); + return RE->Length; } template @@ -631,9 +636,9 @@ MachOObjectFileMiddle::getRelocationTypeImpl(const RelocationEntry *RE) if (isRelocationScattered(RE)) { const typename ObjType::ScatteredRelocationEntry *SRE = reinterpret_cast(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::printRelocationTargetName(const RelocationEntry *RE, } StringRef S; - bool isExtern = RE->getExternal(); + bool isExtern = RE->External; uint64_t Val = RE->Address; if (isExtern) { @@ -1137,7 +1142,7 @@ MachOObjectFile::getRelocationSymbol(DataRefImpl Rel, 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::getRelocationValueString(DataRefImpl Rel, // 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::getRelocationValueString(DataRefImpl Rel, // 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::getRelocationValueString(DataRefImpl Rel, 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::getRelocationValueString(DataRefImpl Rel, 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::getRelocationValueString(DataRefImpl Rel, 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::getRelocationValueString(DataRefImpl Rel, 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::getRelocationHidden(DataRefImpl Rel, 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; } diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index d207eabb524..d4eaae615c8 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -376,8 +376,8 @@ void MachODumper::printRelocation(const MachOObjectFileMiddle *Obj, 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 MachOObjectFileMiddle *Obj, if (IsScattered) OS << " n/a"; else - OS << " " << RE->getExternal(); + OS << " " << RE->External; OS << " " << RelocName << " " << IsScattered << " " << (SymbolName.size() > 0 ? SymbolName : "-")