blob: b6fe17a159f515410e73a07836f19fc0b9572e47 [file] [log] [blame]
Eric Christophere243fd92011-04-03 22:34:07 +00001/*===-- 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
Evan Cheng7d2166a2013-04-03 23:12:39 +000025#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
Eric Christophere243fd92011-04-03 22:34:07 +000026#include "llvm/Object/ObjectFile.h"
Evan Cheng7d2166a2013-04-03 23:12:39 +000027#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
Eric Christophere243fd92011-04-03 22:34:07 +000028
Evan Cheng7d2166a2013-04-03 23:12:39 +000029#ifdef __cplusplus
Eric Christophere243fd92011-04-03 22:34:07 +000030extern "C" {
31#endif
32
Gregory Szorc6244b512012-03-21 03:54:29 +000033/**
34 * @defgroup LLVMCObject Object file reading and writing
35 * @ingroup LLVMC
36 *
37 * @{
38 */
39
Owen Anderson3cb05672011-10-21 17:50:59 +000040// Opaque type wrappers
Eric Christophere243fd92011-04-03 22:34:07 +000041typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
Eric Christophere243fd92011-04-03 22:34:07 +000042typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
Owen Anderson65f73ab2011-10-21 20:28:19 +000043typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
Owen Andersond8b0b912011-10-27 17:15:47 +000044typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
Eric Christophere243fd92011-04-03 22:34:07 +000045
Owen Anderson3cb05672011-10-21 17:50:59 +000046// ObjectFile creation
Eric Christophere243fd92011-04-03 22:34:07 +000047LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
48void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
49
Owen Anderson3cb05672011-10-21 17:50:59 +000050// ObjectFile Section iterators
Eric Christophere243fd92011-04-03 22:34:07 +000051LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
52void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
53LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
54 LLVMSectionIteratorRef SI);
55void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
Owen Andersone2fa64e2011-10-21 18:21:22 +000056void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
57 LLVMSymbolIteratorRef Sym);
Owen Anderson3cb05672011-10-21 17:50:59 +000058
59// ObjectFile Symbol iterators
60LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
61void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
62LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
63 LLVMSymbolIteratorRef SI);
64void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
65
66// SectionRef accessors
Eric Christophere243fd92011-04-03 22:34:07 +000067const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
68uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
69const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000070uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
Owen Andersonca7eb3e2011-10-21 20:35:58 +000071LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
Owen Anderson3cb05672011-10-21 17:50:59 +000072 LLVMSymbolIteratorRef Sym);
Eric Christophere243fd92011-04-03 22:34:07 +000073
Owen Andersond8b0b912011-10-27 17:15:47 +000074// Section Relocation iterators
75LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
76void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
77LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
78 LLVMRelocationIteratorRef RI);
79void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
80
81
Owen Anderson3cb05672011-10-21 17:50:59 +000082// SymbolRef accessors
83const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
84uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
Danil Malyshevb0436a72011-11-29 17:40:10 +000085uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000086uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
Eric Christophere243fd92011-04-03 22:34:07 +000087
Owen Anderson3529c532011-10-27 17:32:36 +000088// RelocationRef accessors
89uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
Danil Malyshevb0436a72011-11-29 17:40:10 +000090uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
Owen Anderson3529c532011-10-27 17:32:36 +000091LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
92uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
93// NOTE: Caller takes ownership of returned string of the two
94// following functions.
95const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
96const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
97
Gregory Szorc6244b512012-03-21 03:54:29 +000098/**
99 * @}
100 */
Owen Anderson3529c532011-10-27 17:32:36 +0000101
Eric Christophere243fd92011-04-03 22:34:07 +0000102#ifdef __cplusplus
103}
Evan Cheng7d2166a2013-04-03 23:12:39 +0000104#endif
Eric Christophere243fd92011-04-03 22:34:07 +0000105
Evan Cheng7d2166a2013-04-03 23:12:39 +0000106#if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
Eric Christophere243fd92011-04-03 22:34:07 +0000107namespace llvm {
108 namespace object {
109 inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
110 return reinterpret_cast<ObjectFile*>(OF);
111 }
112
113 inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
114 return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
115 }
116
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000117 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
118 return reinterpret_cast<section_iterator*>(SI);
Eric Christophere243fd92011-04-03 22:34:07 +0000119 }
120
121 inline LLVMSectionIteratorRef
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000122 wrap(const section_iterator *SI) {
Eric Christophere243fd92011-04-03 22:34:07 +0000123 return reinterpret_cast<LLVMSectionIteratorRef>
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000124 (const_cast<section_iterator*>(SI));
Eric Christophere243fd92011-04-03 22:34:07 +0000125 }
Owen Anderson3cb05672011-10-21 17:50:59 +0000126
127 inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
128 return reinterpret_cast<symbol_iterator*>(SI);
129 }
130
131 inline LLVMSymbolIteratorRef
132 wrap(const symbol_iterator *SI) {
133 return reinterpret_cast<LLVMSymbolIteratorRef>
134 (const_cast<symbol_iterator*>(SI));
135 }
Owen Andersond8b0b912011-10-27 17:15:47 +0000136
137 inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
138 return reinterpret_cast<relocation_iterator*>(SI);
139 }
140
141 inline LLVMRelocationIteratorRef
142 wrap(const relocation_iterator *SI) {
143 return reinterpret_cast<LLVMRelocationIteratorRef>
144 (const_cast<relocation_iterator*>(SI));
145 }
146
Eric Christophere243fd92011-04-03 22:34:07 +0000147 }
148}
Evan Cheng7d2166a2013-04-03 23:12:39 +0000149#endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
Eric Christophere243fd92011-04-03 22:34:07 +0000150
Eric Christophere243fd92011-04-03 22:34:07 +0000151
152#endif
153