Kill ModuleProvider and ghost linkage by inverting the relationship between
[oota-llvm.git] / include / llvm / Bitcode / Archive.h
index 50562e490ff97f19aeacaf7e93d27acd4617a904..67f2a4a999b84414a626cdc99f54e85f0b75e323 100644 (file)
 #ifndef LLVM_BITCODE_ARCHIVE_H
 #define LLVM_BITCODE_ARCHIVE_H
 
-#include "llvm/ADT/ilist"
+#include "llvm/ADT/ilist.h"
+#include "llvm/ADT/ilist_node.h"
 #include "llvm/System/Path.h"
 #include <map>
 #include <set>
-#include <fstream>
 
 namespace llvm {
   class MemoryBuffer;
 
 // Forward declare classes
-class ModuleProvider;      // From VMCore
 class Module;              // From VMCore
 class Archive;             // Declared below
 class ArchiveMemberHeader; // Internal implementation class
+class LLVMContext;         // Global data
 
 /// This class is the main class manipulated by users of the Archive class. It
 /// holds information about one member of the Archive. It is also the element
@@ -39,7 +39,7 @@ class ArchiveMemberHeader; // Internal implementation class
 /// construct ArchiveMember instances. You should obtain them from the methods
 /// of the Archive class instead.
 /// @brief This class represents a single archive member.
-class ArchiveMember {
+class ArchiveMember : public ilist_node<ArchiveMember> {
   /// @name Types
   /// @{
   public:
@@ -164,23 +164,10 @@ class ArchiveMember {
     /// @brief Replace contents of archive member with a new file.
     bool replaceWith(const sys::Path &aFile, std::string* ErrMsg);
 
-  /// @}
-  /// @name ilist methods - do not use
-  /// @{
-  public:
-    const ArchiveMember *getNext() const { return next; }
-    const ArchiveMember *getPrev() const { return prev; }
-    ArchiveMember *getNext()             { return next; }
-    ArchiveMember *getPrev()             { return prev; }
-    void setPrev(ArchiveMember* p)       { prev = p; }
-    void setNext(ArchiveMember* n)       { next = n; }
-
   /// @}
   /// @name Data
   /// @{
   private:
-    ArchiveMember*      next;     ///< Pointer to next archive member
-    ArchiveMember*      prev;     ///< Pointer to previous archive member
     Archive*            parent;   ///< Pointer to parent archive
     sys::PathWithStatus path;     ///< Path of file containing the member
     sys::FileStatus     info;     ///< Status info (size,mode,date)
@@ -216,7 +203,7 @@ class ArchiveMember {
 /// applications and the linkers. Consequently, the implementation of the class
 /// is optimized for reading.
 class Archive {
-  
+
   /// @name Types
   /// @{
   public:
@@ -290,7 +277,8 @@ class Archive {
     /// @returns An Archive* that represents the new archive file.
     /// @brief Create an empty Archive.
     static Archive* CreateEmpty(
-      const sys::Path& Filename ///< Name of the archive to (eventually) create.
+      const sys::Path& Filename,///< Name of the archive to (eventually) create.
+      LLVMContext& C            ///< Context to use for global information
     );
 
     /// Open an existing archive and load its contents in preparation for
@@ -301,6 +289,7 @@ class Archive {
     /// @brief Open and load an archive file
     static Archive* OpenAndLoad(
       const sys::Path& filePath,  ///< The file path to open and load
+      LLVMContext& C,       ///< The context to use for global information
       std::string* ErrorMessage   ///< An optional error string
     );
 
@@ -322,6 +311,7 @@ class Archive {
     /// @brief Open an existing archive and load its symbols.
     static Archive* OpenAndLoadSymbols(
       const sys::Path& Filename,   ///< Name of the archive file to open
+      LLVMContext& C,              ///< The context to use for global info
       std::string* ErrorMessage=0  ///< An optional error string
     );
 
@@ -383,14 +373,14 @@ class Archive {
     /// returns the associated module that defines that symbol. This method can
     /// be called as many times as necessary. This is handy for linking the
     /// archive into another module based on unresolved symbols. Note that the
-    /// ModuleProvider returned by this accessor should not be deleted by the
-    /// caller. It is managed internally by the Archive class. It is possible
-    /// that multiple calls to this accessor will return the same ModuleProvider
-    /// instance because the associated module defines multiple symbols.
-    /// @returns The ModuleProvider* found or null if the archive does not
-    /// contain a module that defines the \p symbol.
+    /// Module returned by this accessor should not be deleted by the caller. It
+    /// is managed internally by the Archive class. It is possible that multiple
+    /// calls to this accessor will return the same Module instance because the
+    /// associated module defines multiple symbols.
+    /// @returns The Module* found or null if the archive does not contain a
+    /// module that defines the \p symbol.
     /// @brief Look up a module by symbol name.
-    ModuleProvider* findModuleDefiningSymbol(
+    Module* findModuleDefiningSymbol(
       const std::string& symbol,  ///< Symbol to be sought
       std::string* ErrMessage     ///< Error message storage, if non-zero
     );
@@ -406,7 +396,7 @@ class Archive {
     /// @brief Look up multiple symbols in the archive.
     bool findModulesDefiningSymbols(
       std::set<std::string>& symbols,     ///< Symbols to be sought
-      std::set<ModuleProvider*>& modules, ///< The modules matching \p symbols
+      std::set<Module*>& modules,         ///< The modules matching \p symbols
       std::string* ErrMessage             ///< Error msg storage, if non-zero
     );
 
@@ -461,7 +451,7 @@ class Archive {
   protected:
     /// @brief Construct an Archive for \p filename and optionally  map it
     /// into memory.
-    explicit Archive(const sys::Path& filename);
+    explicit Archive(const sys::Path& filename, LLVMContext& C);
 
     /// @param data The symbol table data to be parsed
     /// @param len  The length of the symbol table data
@@ -497,7 +487,7 @@ class Archive {
     void writeSymbolTable(std::ofstream& ARFile);
 
     /// Writes one ArchiveMember to an ofstream. If an error occurs, returns
-    /// false, otherwise true. If an error occurs and error is non-null then 
+    /// false, otherwise true. If an error occurs and error is non-null then
     /// it will be set to an error message.
     /// @returns false Writing member succeeded
     /// @returns true Writing member failed, \p error set to error message
@@ -522,9 +512,9 @@ class Archive {
 
     /// This type is used to keep track of bitcode modules loaded from the
     /// symbol table. It maps the file offset to a pair that consists of the
-    /// associated ArchiveMember and the ModuleProvider.
+    /// associated ArchiveMember and the Module.
     /// @brief Module mapping type
-    typedef std::map<unsigned,std::pair<ModuleProvider*,ArchiveMember*> >
+    typedef std::map<unsigned,std::pair<Module*,ArchiveMember*> >
       ModuleMap;
 
 
@@ -542,6 +532,7 @@ class Archive {
     unsigned firstFileOffset; ///< Offset to first normal file.
     ModuleMap modules;        ///< The modules loaded via symbol lookup.
     ArchiveMember* foreignST; ///< This holds the foreign symbol table.
+    LLVMContext& Context;     ///< This holds global data.
   /// @}
   /// @name Hidden
   /// @{