blob: 3e6e1e3ffce003067f76b5ff7a6f2fc53c2b3e41 [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 Anderson3cb05672011-10-21 17:50:59 +000034typedef struct LLVMOpauqeSymbolIterator *LLVMSymbolIteratorRef;
Eric Christophere243fd92011-04-03 22:34:07 +000035
Owen Anderson3cb05672011-10-21 17:50:59 +000036// ObjectFile creation
Eric Christophere243fd92011-04-03 22:34:07 +000037LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
38void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);
39
Owen Anderson3cb05672011-10-21 17:50:59 +000040// ObjectFile Section iterators
Eric Christophere243fd92011-04-03 22:34:07 +000041LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
42void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
43LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
44 LLVMSectionIteratorRef SI);
45void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000046
47// ObjectFile Symbol iterators
48LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
49void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
50LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
51 LLVMSymbolIteratorRef SI);
52void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
53
54// SectionRef accessors
Eric Christophere243fd92011-04-03 22:34:07 +000055const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
56uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
57const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000058uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
59int LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
60 LLVMSymbolIteratorRef Sym);
Eric Christophere243fd92011-04-03 22:34:07 +000061
Owen Anderson3cb05672011-10-21 17:50:59 +000062// SymbolRef accessors
63const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
64uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
65uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI);
66uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
Eric Christophere243fd92011-04-03 22:34:07 +000067
68#ifdef __cplusplus
69}
70
71namespace llvm {
72 namespace object {
73 inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
74 return reinterpret_cast<ObjectFile*>(OF);
75 }
76
77 inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
78 return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
79 }
80
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000081 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
82 return reinterpret_cast<section_iterator*>(SI);
Eric Christophere243fd92011-04-03 22:34:07 +000083 }
84
85 inline LLVMSectionIteratorRef
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000086 wrap(const section_iterator *SI) {
Eric Christophere243fd92011-04-03 22:34:07 +000087 return reinterpret_cast<LLVMSectionIteratorRef>
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000088 (const_cast<section_iterator*>(SI));
Eric Christophere243fd92011-04-03 22:34:07 +000089 }
Owen Anderson3cb05672011-10-21 17:50:59 +000090
91 inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
92 return reinterpret_cast<symbol_iterator*>(SI);
93 }
94
95 inline LLVMSymbolIteratorRef
96 wrap(const symbol_iterator *SI) {
97 return reinterpret_cast<LLVMSymbolIteratorRef>
98 (const_cast<symbol_iterator*>(SI));
99 }
Eric Christophere243fd92011-04-03 22:34:07 +0000100 }
101}
102
103#endif /* defined(__cplusplus) */
104
105#endif
106