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