Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: include/llvm/Object/Binary.h

Issue 9617030: Distinguish between ELF 32/64, little/big endian, in the type system of Binary.h (Closed) Base URL: https://llvm.org/svn/llvm-project/llvm/trunk/
Patch Set: x Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/llvm/Object/Archive.h ('k') | include/llvm/Object/COFF.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « include/llvm/Object/Archive.h ('k') | include/llvm/Object/COFF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698