[Object] Allow iterating over an IRObjectFile's modules
authorJustin Bogner <mail@justinbogner.com>
Wed, 27 Jun 2018 17:58:32 +0000 (17:58 +0000)
committerJustin Bogner <mail@justinbogner.com>
Wed, 27 Jun 2018 17:58:32 +0000 (17:58 +0000)
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.

llvm-svn: 335759

llvm/include/llvm/Object/IRObjectFile.h

index 559a91a..993359b 100644 (file)
@@ -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);