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