The TargetData is not used for the isPowerOfTwo determination. It has never
[oota-llvm.git] / include / llvm / Linker.h
index 2ab0ed4705915731c098c20be9f66d17ff74b88c..1ebcd6b53863541d6207cc8877219e7152419c2a 100644 (file)
 #ifndef LLVM_LINKER_H
 #define LLVM_LINKER_H
 
-#include "llvm/System/Path.h"
 #include <memory>
+#include <string>
 #include <vector>
 
 namespace llvm {
+  namespace sys { class Path; }
 
 class Module;
 class LLVMContext;
+class StringRef;
 
 /// This class provides the core functionality of linking in LLVM. It retains a
 /// Module object which is the composite of the modules and libraries linked
@@ -32,7 +34,7 @@ class LLVMContext;
 /// The Linker can link Modules from memory, bitcode files, or bitcode
 /// archives.  It retains a set of search paths in which to find any libraries
 /// presented to it. By default, the linker will generate error and warning
-/// messages to std::cerr but this capability can be turned off with the
+/// messages to stderr but this capability can be turned off with the
 /// QuietWarnings and QuietErrors flags. It can also be instructed to verbosely
 /// print out the linking actions it is taking with the Verbose flag.
 /// @brief The LLVM Linker.
@@ -52,11 +54,16 @@ class Linker {
     /// This enumeration is used to control various optional features of the
     /// linker.
     enum ControlFlags {
-      Verbose       = 1, ///< Print to std::cerr what steps the linker is taking
-      QuietWarnings = 2, ///< Don't print warnings to std::cerr.
-      QuietErrors   = 4  ///< Don't print errors to std::cerr.
+      Verbose       = 1, ///< Print to stderr what steps the linker is taking
+      QuietWarnings = 2, ///< Don't print warnings to stderr.
+      QuietErrors   = 4  ///< Don't print errors to stderr.
     };
-
+  
+    enum LinkerMode {
+      DestroySource = 0, // Allow source module to be destroyed.
+      PreserveSource = 1 // Preserve the source module.
+    };
+  
   /// @}
   /// @name Constructors
   /// @{
@@ -64,17 +71,16 @@ class Linker {
     /// Construct the Linker with an empty module which will be given the
     /// name \p progname. \p progname will also be used for error messages.
     /// @brief Construct with empty module
-    Linker(
-        const std::string& progname, ///< name of tool running linker
-        const std::string& modulename, ///< name of linker's end-result module
-        const LLVMContext& C, ///< Context for global info
-        unsigned Flags = 0  ///< ControlFlags (one or more |'d together)
+    Linker(StringRef progname, ///< name of tool running linker
+           StringRef modulename, ///< name of linker's end-result module
+           LLVMContext &C, ///< Context for global info
+           unsigned Flags = 0  ///< ControlFlags (one or more |'d together)
     );
 
     /// Construct the Linker with a previously defined module, \p aModule. Use
     /// \p progname for the name of the program in error messages.
     /// @brief Construct with existing module
-    Linker(const std::string& progname, Module* aModule, unsigned Flags = 0);
+    Linker(StringRef progname, Module* aModule, unsigned Flags = 0);
 
     /// Destruct the Linker.
     /// @brief Destructor
@@ -114,9 +120,9 @@ class Linker {
     /// true, indicating an error occurred. At most one error is retained so
     /// this function always returns the last error that occurred. Note that if
     /// the Quiet control flag is not set, the error string will have already
-    /// been printed to std::cerr.
+    /// been printed to stderr.
     /// @brief Get the text of the last error that occurred.
-    const std::stringgetLastError() const { return Error; }
+    const std::string &getLastError() const { return Error; }
 
   /// @}
   /// @name Mutators
@@ -158,7 +164,6 @@ class Linker {
     /// @returns true if an error occurred, false otherwise
     /// @see LinkItemKind
     /// @see getLastError
-    /// @throws nothing
     bool LinkInItems (
       const ItemList& Items, ///< Set of libraries/files to link in
       ItemList& NativeItems  ///< Output list of native files/libs
@@ -214,8 +219,8 @@ class Linker {
     /// @returns true if an error occurs, false otherwise
     /// @brief Link one library into the module
     bool LinkInLibrary (
-      const std::string& Library, ///< The library to link in
-      bool& is_native             ///< Indicates if lib a native library
+      StringRef Library, ///< The library to link in
+      bool& is_native    ///< Indicates if lib a native library
     );
 
     /// This function links one bitcode archive, \p Filename, into the module.
@@ -223,7 +228,7 @@ class Linker {
     /// the archive that resolve outstanding symbols will be linked in. The
     /// library is searched repeatedly until no more modules that resolve
     /// symbols can be found. If an error occurs, the error string is  set.
-    /// To speed up this function, ensure the the archive has been processed
+    /// To speed up this function, ensure the archive has been processed
     /// llvm-ranlib or the S option was given to llvm-ar when the archive was
     /// created. These tools add a symbol table to the archive which makes the
     /// search for undefined symbols much faster.
@@ -246,7 +251,7 @@ class Linker {
       Module* Src,              ///< Module linked into \p Dest
       std::string* ErrorMsg = 0 /// Error/diagnostic string
     ) { 
-      return LinkModules(Composite, Src, ErrorMsg ); 
+      return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg ); 
     }
 
     /// This is the heart of the linker. This method will take unconditional
@@ -260,14 +265,15 @@ class Linker {
     /// error.
     /// @returns True if an error occurs, false otherwise.
     /// @brief Generically link two modules together.
-    static bool LinkModules(Module* Dest, Module* Src, std::string* ErrorMsg);
+    static bool LinkModules(Module* Dest, Module* Src, unsigned Mode,
+                            std::string* ErrorMsg);
 
     /// This function looks through the Linker's LibPaths to find a library with
     /// the name \p Filename. If the library cannot be found, the returned path
     /// will be empty (i.e. sys::Path::isEmpty() will return true).
     /// @returns A sys::Path to the found library
     /// @brief Find a library from its short name.
-    sys::Path FindLib(const std::string &Filename);
+    sys::Path FindLib(StringRef Filename);
 
   /// @}
   /// @name Implementation
@@ -277,15 +283,15 @@ class Linker {
     /// Module it contains (wrapped in an auto_ptr), or 0 if an error occurs.
     std::auto_ptr<Module> LoadObject(const sys::Path& FN);
 
-    bool warning(const std::string& message);
-    bool error(const std::string& message);
-    void verbose(const std::string& message);
+    bool warning(StringRef message);
+    bool error(StringRef message);
+    void verbose(StringRef message);
 
   /// @}
   /// @name Data
   /// @{
   private:
-    const LLVMContext& Context; ///< The context for global information
+    LLVMContext& Context; ///< The context for global information
     Module* Composite; ///< The composite module linked together
     std::vector<sys::Path> LibPaths; ///< The library search paths
     unsigned Flags;    ///< Flags to control optional behavior.