From 3bbd741c2e0e9c17bb1a6406be37e6991b6d14cd Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 14 Mar 2011 18:12:16 -0700 Subject: [PATCH] llvmext: Make the Object bindings actually work --- src/llvmext/Object.cpp | 14 +++++++++----- src/llvmext/include/llvm-c/Object.h | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/llvmext/Object.cpp b/src/llvmext/Object.cpp index f390870fb33..603e72b9036 100644 --- a/src/llvmext/Object.cpp +++ b/src/llvmext/Object.cpp @@ -18,9 +18,8 @@ using namespace llvm; using namespace object; -LLVMObjectFileRef LLVMCreateObjectFile(const char *ObjectPath) { - StringRef SR(ObjectPath); - return wrap(ObjectFile::createObjectFile(SR)); +LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) { + return wrap(ObjectFile::createObjectFile(unwrap(MemBuf))); } void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) { @@ -36,9 +35,14 @@ void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI) { delete unwrap(SI); } +bool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, + LLVMSectionIteratorRef SI) { + return *unwrap(SI) == unwrap(ObjectFile)->end_sections(); +} + void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { - ObjectFile::section_iterator UnwrappedSI = *unwrap(SI); - ++UnwrappedSI; + // We can't use unwrap() here because the argument to ++ must be an lvalue. + ++*reinterpret_cast(SI); } const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) { diff --git a/src/llvmext/include/llvm-c/Object.h b/src/llvmext/include/llvm-c/Object.h index a65a2352aa0..1103d7dd969 100644 --- a/src/llvmext/include/llvm-c/Object.h +++ b/src/llvmext/include/llvm-c/Object.h @@ -33,11 +33,13 @@ typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; -LLVMObjectFileRef LLVMCreateObjectFile(const char *ObjectPath); +LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); +bool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, + LLVMSectionIteratorRef SI); void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);