blob: 603b23c74e9346f100a64e9b0da91d61d4fb018a [file] [log] [blame]
Eric Christophere243fd92011-04-03 22:34:07 +00001//===- Object.cpp - C bindings to the object file library--------*- 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 file defines the C bindings to the file-format-independent object
11// library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Object/ObjectFile.h"
16#include "llvm-c/Object.h"
17
18using namespace llvm;
19using namespace object;
20
21LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
22 return wrap(ObjectFile::createObjectFile(unwrap(MemBuf)));
23}
24
25void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) {
26 delete unwrap(ObjectFile);
27}
28
29LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile) {
30 ObjectFile::section_iterator SI = unwrap(ObjectFile)->begin_sections();
31 return wrap(new ObjectFile::section_iterator(SI));
32}
33
34void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI) {
35 delete unwrap(SI);
36}
37
38LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
39 LLVMSectionIteratorRef SI) {
40 return (*unwrap(SI) == unwrap(ObjectFile)->end_sections()) ? 1 : 0;
41}
42
43void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
44 // We can't use unwrap() here because the argument to ++ must be an lvalue.
45 ++*reinterpret_cast<ObjectFile::section_iterator*>(SI);
46}
47
48const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
49 return (*unwrap(SI))->getName().data();
50}
51
52uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
53 return (*unwrap(SI))->getSize();
54}
55
56const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
57 return (*unwrap(SI))->getContents().data();
58}
59