[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / include / llvm-c / Object.h
blob1e9b703a68ff171206bc3ec118381c5ca2471696
1 /*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/
2 /* */
3 /* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
4 /* Exceptions. */
5 /* See https://llvm.org/LICENSE.txt for license information. */
6 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
7 /* */
8 /*===----------------------------------------------------------------------===*/
9 /* */
10 /* This header declares the C interface to libLLVMObject.a, which */
11 /* implements object file reading and writing. */
12 /* */
13 /* Many exotic languages can interoperate with C code but have a harder time */
14 /* with C++ due to name mangling. So in addition to C, this interface enables */
15 /* tools written in such languages. */
16 /* */
17 /*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_OBJECT_H
20 #define LLVM_C_OBJECT_H
22 #include "llvm-c/Types.h"
23 #include "llvm/Config/llvm-config.h"
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
29 /**
30 * @defgroup LLVMCObject Object file reading and writing
31 * @ingroup LLVMC
33 * @{
36 // Opaque type wrappers
37 typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
38 typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
39 typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
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;
59 /**
60 * Create a binary file from the given memory buffer.
62 * The exact type of the binary file will be inferred automatically, and the
63 * appropriate implementation selected. The context may be NULL except if
64 * the resulting file is an LLVM IR file.
66 * The memory buffer is not consumed by this function. It is the responsibilty
67 * of the caller to free it with \c LLVMDisposeMemoryBuffer.
69 * If NULL is returned, the \p ErrorMessage parameter is populated with the
70 * error's description. It is then the caller's responsibility to free this
71 * message by calling \c LLVMDisposeMessage.
73 * @see llvm::object::createBinary
75 LLVMBinaryRef LLVMCreateBinary(LLVMMemoryBufferRef MemBuf,
76 LLVMContextRef Context,
77 char **ErrorMessage);
79 /**
80 * Dispose of a binary file.
82 * The binary file does not own its backing buffer. It is the responsibilty
83 * of the caller to free it with \c LLVMDisposeMemoryBuffer.
85 void LLVMDisposeBinary(LLVMBinaryRef BR);
87 /**
88 * Retrieves a copy of the memory buffer associated with this object file.
90 * The returned buffer is merely a shallow copy and does not own the actual
91 * backing buffer of the binary. Nevertheless, it is the responsibility of the
92 * caller to free it with \c LLVMDisposeMemoryBuffer.
94 * @see llvm::object::getMemoryBufferRef
96 LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR);
98 /**
99 * Retrieve the specific type of a binary.
101 * @see llvm::object::Binary::getType
103 LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR);
106 * For a Mach-O universal binary file, retrieves the object file corresponding
107 * to the given architecture if it is present as a slice.
109 * If NULL is returned, the \p ErrorMessage parameter is populated with the
110 * error's description. It is then the caller's responsibility to free this
111 * message by calling \c LLVMDisposeMessage.
113 * It is the responsiblity of the caller to free the returned object file by
114 * calling \c LLVMDisposeBinary.
116 LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,
117 const char *Arch,
118 size_t ArchLen,
119 char **ErrorMessage);
122 * Retrieve a copy of the section iterator for this object file.
124 * If there are no sections, the result is NULL.
126 * The returned iterator is merely a shallow copy. Nevertheless, it is
127 * the responsibility of the caller to free it with
128 * \c LLVMDisposeSectionIterator.
130 * @see llvm::object::sections()
132 LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR);
135 * Returns whether the given section iterator is at the end.
137 * @see llvm::object::section_end
139 LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR,
140 LLVMSectionIteratorRef SI);
143 * Retrieve a copy of the symbol iterator for this object file.
145 * If there are no symbols, the result is NULL.
147 * The returned iterator is merely a shallow copy. Nevertheless, it is
148 * the responsibility of the caller to free it with
149 * \c LLVMDisposeSymbolIterator.
151 * @see llvm::object::symbols()
153 LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR);
156 * Returns whether the given symbol iterator is at the end.
158 * @see llvm::object::symbol_end
160 LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR,
161 LLVMSymbolIteratorRef SI);
163 void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
165 void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
166 void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
167 LLVMSymbolIteratorRef Sym);
169 // ObjectFile Symbol iterators
170 void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
171 void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
173 // SectionRef accessors
174 const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
175 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
176 const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
177 uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
178 LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
179 LLVMSymbolIteratorRef Sym);
181 // Section Relocation iterators
182 LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
183 void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
184 LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
185 LLVMRelocationIteratorRef RI);
186 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
189 // SymbolRef accessors
190 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
191 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
192 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
194 // RelocationRef accessors
195 uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
196 LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
197 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
198 // NOTE: Caller takes ownership of returned string of the two
199 // following functions.
200 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
201 const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
203 /** Deprecated: Use LLVMBinaryRef instead. */
204 typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
206 /** Deprecated: Use LLVMCreateBinary instead. */
207 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
209 /** Deprecated: Use LLVMDisposeBinary instead. */
210 void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
212 /** Deprecated: Use LLVMObjectFileCopySectionIterator instead. */
213 LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
215 /** Deprecated: Use LLVMObjectFileIsSectionIteratorAtEnd instead. */
216 LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
217 LLVMSectionIteratorRef SI);
219 /** Deprecated: Use LLVMObjectFileCopySymbolIterator instead. */
220 LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
222 /** Deprecated: Use LLVMObjectFileIsSymbolIteratorAtEnd instead. */
223 LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
224 LLVMSymbolIteratorRef SI);
226 * @}
229 #ifdef __cplusplus
231 #endif /* defined(__cplusplus) */
233 #endif