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 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 31 | // Opaque type wrappers |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 32 | typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 33 | typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; |
Owen Anderson | 65f73ab | 2011-10-21 20:28:19 +0000 | [diff] [blame] | 34 | typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame^] | 35 | typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 36 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 37 | // ObjectFile creation |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 38 | LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); |
| 39 | void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); |
| 40 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 41 | // ObjectFile Section iterators |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 42 | LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); |
| 43 | void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); |
| 44 | LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 45 | LLVMSectionIteratorRef SI); |
| 46 | void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); |
Owen Anderson | e2fa64e | 2011-10-21 18:21:22 +0000 | [diff] [blame] | 47 | void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, |
| 48 | LLVMSymbolIteratorRef Sym); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 49 | |
| 50 | // ObjectFile Symbol iterators |
| 51 | LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); |
| 52 | void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); |
| 53 | LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 54 | LLVMSymbolIteratorRef SI); |
| 55 | void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); |
| 56 | |
| 57 | // SectionRef accessors |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 58 | const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); |
| 59 | uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); |
| 60 | const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 61 | uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); |
Owen Anderson | ca7eb3e | 2011-10-21 20:35:58 +0000 | [diff] [blame] | 62 | LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 63 | LLVMSymbolIteratorRef Sym); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 64 | |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame^] | 65 | // Section Relocation iterators |
| 66 | LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section); |
| 67 | void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI); |
| 68 | LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, |
| 69 | LLVMRelocationIteratorRef RI); |
| 70 | void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI); |
| 71 | |
| 72 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 73 | // SymbolRef accessors |
| 74 | const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); |
| 75 | uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); |
| 76 | uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI); |
| 77 | uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 78 | |
| 79 | #ifdef __cplusplus |
| 80 | } |
| 81 | |
| 82 | namespace llvm { |
| 83 | namespace object { |
| 84 | inline ObjectFile *unwrap(LLVMObjectFileRef OF) { |
| 85 | return reinterpret_cast<ObjectFile*>(OF); |
| 86 | } |
| 87 | |
| 88 | inline LLVMObjectFileRef wrap(const ObjectFile *OF) { |
| 89 | return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF)); |
| 90 | } |
| 91 | |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 92 | inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { |
| 93 | return reinterpret_cast<section_iterator*>(SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | inline LLVMSectionIteratorRef |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 97 | wrap(const section_iterator *SI) { |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 98 | return reinterpret_cast<LLVMSectionIteratorRef> |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 99 | (const_cast<section_iterator*>(SI)); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 100 | } |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 101 | |
| 102 | inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { |
| 103 | return reinterpret_cast<symbol_iterator*>(SI); |
| 104 | } |
| 105 | |
| 106 | inline LLVMSymbolIteratorRef |
| 107 | wrap(const symbol_iterator *SI) { |
| 108 | return reinterpret_cast<LLVMSymbolIteratorRef> |
| 109 | (const_cast<symbol_iterator*>(SI)); |
| 110 | } |
Owen Anderson | d8b0b91 | 2011-10-27 17:15:47 +0000 | [diff] [blame^] | 111 | |
| 112 | inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) { |
| 113 | return reinterpret_cast<relocation_iterator*>(SI); |
| 114 | } |
| 115 | |
| 116 | inline LLVMRelocationIteratorRef |
| 117 | wrap(const relocation_iterator *SI) { |
| 118 | return reinterpret_cast<LLVMRelocationIteratorRef> |
| 119 | (const_cast<relocation_iterator*>(SI)); |
| 120 | } |
| 121 | |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | #endif /* defined(__cplusplus) */ |
| 126 | |
| 127 | #endif |
| 128 | |