blob: 2ea8db978670edb7d8b87617f6e83ef6f5a91c12 [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) {
Michael J. Spencer4344b1e2011-10-07 19:25:32 +000030 section_iterator SI = unwrap(ObjectFile)->begin_sections();
31 return wrap(new section_iterator(SI));
Eric Christophere243fd92011-04-03 22:34:07 +000032}
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) {
Michael J. Spencer25b15772011-06-25 17:55:23 +000044 error_code ec;
45 unwrap(SI)->increment(ec);
46 if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message());
Eric Christophere243fd92011-04-03 22:34:07 +000047}
48
49const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
Michael J. Spencer25b15772011-06-25 17:55:23 +000050 StringRef ret;
51 if (error_code ec = (*unwrap(SI))->getName(ret))
52 report_fatal_error(ec.message());
53 return ret.data();
Eric Christophere243fd92011-04-03 22:34:07 +000054}
55
56uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
Michael J. Spencer25b15772011-06-25 17:55:23 +000057 uint64_t ret;
58 if (error_code ec = (*unwrap(SI))->getSize(ret))
59 report_fatal_error(ec.message());
60 return ret;
Eric Christophere243fd92011-04-03 22:34:07 +000061}
62
63const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
Michael J. Spencer25b15772011-06-25 17:55:23 +000064 StringRef ret;
65 if (error_code ec = (*unwrap(SI))->getContents(ret))
66 report_fatal_error(ec.message());
67 return ret.data();
Eric Christophere243fd92011-04-03 22:34:07 +000068}