Object.cpp revision 25b15777df42d5d608810f6881b6c98107481d69
1e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher//===- Object.cpp - C bindings to the object file library--------*- C++ -*-===// 2e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// 3e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// The LLVM Compiler Infrastructure 4e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// 5e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// This file is distributed under the University of Illinois Open Source 6e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// License. See LICENSE.TXT for details. 7e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// 8e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher//===----------------------------------------------------------------------===// 9e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// 10e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// This file defines the C bindings to the file-format-independent object 11e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// library. 12e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher// 13e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher//===----------------------------------------------------------------------===// 14e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 15e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#include "llvm/Object/ObjectFile.h" 16e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher#include "llvm-c/Object.h" 17e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 18e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherusing namespace llvm; 19e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherusing namespace object; 20e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 21e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) { 22e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return wrap(ObjectFile::createObjectFile(unwrap(MemBuf))); 23e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 24e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 25e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) { 26e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher delete unwrap(ObjectFile); 27e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 28e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 29e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile) { 30e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher ObjectFile::section_iterator SI = unwrap(ObjectFile)->begin_sections(); 31e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return wrap(new ObjectFile::section_iterator(SI)); 32e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 33e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 34e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI) { 35e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher delete unwrap(SI); 36e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 37e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 38e243fd9e2be8897c9350650b724d7eda2f607f8fEric ChristopherLLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, 39e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher LLVMSectionIteratorRef SI) { 40e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher return (*unwrap(SI) == unwrap(ObjectFile)->end_sections()) ? 1 : 0; 41e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 42e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 43e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christophervoid LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { 4425b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer error_code ec; 4525b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer unwrap(SI)->increment(ec); 4625b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message()); 47e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 48e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 49e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherconst char *LLVMGetSectionName(LLVMSectionIteratorRef SI) { 5025b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer StringRef ret; 5125b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer if (error_code ec = (*unwrap(SI))->getName(ret)) 5225b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer report_fatal_error(ec.message()); 5325b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer return ret.data(); 54e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 55e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 56e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopheruint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) { 5725b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer uint64_t ret; 5825b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer if (error_code ec = (*unwrap(SI))->getSize(ret)) 5925b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer report_fatal_error(ec.message()); 6025b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer return ret; 61e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 62e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher 63e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopherconst char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) { 6425b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer StringRef ret; 6525b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer if (error_code ec = (*unwrap(SI))->getContents(ret)) 6625b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer report_fatal_error(ec.message()); 6725b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer return ret.data(); 68e243fd9e2be8897c9350650b724d7eda2f607f8fEric Christopher} 69