llvm.org GIT mirror llvm / f44199b
[LLVM-C] Allow Access to the Type of a Binary Summary: Add an accessor for the type of a binary file. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: hiraditya, aheejin, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60366 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357872 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 4 months ago
2 changed file(s) with 72 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3838 typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
3939 typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
4040
41 typedef enum {
42 LLVMBinaryTypeArchive, /**< Archive file. */
43 LLVMBinaryTypeMachOUniversalBinary, /**< Mach-O Universal Binary file. */
44 LLVMBinaryTypeCOFFImportFile, /**< COFF Import file. */
45 LLVMBinaryTypeIR, /**< LLVM IR. */
46 LLVMBinaryTypeWinRes, /**< Windows resource (.res) file. */
47 LLVMBinaryTypeCOFF, /**< COFF Object file. */
48 LLVMBinaryTypeELF32L, /**< ELF 32-bit, little endian. */
49 LLVMBinaryTypeELF32B, /**< ELF 32-bit, big endian. */
50 LLVMBinaryTypeELF64L, /**< ELF 64-bit, little endian. */
51 LLVMBinaryTypeELF64B, /**< ELF 64-bit, big endian. */
52 LLVMBinaryTypeMachO32L, /**< MachO 32-bit, little endian. */
53 LLVMBinaryTypeMachO32B, /**< MachO 32-bit, big endian. */
54 LLVMBinaryTypeMachO64L, /**< MachO 64-bit, little endian. */
55 LLVMBinaryTypeMachO64B, /**< MachO 64-bit, big endian. */
56 LLVMBinaryTypeWasm, /**< Web Assembly. */
57 } LLVMBinaryType;
58
4159 /**
4260 * Create a binary file from the given memory buffer.
4361 *
7694 * @see llvm::object::getMemoryBufferRef
7795 */
7896 LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR);
97
98 /**
99 * Retrieve the specific type of a binary.
100 *
101 * @see llvm::object::Binary::getType
102 */
103 LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR);
104
79105
80106 // ObjectFile creation
81107 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
8484 delete unwrap(BR);
8585 }
8686
87 LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR) {
88 class BinaryTypeMapper final : public Binary {
89 public:
90 static LLVMBinaryType mapBinaryTypeToLLVMBinaryType(unsigned Kind) {
91 switch (Kind) {
92 case ID_Archive:
93 return LLVMBinaryTypeArchive;
94 case ID_MachOUniversalBinary:
95 return LLVMBinaryTypeMachOUniversalBinary;
96 case ID_COFFImportFile:
97 return LLVMBinaryTypeCOFFImportFile;
98 case ID_IR:
99 return LLVMBinaryTypeIR;
100 case ID_WinRes:
101 return LLVMBinaryTypeWinRes;
102 case ID_COFF:
103 return LLVMBinaryTypeCOFF;
104 case ID_ELF32L:
105 return LLVMBinaryTypeELF32L;
106 case ID_ELF32B:
107 return LLVMBinaryTypeELF32B;
108 case ID_ELF64L:
109 return LLVMBinaryTypeELF64L;
110 case ID_ELF64B:
111 return LLVMBinaryTypeELF64B;
112 case ID_MachO32L:
113 return LLVMBinaryTypeMachO32L;
114 case ID_MachO32B:
115 return LLVMBinaryTypeMachO32B;
116 case ID_MachO64L:
117 return LLVMBinaryTypeMachO64L;
118 case ID_MachO64B:
119 return LLVMBinaryTypeMachO64B;
120 case ID_Wasm:
121 return LLVMBinaryTypeWasm;
122 case ID_StartObjects:
123 case ID_EndObjects:
124 llvm_unreachable("Marker types are not valid binary kinds!");
125 default:
126 llvm_unreachable("Unknown binary kind!");
127 }
128 }
129 };
130 return BinaryTypeMapper::mapBinaryTypeToLLVMBinaryType(unwrap(BR)->getType());
131 }
132
87133 // ObjectFile creation
88134 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
89135 std::unique_ptr Buf(unwrap(MemBuf));