From d1ba3b13f83ebb7a76b62cacb1a97006c8d9f4b3 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 9 Apr 2019 21:53:31 +0000 Subject: [LLVM-C] Add Section and Symbol Iterator Accessors for Object File Binaries Summary: This brings us to full feature parity with the old API, so I've deprecated it and updated the tests. I'll do a follow-up patch to do some more cleanup and documentation work in this header. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60407 llvm-svn: 358037 --- llvm/lib/Object/Object.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'llvm/lib/Object/Object.cpp') diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index 3a88477..77e27ec 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -131,6 +131,34 @@ LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR) { return BinaryTypeMapper::mapBinaryTypeToLLVMBinaryType(unwrap(BR)->getType()); } +LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR) { + auto OF = cast(unwrap(BR)); + auto sections = OF->sections(); + if (sections.begin() == sections.end()) + return nullptr; + return wrap(new section_iterator(sections.begin())); +} + +LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR, + LLVMSectionIteratorRef SI) { + auto OF = cast(unwrap(BR)); + return (*unwrap(SI) == OF->section_end()) ? 1 : 0; +} + +LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR) { + auto OF = cast(unwrap(BR)); + auto symbols = OF->symbols(); + if (symbols.begin() == symbols.end()) + return nullptr; + return wrap(new symbol_iterator(symbols.begin())); +} + +LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR, + LLVMSymbolIteratorRef SI) { + auto OF = cast(unwrap(BR)); + return (*unwrap(SI) == OF->symbol_end()) ? 1 : 0; +} + // ObjectFile creation LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) { std::unique_ptr Buf(unwrap(MemBuf)); -- cgit v1.1