2011-04-03 22:34:07 +00:00
|
|
|
//===- Object.cpp - C bindings to the object file library--------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the C bindings to the file-format-independent object
|
|
|
|
// library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
|
|
|
#include "llvm-c/Object.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace object;
|
|
|
|
|
2011-10-21 17:50:59 +00:00
|
|
|
// ObjectFile creation
|
2011-04-03 22:34:07 +00:00
|
|
|
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
|
|
|
|
return wrap(ObjectFile::createObjectFile(unwrap(MemBuf)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) {
|
|
|
|
delete unwrap(ObjectFile);
|
|
|
|
}
|
|
|
|
|
2011-10-21 17:50:59 +00:00
|
|
|
// ObjectFile Section iterators
|
2011-04-03 22:34:07 +00:00
|
|
|
LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile) {
|
2011-10-07 19:25:32 +00:00
|
|
|
section_iterator SI = unwrap(ObjectFile)->begin_sections();
|
|
|
|
return wrap(new section_iterator(SI));
|
2011-04-03 22:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI) {
|
|
|
|
delete unwrap(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
|
|
|
|
LLVMSectionIteratorRef SI) {
|
|
|
|
return (*unwrap(SI) == unwrap(ObjectFile)->end_sections()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
|
2011-06-25 17:55:23 +00:00
|
|
|
error_code ec;
|
|
|
|
unwrap(SI)->increment(ec);
|
|
|
|
if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message());
|
2011-04-03 22:34:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 17:50:59 +00:00
|
|
|
// ObjectFile Symbol iterators
|
|
|
|
LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile) {
|
|
|
|
symbol_iterator SI = unwrap(ObjectFile)->begin_symbols();
|
|
|
|
return wrap(new symbol_iterator(SI));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI) {
|
|
|
|
delete unwrap(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
|
|
|
|
LLVMSymbolIteratorRef SI) {
|
|
|
|
return (*unwrap(SI) == unwrap(ObjectFile)->end_symbols()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
|
|
|
|
error_code ec;
|
|
|
|
unwrap(SI)->increment(ec);
|
|
|
|
if (ec) report_fatal_error("LLVMMoveToNextSymbol failed: " + ec.message());
|
|
|
|
}
|
|
|
|
|
|
|
|
// SectionRef accessors
|
2011-04-03 22:34:07 +00:00
|
|
|
const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
|
2011-06-25 17:55:23 +00:00
|
|
|
StringRef ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getName(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret.data();
|
2011-04-03 22:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
|
2011-06-25 17:55:23 +00:00
|
|
|
uint64_t ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getSize(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
2011-04-03 22:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
|
2011-06-25 17:55:23 +00:00
|
|
|
StringRef ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getContents(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret.data();
|
2011-04-03 22:34:07 +00:00
|
|
|
}
|
2011-10-21 17:50:59 +00:00
|
|
|
|
|
|
|
uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) {
|
|
|
|
uint64_t ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getAddress(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
|
|
|
|
LLVMSymbolIteratorRef Sym) {
|
|
|
|
bool ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SymbolRef accessors
|
|
|
|
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
|
|
|
StringRef ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getName(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
|
|
|
|
uint64_t ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getAddress(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI) {
|
|
|
|
uint64_t ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getOffset(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
|
|
|
|
uint64_t ret;
|
|
|
|
if (error_code ec = (*unwrap(SI))->getSize(ret))
|
|
|
|
report_fatal_error(ec.message());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|