1e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/ 2e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 3e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* The LLVM Compiler Infrastructure */ 4e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 5e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* This file is distributed under the University of Illinois Open Source */ 6e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* License. See LICENSE.TXT for details. */ 7e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 8e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/*===----------------------------------------------------------------------===*/ 9e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 10e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* This header declares the C interface to libLLVMObject.a, which */ 11e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* implements object file reading and writing. */ 12e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 13e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* Many exotic languages can interoperate with C code but have a harder time */ 14e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* with C++ due to name mangling. So in addition to C, this interface enables */ 15e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* tools written in such languages. */ 16e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/* */ 17e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher/*===----------------------------------------------------------------------===*/ 18e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 19e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#ifndef LLVM_C_OBJECT_H 20e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#define LLVM_C_OBJECT_H 21e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 22e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#include "llvm-c/Core.h" 23e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#include "llvm/Config/llvm-config.h" 24e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 25e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#ifdef __cplusplus 26e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#include "llvm/Object/ObjectFile.h" 27e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 28e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherextern "C" { 29e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#endif 30e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 316244b518880842f2c15200ee041e06799e4cc779Gregory Szorc/** 326244b518880842f2c15200ee041e06799e4cc779Gregory Szorc * @defgroup LLVMCObject Object file reading and writing 336244b518880842f2c15200ee041e06799e4cc779Gregory Szorc * @ingroup LLVMC 346244b518880842f2c15200ee041e06799e4cc779Gregory Szorc * 356244b518880842f2c15200ee041e06799e4cc779Gregory Szorc * @{ 366244b518880842f2c15200ee041e06799e4cc779Gregory Szorc */ 376244b518880842f2c15200ee041e06799e4cc779Gregory Szorc 383cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// Opaque type wrappers 39e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophertypedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; 40e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophertypedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; 4165f73abf079d3e9a5ccce8091f2058f6eced4720Owen Andersontypedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; 42d8b0b915c5a94806596c381660c548aabef447b2Owen Andersontypedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; 43e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 443cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// ObjectFile creation 45e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); 46e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); 47e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 483cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// ObjectFile Section iterators 49e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); 50e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); 51e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, 52e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher LLVMSectionIteratorRef SI); 53e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMMoveToNextSection(LLVMSectionIteratorRef SI); 54e2fa64ef22321c5771667a8f00dca737ecb0799cOwen Andersonvoid LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, 55e2fa64ef22321c5771667a8f00dca737ecb0799cOwen Anderson LLVMSymbolIteratorRef Sym); 563cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson 573cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// ObjectFile Symbol iterators 583cb056797b17785cfd2429ce8232143d5aeb5e42Owen AndersonLLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); 593cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonvoid LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); 603cb056797b17785cfd2429ce8232143d5aeb5e42Owen AndersonLLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, 613cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson LLVMSymbolIteratorRef SI); 623cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonvoid LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); 633cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson 643cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// SectionRef accessors 65e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherconst char *LLVMGetSectionName(LLVMSectionIteratorRef SI); 66e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopheruint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); 67e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherconst char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); 683cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonuint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); 69ca7eb3e171f63de3cfc1020d86375ce11d356194Owen AndersonLLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, 703cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson LLVMSymbolIteratorRef Sym); 71e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 72d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson// Section Relocation iterators 73d8b0b915c5a94806596c381660c548aabef447b2Owen AndersonLLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section); 74d8b0b915c5a94806596c381660c548aabef447b2Owen Andersonvoid LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI); 75d8b0b915c5a94806596c381660c548aabef447b2Owen AndersonLLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, 76d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson LLVMRelocationIteratorRef RI); 77d8b0b915c5a94806596c381660c548aabef447b2Owen Andersonvoid LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI); 78d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson 79d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson 803cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson// SymbolRef accessors 813cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonconst char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); 823cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonuint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); 83b0436a73054fe676b216a0cf872d1fc433125c62Danil Malyshevuint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI); 843cb056797b17785cfd2429ce8232143d5aeb5e42Owen Andersonuint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); 85e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 863529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Anderson// RelocationRef accessors 873529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Andersonuint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI); 88b0436a73054fe676b216a0cf872d1fc433125c62Danil Malyshevuint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI); 893529c53d2f07bb283e990d1678962f1b5eba9ba4Owen AndersonLLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI); 903529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Andersonuint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI); 913529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Anderson// NOTE: Caller takes ownership of returned string of the two 923529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Anderson// following functions. 933529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Andersonconst char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI); 943529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Andersonconst char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI); 953529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Anderson 966244b518880842f2c15200ee041e06799e4cc779Gregory Szorc/** 976244b518880842f2c15200ee041e06799e4cc779Gregory Szorc * @} 986244b518880842f2c15200ee041e06799e4cc779Gregory Szorc */ 993529c53d2f07bb283e990d1678962f1b5eba9ba4Owen Anderson 100e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#ifdef __cplusplus 101e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 102e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 103e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophernamespace llvm { 104e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher namespace object { 105e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher inline ObjectFile *unwrap(LLVMObjectFileRef OF) { 106e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return reinterpret_cast<ObjectFile*>(OF); 107e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher } 108e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 109e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher inline LLVMObjectFileRef wrap(const ObjectFile *OF) { 110e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF)); 111e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher } 112e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 1134344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { 1144344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer return reinterpret_cast<section_iterator*>(SI); 115e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher } 116e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 117e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher inline LLVMSectionIteratorRef 1184344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer wrap(const section_iterator *SI) { 119e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return reinterpret_cast<LLVMSectionIteratorRef> 1204344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer (const_cast<section_iterator*>(SI)); 121e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher } 1223cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson 1233cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { 1243cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson return reinterpret_cast<symbol_iterator*>(SI); 1253cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson } 1263cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson 1273cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson inline LLVMSymbolIteratorRef 1283cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson wrap(const symbol_iterator *SI) { 1293cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson return reinterpret_cast<LLVMSymbolIteratorRef> 1303cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson (const_cast<symbol_iterator*>(SI)); 1313cb056797b17785cfd2429ce8232143d5aeb5e42Owen Anderson } 132d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson 133d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) { 134d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson return reinterpret_cast<relocation_iterator*>(SI); 135d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson } 136d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson 137d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson inline LLVMRelocationIteratorRef 138d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson wrap(const relocation_iterator *SI) { 139d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson return reinterpret_cast<LLVMRelocationIteratorRef> 140d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson (const_cast<relocation_iterator*>(SI)); 141d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson } 142d8b0b915c5a94806596c381660c548aabef447b2Owen Anderson 143e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher } 144e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 145e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 146e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#endif /* defined(__cplusplus) */ 147e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 148e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#endif 149e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 150