blob: ccf62868cf26e20c71a37c63aef291324f1ce343 [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
Owen Anderson3cb05672011-10-21 17:50:59 +000031// Opaque type wrappers
Eric Christophere243fd92011-04-03 22:34:07 +000032typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
Eric Christophere243fd92011-04-03 22:34:07 +000033typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
Owen Anderson65f73ab2011-10-21 20:28:19 +000034typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
Owen Andersond8b0b912011-10-27 17:15:47 +000035typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
Eric Christophere243fd92011-04-03 22:34:07 +000036
Owen Anderson3cb05672011-10-21 17:50:59 +000037// ObjectFile creation
Eric Christophere243fd92011-04-03 22:34:07 +000038LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
39void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
40
Owen Anderson3cb05672011-10-21 17:50:59 +000041// ObjectFile Section iterators
Eric Christophere243fd92011-04-03 22:34:07 +000042LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
43void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
44LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
45 LLVMSectionIteratorRef SI);
46void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
Owen Andersone2fa64e2011-10-21 18:21:22 +000047void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
48 LLVMSymbolIteratorRef Sym);
Owen Anderson3cb05672011-10-21 17:50:59 +000049
50// ObjectFile Symbol iterators
51LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
52void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
53LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
54 LLVMSymbolIteratorRef SI);
55void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
56
57// SectionRef accessors
Eric Christophere243fd92011-04-03 22:34:07 +000058const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
59uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
60const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000061uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
Owen Andersonca7eb3e2011-10-21 20:35:58 +000062LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
Owen Anderson3cb05672011-10-21 17:50:59 +000063 LLVMSymbolIteratorRef Sym);
Eric Christophere243fd92011-04-03 22:34:07 +000064
Owen Andersond8b0b912011-10-27 17:15:47 +000065// Section Relocation iterators
66LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
67void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
68LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
69 LLVMRelocationIteratorRef RI);
70void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
71
72
Owen Anderson3cb05672011-10-21 17:50:59 +000073// SymbolRef accessors
74const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
75uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
76uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI);
77uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
Eric Christophere243fd92011-04-03 22:34:07 +000078
79#ifdef __cplusplus
80}
81
82namespace llvm {
83 namespace object {
84 inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
85 return reinterpret_cast<ObjectFile*>(OF);
86 }
87
88 inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
89 return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
90 }
91
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000092 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
93 return reinterpret_cast<section_iterator*>(SI);
Eric Christophere243fd92011-04-03 22:34:07 +000094 }
95
96 inline LLVMSectionIteratorRef
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000097 wrap(const section_iterator *SI) {
Eric Christophere243fd92011-04-03 22:34:07 +000098 return reinterpret_cast<LLVMSectionIteratorRef>
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000099 (const_cast<section_iterator*>(SI));
Eric Christophere243fd92011-04-03 22:34:07 +0000100 }
Owen Anderson3cb05672011-10-21 17:50:59 +0000101
102 inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
103 return reinterpret_cast<symbol_iterator*>(SI);
104 }
105
106 inline LLVMSymbolIteratorRef
107 wrap(const symbol_iterator *SI) {
108 return reinterpret_cast<LLVMSymbolIteratorRef>
109 (const_cast<symbol_iterator*>(SI));
110 }
Owen Andersond8b0b912011-10-27 17:15:47 +0000111
112 inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
113 return reinterpret_cast<relocation_iterator*>(SI);
114 }
115
116 inline LLVMRelocationIteratorRef
117 wrap(const relocation_iterator *SI) {
118 return reinterpret_cast<LLVMRelocationIteratorRef>
119 (const_cast<relocation_iterator*>(SI));
120 }
121
Eric Christophere243fd92011-04-03 22:34:07 +0000122 }
123}
124
125#endif /* defined(__cplusplus) */
126
127#endif
128