diff options
author | David Meyer <pdox@google.com> | 2012-03-09 20:41:57 +0000 |
---|---|---|
committer | David Meyer <pdox@google.com> | 2012-03-09 20:41:57 +0000 |
commit | 6f9489a86f33624f9ff5388411d12359ce9cef20 (patch) | |
tree | 24b05bed8391c0be6059143a5639605ec28f77b0 /include | |
parent | a8eb6bb408e84ceb468ceb409f4c87308e67b9eb (diff) | |
download | llvm-6f9489a86f33624f9ff5388411d12359ce9cef20.tar.gz llvm-6f9489a86f33624f9ff5388411d12359ce9cef20.tar.bz2 llvm-6f9489a86f33624f9ff5388411d12359ce9cef20.tar.xz |
[Object]
Make Binary::TypeID more granular, to distinguish between ELF 32/64 little/big
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152435 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Object/Archive.h | 2 | ||||
-rw-r--r-- | include/llvm/Object/Binary.h | 44 | ||||
-rw-r--r-- | include/llvm/Object/COFF.h | 2 | ||||
-rw-r--r-- | include/llvm/Object/ELF.h | 6 | ||||
-rw-r--r-- | include/llvm/Object/MachO.h | 2 | ||||
-rw-r--r-- | include/llvm/Object/ObjectFile.h | 3 |
6 files changed, 45 insertions, 14 deletions
diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index e6df85679d..358b27a416 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -131,7 +131,7 @@ public: // Cast methods. static inline bool classof(Archive const *v) { return true; } static inline bool classof(Binary const *v) { - return v->getType() == Binary::isArchive; + return v->isArchive(); } private: diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index cd092fd8e4..81cdd32a73 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -37,16 +37,25 @@ protected: Binary(unsigned int Type, MemoryBuffer *Source); enum { - isArchive, - + ID_Archive, // Object and children. - isObject, - isCOFF, - isELF, - isMachO, - lastObject + ID_StartObjects, + ID_COFF, + ID_ELF32L, // ELF 32-bit, little endian + ID_ELF32B, // ELF 32-bit, big endian + ID_ELF64L, // ELF 64-bit, little endian + ID_ELF64B, // ELF 64-bit, big endian + ID_MachO, + ID_EndObjects }; + static inline unsigned int getELFType(bool isLittleEndian, bool is64Bits) { + if (isLittleEndian) + return is64Bits ? ID_ELF64L : ID_ELF32L; + else + return is64Bits ? ID_ELF64B : ID_ELF32B; + } + public: virtual ~Binary(); @@ -56,6 +65,27 @@ public: // Cast methods. unsigned int getType() const { return TypeID; } static inline bool classof(const Binary *v) { return true; } + + // Convenience methods + bool isObject() const { + return TypeID > ID_StartObjects && TypeID < ID_EndObjects; + } + + bool isArchive() const { + return TypeID == ID_Archive; + } + + bool isELF() const { + return TypeID >= ID_ELF32L && TypeID <= ID_ELF64B; + } + + bool isMachO() const { + return TypeID == ID_MachO; + } + + bool isCOFF() const { + return TypeID == ID_COFF; + } }; error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result); diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 4f90187895..fc33ab1035 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -179,7 +179,7 @@ public: error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const; static inline bool classof(const Binary *v) { - return v->getType() == isCOFF; + return v->isCOFF(); } static inline bool classof(const COFFObjectFile *v) { return true; } }; diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index e746b0aaa5..e27a23edeb 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -484,7 +484,8 @@ public: // Methods for type inquiry through isa, cast, and dyn_cast bool isDyldType() const { return isDyldELFObject; } static inline bool classof(const Binary *v) { - return v->getType() == Binary::isELF; + return v->getType() == getELFType(target_endianness == support::little, + is64Bits); } static inline bool classof(const ELFObjectFile *v) { return true; } }; @@ -1257,7 +1258,8 @@ void ELFObjectFile<target_endianness, is64Bits> template<support::endianness target_endianness, bool is64Bits> ELFObjectFile<target_endianness, is64Bits>::ELFObjectFile(MemoryBuffer *Object , error_code &ec) - : ObjectFile(Binary::isELF, Object, ec) + : ObjectFile(getELFType(target_endianness == support::little, is64Bits), + Object, ec) , isDyldELFObject(false) , SectionHeaderTable(0) , dot_shstrtab_sec(0) diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 1aae85ab36..1e409b2856 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -47,7 +47,7 @@ public: MachOObject *getObject() { return MachOObj; } static inline bool classof(const Binary *v) { - return v->getType() == isMachO; + return v->isMachO(); } static inline bool classof(const MachOObjectFile *v) { return true; } diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 1e9d89549d..09eb7fc75e 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -372,8 +372,7 @@ public: static ObjectFile *createObjectFile(MemoryBuffer *Object); static inline bool classof(const Binary *v) { - return v->getType() >= isObject && - v->getType() < lastObject; + return v->isObject(); } static inline bool classof(const ObjectFile *v) { return true; } |