blob: e2dad62b4e07b8f946cdc42545373d472c995f99 [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
25#ifdef __cplusplus
26#include "llvm/Object/ObjectFile.h"
27
28extern "C" {
29#endif
30
Gregory Szorc6244b512012-03-21 03:54:29 +000031/**
32 * @defgroup LLVMCObject Object file reading and writing
33 * @ingroup LLVMC
34 *
35 * @{
36 */
37
Owen Anderson3cb05672011-10-21 17:50:59 +000038// Opaque type wrappers
Eric Christophere243fd92011-04-03 22:34:07 +000039typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
Eric Christophere243fd92011-04-03 22:34:07 +000040typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
Owen Anderson65f73ab2011-10-21 20:28:19 +000041typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
Owen Andersond8b0b912011-10-27 17:15:47 +000042typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
Eric Christophere243fd92011-04-03 22:34:07 +000043
Owen Anderson3cb05672011-10-21 17:50:59 +000044// ObjectFile creation
Eric Christophere243fd92011-04-03 22:34:07 +000045LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
46void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
47
Owen Anderson3cb05672011-10-21 17:50:59 +000048// ObjectFile Section iterators
Eric Christophere243fd92011-04-03 22:34:07 +000049LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
50void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
51LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
52 LLVMSectionIteratorRef SI);
53void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
Owen Andersone2fa64e2011-10-21 18:21:22 +000054void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
55 LLVMSymbolIteratorRef Sym);
Owen Anderson3cb05672011-10-21 17:50:59 +000056
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
Eric Christophere243fd92011-04-03 22:34:07 +000065const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
66uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
67const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000068uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
Owen Andersonca7eb3e2011-10-21 20:35:58 +000069LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
Owen Anderson3cb05672011-10-21 17:50:59 +000070 LLVMSymbolIteratorRef Sym);
Eric Christophere243fd92011-04-03 22:34:07 +000071
Owen Andersond8b0b912011-10-27 17:15:47 +000072// Section Relocation iterators
73LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
74void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
75LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
76 LLVMRelocationIteratorRef RI);
77void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
78
79
Owen Anderson3cb05672011-10-21 17:50:59 +000080// SymbolRef accessors
81const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
82uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
Danil Malyshevb0436a72011-11-29 17:40:10 +000083uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000084uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
Eric Christophere243fd92011-04-03 22:34:07 +000085
Owen Anderson3529c532011-10-27 17:32:36 +000086// RelocationRef accessors
87uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
Danil Malyshevb0436a72011-11-29 17:40:10 +000088uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
Owen Anderson3529c532011-10-27 17:32:36 +000089LLVMSymbolIteratorRef 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
Gregory Szorc6244b512012-03-21 03:54:29 +000096/**
97 * @}
98 */
Owen Anderson3529c532011-10-27 17:32:36 +000099
Eric Christophere243fd92011-04-03 22:34:07 +0000100#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
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000113 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
114 return reinterpret_cast<section_iterator*>(SI);
Eric Christophere243fd92011-04-03 22:34:07 +0000115 }
116
117 inline LLVMSectionIteratorRef
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000118 wrap(const section_iterator *SI) {
Eric Christophere243fd92011-04-03 22:34:07 +0000119 return reinterpret_cast<LLVMSectionIteratorRef>
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000120 (const_cast<section_iterator*>(SI));
Eric Christophere243fd92011-04-03 22:34:07 +0000121 }
Owen Anderson3cb05672011-10-21 17:50:59 +0000122
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 }
Owen Andersond8b0b912011-10-27 17:15:47 +0000132
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
Eric Christophere243fd92011-04-03 22:34:07 +0000143 }
144}
145
146#endif /* defined(__cplusplus) */
147
148#endif
149