X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FLinker.h;h=3667b8521d90c5c8e482e9f3f4f84e4f9e4e764a;hb=f6db9425648e9d9b965dc0aae9f63afbb3e7a5b8;hp=593d913b59d02c8a75a4b3e00ebb51fa2e265ba2;hpb=e6315cd32b4983c1c1ab900c3e28fdfc4b5d003e;p=oota-llvm.git diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 593d913b59d..3667b8521d9 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -10,116 +10,46 @@ #ifndef LLVM_LINKER_H #define LLVM_LINKER_H +#include "llvm/ADT/SmallPtrSet.h" #include namespace llvm { class Module; -class LLVMContext; class StringRef; +class StructType; -/// 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 -/// into it. The composite Module can be retrieved via the getModule() method. -/// In this case the Linker still retains ownership of the Module. If the -/// releaseModule() method is used, the ownership of the Module is transferred -/// to the caller and the Linker object is only suitable for destruction. -/// The Linker can link Modules from memory. By default, the linker -/// will generate error and warning 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. +/// This class provides the core functionality of linking in LLVM. It keeps a +/// pointer to the merged module so far. It doesn't take ownership of the +/// module since it is assumed that the user of this class will want to do +/// something with it after the linking. class Linker { - - /// @name Types - /// @{ public: enum LinkerMode { DestroySource = 0, // Allow source module to be destroyed. PreserveSource = 1 // Preserve the source module. }; - /// @} - /// @name Constructors - /// @{ - public: - /// 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(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(StringRef progname, Module* aModule, unsigned Flags = 0); - - /// Destruct the Linker. - /// @brief Destructor + Linker(Module *M); ~Linker(); - - /// @} - /// @name Accessors - /// @{ - public: - /// This method gets the composite module into which linking is being - /// done. The Composite module starts out empty and accumulates modules - /// linked into it via the various LinkIn* methods. This method does not - /// release the Module to the caller. The Linker retains ownership and will - /// destruct the Module when the Linker is destructed. - /// @see releaseModule - /// @brief Get the linked/composite module. - Module* getModule() const { return Composite; } - - /// @} - /// @name Mutators - /// @{ - public: - /// This method links the \p Src module into the Linker's Composite module - /// by calling LinkModules. - /// @see LinkModules - /// @returns True if an error occurs, false otherwise. - /// @brief Link in a module. - bool LinkInModule( - Module* Src, ///< Module linked into \p Dest - std::string* ErrorMsg = 0 /// Error/diagnostic string - ) { - return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg); + Module *getModule() const { return Composite; } + + /// \brief Link \p Src into the composite. The source is destroyed if + /// \p Mode is DestroySource and preserved if it is PreserveSource. + /// If \p ErrorMsg is not null, information about any error is written + /// to it. + /// Returns true on error. + bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg); + bool linkInModule(Module *Src, std::string *ErrorMsg) { + return linkInModule(Src, Linker::DestroySource, ErrorMsg); } - /// This is the heart of the linker. This method will take unconditional - /// control of the \p Src module and link it into the \p Dest module. The - /// \p Src module will be destructed or subsumed by this method. In either - /// case it is not usable by the caller after this method is invoked. Only - /// the \p Dest module will remain. The \p Src module is linked into the - /// Linker's composite module such that types, global variables, functions, - /// and etc. are matched and resolved. If an error occurs, this function - /// returns true and ErrorMsg is set to a descriptive message about the - /// error. - /// @returns True if an error occurs, false otherwise. - /// @brief Generically link two modules together. - static bool LinkModules(Module* Dest, Module* Src, unsigned Mode, - std::string* ErrorMsg); + static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, + std::string *ErrorMsg); - /// @} - /// @name Implementation - /// @{ private: - /// @} - /// @name Data - /// @{ - private: - LLVMContext& Context; ///< The context for global information - Module* Composite; ///< The composite module linked together - unsigned Flags; ///< Flags to control optional behavior. - std::string Error; ///< Text of error that occurred. - std::string ProgramName; ///< Name of the program being linked - /// @} - + Module *Composite; + SmallPtrSet IdentifiedStructTypes; }; } // End llvm namespace