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 | |
| 25 | #ifdef __cplusplus |
| 26 | #include "llvm/Object/ObjectFile.h" |
| 27 | |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 31 | /** |
| 32 | * @defgroup LLVMCObject Object file reading and writing |
| 33 | * @ingroup LLVMC |
| 34 | * |
| 35 | * @{ |
| 36 | */ |
| 37 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 38 | // Opaque type wrappers |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 39 | typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 40 | typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; |
Owen Anderson | 65f73ab | 2011-10-21 20:28:19 +0000 | [diff] [blame] | 41 | typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 42 | typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 43 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 44 | // ObjectFile creation |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 45 | LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); |
| 46 | void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); |
| 47 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 48 | // ObjectFile Section iterators |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 49 | LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); |
| 50 | void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); |
| 51 | LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 52 | LLVMSectionIteratorRef SI); |
| 53 | void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); |
Owen Anderson | e2fa64e | 2011-10-21 18:21:22 +0000 | [diff] [blame] | 54 | void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, |
| 55 | LLVMSymbolIteratorRef Sym); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 56 | |
| 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); |
| 63 | |
| 64 | // SectionRef accessors |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 65 | const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); |
| 66 | uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); |
| 67 | const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 68 | uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); |
Owen Anderson | ca7eb3e | 2011-10-21 20:35:58 +0000 | [diff] [blame] | 69 | LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 70 | LLVMSymbolIteratorRef Sym); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 71 | |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 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); |
| 78 | |
| 79 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 80 | // SymbolRef accessors |
| 81 | const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); |
| 82 | uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); |
Danil Malyshev | b0436a7 | 2011-11-29 17:40:10 +0000 | [diff] [blame] | 83 | uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 84 | uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 85 | |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 86 | // RelocationRef accessors |
| 87 | uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI); |
Danil Malyshev | b0436a7 | 2011-11-29 17:40:10 +0000 | [diff] [blame] | 88 | uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI); |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 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); |
| 95 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 96 | /** |
| 97 | * @} |
| 98 | */ |
Owen Anderson | 3529c53 | 2011-10-27 17:32:36 +0000 | [diff] [blame] | 99 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | |
| 103 | namespace llvm { |
| 104 | namespace object { |
| 105 | inline ObjectFile *unwrap(LLVMObjectFileRef OF) { |
| 106 | return reinterpret_cast<ObjectFile*>(OF); |
| 107 | } |
| 108 | |
| 109 | inline LLVMObjectFileRef wrap(const ObjectFile *OF) { |
| 110 | return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF)); |
| 111 | } |
| 112 | |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 113 | inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { |
| 114 | return reinterpret_cast<section_iterator*>(SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | inline LLVMSectionIteratorRef |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 118 | wrap(const section_iterator *SI) { |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 119 | return reinterpret_cast<LLVMSectionIteratorRef> |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 120 | (const_cast<section_iterator*>(SI)); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 121 | } |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 122 | |
| 123 | inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { |
| 124 | return reinterpret_cast<symbol_iterator*>(SI); |
| 125 | } |
| 126 | |
| 127 | inline LLVMSymbolIteratorRef |
| 128 | wrap(const symbol_iterator *SI) { |
| 129 | return reinterpret_cast<LLVMSymbolIteratorRef> |
| 130 | (const_cast<symbol_iterator*>(SI)); |
| 131 | } |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame] | 132 | |
| 133 | inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) { |
| 134 | return reinterpret_cast<relocation_iterator*>(SI); |
| 135 | } |
| 136 | |
| 137 | inline LLVMRelocationIteratorRef |
| 138 | wrap(const relocation_iterator *SI) { |
| 139 | return reinterpret_cast<LLVMRelocationIteratorRef> |
| 140 | (const_cast<relocation_iterator*>(SI)); |
| 141 | } |
| 142 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | #endif /* defined(__cplusplus) */ |
| 147 | |
| 148 | #endif |
| 149 | |