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 28extern "C" { 29#endif 30 31/** 32 * @defgroup LLVMCObject Object file reading and writing 33 * @ingroup LLVMC 34 * 35 * @{ 36 */ 37 38// Opaque type wrappers 39typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; 40typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; 41typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; 42typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; 43 44// ObjectFile creation 45LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); 46void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); 47 48// ObjectFile Section iterators 49LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); 50void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); 51LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, 52 LLVMSectionIteratorRef SI); 53void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); 54void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, 55 LLVMSymbolIteratorRef Sym); 56 57// ObjectFile Symbol iterators 58LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); 59void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); 60LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, 61 LLVMSymbolIteratorRef SI); 62void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); 63 64// SectionRef accessors 65const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); 66uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); 67const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); 68uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); 69LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, 70 LLVMSymbolIteratorRef Sym); 71 72// Section Relocation iterators 73LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section); 74void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI); 75LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, 76 LLVMRelocationIteratorRef RI); 77void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI); 78 79 80// SymbolRef accessors 81const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); 82uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); 83uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI); 84uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); 85 86// RelocationRef accessors 87uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI); 88uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI); 89LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI); 90uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI); 91// NOTE: Caller takes ownership of returned string of the two 92// following functions. 93const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI); 94const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI); 95 96/** 97 * @} 98 */ 99 100#ifdef __cplusplus 101} 102 103namespace 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 113 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { 114 return reinterpret_cast<section_iterator*>(SI); 115 } 116 117 inline LLVMSectionIteratorRef 118 wrap(const section_iterator *SI) { 119 return reinterpret_cast<LLVMSectionIteratorRef> 120 (const_cast<section_iterator*>(SI)); 121 } 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 } 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 143 } 144} 145 146#endif /* defined(__cplusplus) */ 147 148#endif 149 150