1 //===- Binary.h - A generic binary file -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the Binary class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_BINARY_H
15 #define LLVM_OBJECT_BINARY_H
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/Object/Error.h"
30 Binary(const Binary &other); // = delete
37 Binary(unsigned int Type, MemoryBuffer *Source);
41 // Object and children.
44 ID_ELF32L, // ELF 32-bit, little endian
45 ID_ELF32B, // ELF 32-bit, big endian
46 ID_ELF64L, // ELF 64-bit, little endian
47 ID_ELF64B, // ELF 64-bit, big endian
52 static inline unsigned int getELFType(bool isLittleEndian, bool is64Bits) {
54 return is64Bits ? ID_ELF64L : ID_ELF32L;
56 return is64Bits ? ID_ELF64B : ID_ELF32B;
62 StringRef getData() const;
63 StringRef getFileName() const;
66 unsigned int getType() const { return TypeID; }
67 static inline bool classof(const Binary *v) { return true; }
69 // Convenience methods
70 bool isObject() const {
71 return TypeID > ID_StartObjects && TypeID < ID_EndObjects;
74 bool isArchive() const {
75 return TypeID == ID_Archive;
79 return TypeID >= ID_ELF32L && TypeID <= ID_ELF64B;
82 bool isMachO() const {
83 return TypeID == ID_MachO;
87 return TypeID == ID_COFF;
91 /// @brief Create a Binary from Source, autodetecting the file type.
93 /// @param Source The data to create the Binary from. Ownership is transferred
94 /// to Result if successful. If an error is returned, Source is destroyed
95 /// by createBinary before returning.
96 /// @param Result A pointer to the resulting Binary if no error occured.
97 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
99 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);