Fixed ObjectFile functions:
[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 #ifdef __cplusplus
26 #include "llvm/Object/ObjectFile.h"
27
28 extern "C" {
29 #endif
30
31 // Opaque type wrappers
32 typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
33 typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
34 typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
35 typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
36
37 // ObjectFile creation
38 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
39 void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
40
41 // ObjectFile Section iterators
42 LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
43 void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
44 LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
45                                 LLVMSectionIteratorRef SI);
46 void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
47 void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
48                                  LLVMSymbolIteratorRef Sym);
49
50 // ObjectFile Symbol iterators
51 LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
52 void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
53 LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
54                                 LLVMSymbolIteratorRef SI);
55 void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
56
57 // SectionRef accessors
58 const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
59 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
60 const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
61 uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
62 LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
63                                  LLVMSymbolIteratorRef Sym);
64
65 // Section Relocation iterators
66 LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
67 void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
68 LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
69                                        LLVMRelocationIteratorRef RI);
70 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
71
72
73 // SymbolRef accessors
74 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
75 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
76 uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
77 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
78
79 // RelocationRef accessors
80 uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
81 uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
82 LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
83 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
84 // NOTE: Caller takes ownership of returned string of the two
85 // following functions.
86 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
87 const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
88
89
90 #ifdef __cplusplus
91 }
92
93 namespace llvm {
94   namespace object {
95     inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
96       return reinterpret_cast<ObjectFile*>(OF);
97     }
98
99     inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
100       return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
101     }
102
103     inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
104       return reinterpret_cast<section_iterator*>(SI);
105     }
106
107     inline LLVMSectionIteratorRef
108     wrap(const section_iterator *SI) {
109       return reinterpret_cast<LLVMSectionIteratorRef>
110         (const_cast<section_iterator*>(SI));
111     }
112
113     inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
114       return reinterpret_cast<symbol_iterator*>(SI);
115     }
116
117     inline LLVMSymbolIteratorRef
118     wrap(const symbol_iterator *SI) {
119       return reinterpret_cast<LLVMSymbolIteratorRef>
120         (const_cast<symbol_iterator*>(SI));
121     }
122
123     inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
124       return reinterpret_cast<relocation_iterator*>(SI);
125     }
126
127     inline LLVMRelocationIteratorRef
128     wrap(const relocation_iterator *SI) {
129       return reinterpret_cast<LLVMRelocationIteratorRef>
130         (const_cast<relocation_iterator*>(SI));
131     }
132
133   }
134 }
135
136 #endif /* defined(__cplusplus) */
137
138 #endif
139