Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/ |
| 2 | /* */ |
| 3 | /* The LLVM Compiler Infrastructure */ |
| 4 | /* */ |
| 5 | /* This file is distributed under the University of Illinois Open Source */ |
| 6 | /* License. See LICENSE.TXT for details. */ |
| 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 | /*===----------------------------------------------------------------------===*/ |
| 18 | |
| 19 | #ifndef LLVM_C_OBJECT_H |
| 20 | #define LLVM_C_OBJECT_H |
| 21 | |
| 22 | #include "llvm-c/Core.h" |
| 23 | #include "llvm/Config/llvm-config.h" |
| 24 | |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 25 | #if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 26 | #include "llvm/Object/ObjectFile.h" |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 27 | #endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */ |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 28 | |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 29 | #ifdef __cplusplus |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 30 | extern "C" { |
| 31 | #endif |
| 32 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 33 | /** |
| 34 | * @defgroup LLVMCObject Object file reading and writing |
| 35 | * @ingroup LLVMC |
| 36 | * |
| 37 | * @{ |
| 38 | */ |
| 39 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 40 | // Opaque type wrappers |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 41 | typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 42 | typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; |
Owen Anderson | 65f73ab | 2011-10-21 20:28:19 +0000 | [diff] [blame] | 43 | typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 44 | typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 45 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 46 | // ObjectFile creation |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 47 | LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); |
| 48 | void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); |
| 49 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 50 | // ObjectFile Section iterators |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 51 | LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); |
| 52 | void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); |
| 53 | LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 54 | LLVMSectionIteratorRef SI); |
| 55 | void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); |
Owen Anderson | e2fa64e | 2011-10-21 18:21:22 +0000 | [diff] [blame] | 56 | void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, |
| 57 | LLVMSymbolIteratorRef Sym); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 58 | |
| 59 | // ObjectFile Symbol iterators |
| 60 | LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); |
| 61 | void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); |
| 62 | LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 63 | LLVMSymbolIteratorRef SI); |
| 64 | void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); |
| 65 | |
| 66 | // SectionRef accessors |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 67 | const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); |
| 68 | uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); |
| 69 | const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 70 | uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); |
Owen Anderson | ca7eb3e | 2011-10-21 20:35:58 +0000 | [diff] [blame] | 71 | LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 72 | LLVMSymbolIteratorRef Sym); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 73 | |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 74 | // Section Relocation iterators |
| 75 | LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section); |
| 76 | void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI); |
| 77 | LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, |
| 78 | LLVMRelocationIteratorRef RI); |
| 79 | void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI); |
| 80 | |
| 81 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 82 | // SymbolRef accessors |
| 83 | const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); |
| 84 | uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); |
Danil Malyshev | b0436a7 | 2011-11-29 17:40:10 +0000 | [diff] [blame] | 85 | uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 86 | uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 87 | |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 88 | // RelocationRef accessors |
| 89 | uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI); |
Danil Malyshev | b0436a7 | 2011-11-29 17:40:10 +0000 | [diff] [blame] | 90 | uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI); |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 91 | LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI); |
| 92 | uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI); |
| 93 | // NOTE: Caller takes ownership of returned string of the two |
| 94 | // following functions. |
| 95 | const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI); |
| 96 | const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI); |
| 97 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 98 | /** |
| 99 | * @} |
| 100 | */ |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 101 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 102 | #ifdef __cplusplus |
| 103 | } |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 104 | #endif |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 105 | |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 106 | #if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 107 | namespace llvm { |
| 108 | namespace object { |
| 109 | inline ObjectFile *unwrap(LLVMObjectFileRef OF) { |
| 110 | return reinterpret_cast<ObjectFile*>(OF); |
| 111 | } |
| 112 | |
| 113 | inline LLVMObjectFileRef wrap(const ObjectFile *OF) { |
| 114 | return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF)); |
| 115 | } |
| 116 | |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 117 | inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { |
| 118 | return reinterpret_cast<section_iterator*>(SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | inline LLVMSectionIteratorRef |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 122 | wrap(const section_iterator *SI) { |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 123 | return reinterpret_cast<LLVMSectionIteratorRef> |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 124 | (const_cast<section_iterator*>(SI)); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 125 | } |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 126 | |
| 127 | inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { |
| 128 | return reinterpret_cast<symbol_iterator*>(SI); |
| 129 | } |
| 130 | |
| 131 | inline LLVMSymbolIteratorRef |
| 132 | wrap(const symbol_iterator *SI) { |
| 133 | return reinterpret_cast<LLVMSymbolIteratorRef> |
| 134 | (const_cast<symbol_iterator*>(SI)); |
| 135 | } |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 136 | |
| 137 | inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) { |
| 138 | return reinterpret_cast<relocation_iterator*>(SI); |
| 139 | } |
| 140 | |
| 141 | inline LLVMRelocationIteratorRef |
| 142 | wrap(const relocation_iterator *SI) { |
| 143 | return reinterpret_cast<LLVMRelocationIteratorRef> |
| 144 | (const_cast<relocation_iterator*>(SI)); |
| 145 | } |
| 146 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
Evan Cheng | 7d2166a | 2013-04-03 23:12:39 +0000 | [diff] [blame] | 149 | #endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */ |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 150 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 151 | |
| 152 | #endif |
| 153 | |