| OLD | NEW |
| 1 //===- Binary.h - A generic binary file -------------------------*- C++ -*-===// | 1 //===- Binary.h - A generic binary file -------------------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file declares the Binary class. | 10 // This file declares the Binary class. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 Binary(const Binary &other); // = delete | 30 Binary(const Binary &other); // = delete |
| 31 | 31 |
| 32 unsigned int TypeID; | 32 unsigned int TypeID; |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 MemoryBuffer *Data; | 35 MemoryBuffer *Data; |
| 36 | 36 |
| 37 Binary(unsigned int Type, MemoryBuffer *Source); | 37 Binary(unsigned int Type, MemoryBuffer *Source); |
| 38 | 38 |
| 39 enum { | 39 enum { |
| 40 isArchive, | 40 ID_Archive, |
| 41 // Object and children. |
| 42 ID_StartObjects, |
| 43 ID_COFF, |
| 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 |
| 48 ID_MachO, |
| 49 ID_EndObjects |
| 50 }; |
| 41 | 51 |
| 42 // Object and children. | 52 static inline unsigned int getELFType(bool isLittleEndian, bool is64Bits) { |
| 43 isObject, | 53 if (isLittleEndian) |
| 44 isCOFF, | 54 return is64Bits ? ID_ELF64L : ID_ELF32L; |
| 45 isELF, | 55 else |
| 46 isMachO, | 56 return is64Bits ? ID_ELF64B : ID_ELF32B; |
| 47 lastObject | 57 } |
| 48 }; | |
| 49 | 58 |
| 50 public: | 59 public: |
| 51 virtual ~Binary(); | 60 virtual ~Binary(); |
| 52 | 61 |
| 53 StringRef getData() const; | 62 StringRef getData() const; |
| 54 StringRef getFileName() const; | 63 StringRef getFileName() const; |
| 55 | 64 |
| 56 // Cast methods. | 65 // Cast methods. |
| 57 unsigned int getType() const { return TypeID; } | 66 unsigned int getType() const { return TypeID; } |
| 58 static inline bool classof(const Binary *v) { return true; } | 67 static inline bool classof(const Binary *v) { return true; } |
| 68 |
| 69 // Convenience methods |
| 70 bool isObject() const { |
| 71 return TypeID > ID_StartObjects && TypeID < ID_EndObjects; |
| 72 } |
| 73 |
| 74 bool isArchive() const { |
| 75 return TypeID == ID_Archive; |
| 76 } |
| 77 |
| 78 bool isELF() const { |
| 79 return TypeID >= ID_ELF32L && TypeID <= ID_ELF64B; |
| 80 } |
| 81 |
| 82 bool isMachO() const { |
| 83 return TypeID == ID_MachO; |
| 84 } |
| 85 |
| 86 bool isCOFF() const { |
| 87 return TypeID == ID_COFF; |
| 88 } |
| 59 }; | 89 }; |
| 60 | 90 |
| 61 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result); | 91 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result); |
| 62 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result); | 92 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result); |
| 63 | 93 |
| 64 } | 94 } |
| 65 } | 95 } |
| 66 | 96 |
| 67 #endif | 97 #endif |
| OLD | NEW |