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"
29 Binary() LLVM_DELETED_FUNCTION;
30 Binary(const Binary &other) LLVM_DELETED_FUNCTION;
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; }
68 // Convenience methods
69 bool isObject() const {
70 return TypeID > ID_StartObjects && TypeID < ID_EndObjects;
73 bool isArchive() const {
74 return TypeID == ID_Archive;
78 return TypeID >= ID_ELF32L && TypeID <= ID_ELF64B;
81 bool isMachO() const {
82 return TypeID == ID_MachO;
86 return TypeID == ID_COFF;
90 /// @brief Create a Binary from Source, autodetecting the file type.
92 /// @param Source The data to create the Binary from. Ownership is transferred
93 /// to Result if successful. If an error is returned, Source is destroyed
94 /// by createBinary before returning.
95 /// @param Result A pointer to the resulting Binary if no error occured.
96 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
98 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);