[llvm-commits] [llvm] r152435 - in /llvm/trunk: include/llvm/Object/Archive.h include/llvm/Object/Binary.h include/llvm/Object/COFF.h include/llvm/Object/ELF.h include/llvm/Object/MachO.h include/llvm/Object/ObjectFile.h lib/Object/Archive.cpp lib/Object/COFFObjectFile.cpp lib/Object/MachOObjectFile.cpp
David Meyer
pdox at google.com
Fri Mar 9 12:41:57 PST 2012
Author: pdox
Date: Fri Mar 9 14:41:57 2012
New Revision: 152435
URL: http://llvm.org/viewvc/llvm-project?rev=152435&view=rev
Log:
[Object]
Make Binary::TypeID more granular, to distinguish between ELF 32/64 little/big
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/include/llvm/Object/Binary.h
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Fri Mar 9 14:41:57 2012
@@ -131,7 +131,7 @@
// 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:
Modified: llvm/trunk/include/llvm/Object/Binary.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Binary.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Binary.h (original)
+++ llvm/trunk/include/llvm/Object/Binary.h Fri Mar 9 14:41:57 2012
@@ -37,16 +37,25 @@
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 @@
// 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);
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Fri Mar 9 14:41:57 2012
@@ -179,7 +179,7 @@
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; }
};
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Fri Mar 9 14:41:57 2012
@@ -484,7 +484,8 @@
// 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 @@
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)
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Fri Mar 9 14:41:57 2012
@@ -47,7 +47,7 @@
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; }
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Fri Mar 9 14:41:57 2012
@@ -372,8 +372,7 @@
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; }
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Fri Mar 9 14:41:57 2012
@@ -174,7 +174,7 @@
}
Archive::Archive(MemoryBuffer *source, error_code &ec)
- : Binary(Binary::isArchive, source) {
+ : Binary(Binary::ID_Archive, source) {
// Check for sufficient magic.
if (!source || source->getBufferSize()
< (8 + sizeof(ArchiveMemberHeader) + 2) // Smallest archive.
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Fri Mar 9 14:41:57 2012
@@ -421,7 +421,7 @@
}
COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
- : ObjectFile(Binary::isCOFF, Object, ec)
+ : ObjectFile(Binary::ID_COFF, Object, ec)
, Header(0)
, SectionTable(0)
, SymbolTable(0)
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=152435&r1=152434&r2=152435&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Mar 9 14:41:57 2012
@@ -30,7 +30,7 @@
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO,
error_code &ec)
- : ObjectFile(Binary::isMachO, Object, ec),
+ : ObjectFile(Binary::ID_MachO, Object, ec),
MachOObj(MOO),
RegisteredStringTable(std::numeric_limits<uint32_t>::max()) {
DataRefImpl DRI;
More information about the llvm-commits
mailing list