[llvm] r335759 - [Object] Allow iterating over an IRObjectFile's modules

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 27 10:58:32 PDT 2018


Author: bogner
Date: Wed Jun 27 10:58:32 2018
New Revision: 335759

URL: http://llvm.org/viewvc/llvm-project?rev=335759&view=rev
Log:
[Object] Allow iterating over an IRObjectFile's modules

If you've already loaded an IRObjectFile and need access to the
Modules themselves you shouldn't have to reparse a byte stream to do
it. Adds an accessor for the modules in IRObjectFile.

Modified:
    llvm/trunk/include/llvm/Object/IRObjectFile.h

Modified: llvm/trunk/include/llvm/Object/IRObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRObjectFile.h?rev=335759&r1=335758&r2=335759&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/IRObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/IRObjectFile.h Wed Jun 27 10:58:32 2018
@@ -50,6 +50,17 @@ public:
     return v->isIR();
   }
 
+  using module_iterator =
+      pointee_iterator<std::vector<std::unique_ptr<Module>>::const_iterator,
+                       const Module>;
+
+  module_iterator module_begin() const { return module_iterator(Mods.begin()); }
+  module_iterator module_end() const { return module_iterator(Mods.end()); }
+
+  iterator_range<module_iterator> modules() const {
+    return make_range(module_begin(), module_end());
+  }
+
   /// Finds and returns bitcode embedded in the given object file, or an
   /// error code if not found.
   static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);




More information about the llvm-commits mailing list