// 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:
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();
// 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);
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; }
};
// 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; }
};
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)
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; }
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; }
}
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.
}
COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
- : ObjectFile(Binary::isCOFF, Object, ec)
+ : ObjectFile(Binary::ID_COFF, Object, ec)
, Header(0)
, SectionTable(0)
, SymbolTable(0)
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;