1 /*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- 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 header declares the C interface to libLLVMObject.a, which */
11 /* implements object file reading and writing. */
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. */
17 /*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_OBJECT_H
20 #define LLVM_C_OBJECT_H
22 #include "llvm-c/Core.h"
23 #include "llvm/Config/llvm-config.h"
26 #include "llvm/Object/ObjectFile.h"
32 * @defgroup LLVMCObject Object file reading and writing
38 // Opaque type wrappers
39 typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
40 typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
41 typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
42 typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
44 // ObjectFile creation
45 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
46 void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
48 // ObjectFile Section iterators
49 LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
50 void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
51 LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
52 LLVMSectionIteratorRef SI);
53 void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
54 void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
55 LLVMSymbolIteratorRef Sym);
57 // ObjectFile Symbol iterators
58 LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
59 void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
60 LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
61 LLVMSymbolIteratorRef SI);
62 void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
64 // SectionRef accessors
65 const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
66 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
67 const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
68 uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
69 LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
70 LLVMSymbolIteratorRef Sym);
72 // Section Relocation iterators
73 LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
74 void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
75 LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
76 LLVMRelocationIteratorRef RI);
77 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
80 // SymbolRef accessors
81 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
82 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
83 uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
84 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
86 // RelocationRef accessors
87 uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
88 uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
89 LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
90 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
91 // NOTE: Caller takes ownership of returned string of the two
92 // following functions.
93 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
94 const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
105 inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
106 return reinterpret_cast<ObjectFile*>(OF);
109 inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
110 return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
113 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
114 return reinterpret_cast<section_iterator*>(SI);
117 inline LLVMSectionIteratorRef
118 wrap(const section_iterator *SI) {
119 return reinterpret_cast<LLVMSectionIteratorRef>
120 (const_cast<section_iterator*>(SI));
123 inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
124 return reinterpret_cast<symbol_iterator*>(SI);
127 inline LLVMSymbolIteratorRef
128 wrap(const symbol_iterator *SI) {
129 return reinterpret_cast<LLVMSymbolIteratorRef>
130 (const_cast<symbol_iterator*>(SI));
133 inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
134 return reinterpret_cast<relocation_iterator*>(SI);
137 inline LLVMRelocationIteratorRef
138 wrap(const relocation_iterator *SI) {
139 return reinterpret_cast<LLVMRelocationIteratorRef>
140 (const_cast<relocation_iterator*>(SI));
146 #endif /* defined(__cplusplus) */