blob: 6acad85c55a14b0bbd7b8ddf5407c5208ebe8814 [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 Andersone2fa64e2011-10-21 18:21:22 +000046void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
47 LLVMSymbolIteratorRef Sym);
Owen Anderson3cb05672011-10-21 17:50:59 +000048
49// ObjectFile Symbol iterators
50LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
51void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
52LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
53 LLVMSymbolIteratorRef SI);
54void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);
55
56// SectionRef accessors
Eric Christophere243fd92011-04-03 22:34:07 +000057const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);
58uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
59const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
Owen Anderson3cb05672011-10-21 17:50:59 +000060uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
61int LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
62 LLVMSymbolIteratorRef Sym);
Eric Christophere243fd92011-04-03 22:34:07 +000063
Owen Anderson3cb05672011-10-21 17:50:59 +000064// SymbolRef accessors
65const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
66uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
67uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI);
68uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
Eric Christophere243fd92011-04-03 22:34:07 +000069
70#ifdef __cplusplus
71}
72
73namespace llvm {
74 namespace object {
75 inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
76 return reinterpret_cast<ObjectFile*>(OF);
77 }
78
79 inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
80 return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
81 }
82
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000083 inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
84 return reinterpret_cast<section_iterator*>(SI);
Eric Christophere243fd92011-04-03 22:34:07 +000085 }
86
87 inline LLVMSectionIteratorRef
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000088 wrap(const section_iterator *SI) {
Eric Christophere243fd92011-04-03 22:34:07 +000089 return reinterpret_cast<LLVMSectionIteratorRef>
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000090 (const_cast<section_iterator*>(SI));
Eric Christophere243fd92011-04-03 22:34:07 +000091 }
Owen Anderson3cb05672011-10-21 17:50:59 +000092
93 inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
94 return reinterpret_cast<symbol_iterator*>(SI);
95 }
96
97 inline LLVMSymbolIteratorRef
98 wrap(const symbol_iterator *SI) {
99 return reinterpret_cast<LLVMSymbolIteratorRef>
100 (const_cast<symbol_iterator*>(SI));
101 }
Eric Christophere243fd92011-04-03 22:34:07 +0000102 }
103}
104
105#endif /* defined(__cplusplus) */
106
107#endif
108