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; |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 35 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 36 | // ObjectFile creation |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 37 | LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); |
| 38 | void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); |
| 39 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 40 | // ObjectFile Section iterators |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 41 | LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); |
| 42 | void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); |
| 43 | LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 44 | LLVMSectionIteratorRef SI); |
| 45 | void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); |
Owen Anderson | e2fa64e | 2011-10-21 18:21:22 +0000 | [diff] [blame] | 46 | void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, |
| 47 | LLVMSymbolIteratorRef Sym); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 48 | |
| 49 | // ObjectFile Symbol iterators |
| 50 | LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); |
| 51 | void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); |
| 52 | LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, |
| 53 | LLVMSymbolIteratorRef SI); |
| 54 | void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); |
| 55 | |
| 56 | // SectionRef accessors |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 57 | const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); |
| 58 | uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); |
| 59 | const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 60 | uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); |
| 61 | int LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, |
| 62 | LLVMSymbolIteratorRef Sym); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 63 | |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 64 | // SymbolRef accessors |
| 65 | const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); |
| 66 | uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); |
| 67 | uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI); |
| 68 | uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 69 | |
| 70 | #ifdef __cplusplus |
| 71 | } |
| 72 | |
| 73 | namespace llvm { |
| 74 | namespace object { |
| 75 | inline ObjectFile *unwrap(LLVMObjectFileRef OF) { |
| 76 | return reinterpret_cast<ObjectFile*>(OF); |
| 77 | } |
| 78 | |
| 79 | inline LLVMObjectFileRef wrap(const ObjectFile *OF) { |
| 80 | return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF)); |
| 81 | } |
| 82 | |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 83 | inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { |
| 84 | return reinterpret_cast<section_iterator*>(SI); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | inline LLVMSectionIteratorRef |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 88 | wrap(const section_iterator *SI) { |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 89 | return reinterpret_cast<LLVMSectionIteratorRef> |
Michael J. Spencer | 4344b1e | 2011-10-07 19:25:32 +0000 | [diff] [blame] | 90 | (const_cast<section_iterator*>(SI)); |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 91 | } |
Owen Anderson | 3cb0567 | 2011-10-21 17:50:59 +0000 | [diff] [blame] | 92 | |
| 93 | inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { |
| 94 | return reinterpret_cast<symbol_iterator*>(SI); |
| 95 | } |
| 96 | |
| 97 | inline LLVMSymbolIteratorRef |
| 98 | wrap(const symbol_iterator *SI) { |
| 99 | return reinterpret_cast<LLVMSymbolIteratorRef> |
| 100 | (const_cast<symbol_iterator*>(SI)); |
| 101 | } |
Eric Christopher | e243fd9 | 2011-04-03 22:34:07 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | #endif /* defined(__cplusplus) */ |
| 106 | |
| 107 | #endif |
| 108 | |