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);