2004-11-14 20:21:58 +00:00
|
|
|
//===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-13 16:57:49 +00:00
|
|
|
|
2004-11-14 20:21:58 +00:00
|
|
|
#ifndef LLVM_LINKER_H
|
|
|
|
#define LLVM_LINKER_H
|
2001-10-13 16:57:49 +00:00
|
|
|
|
2012-03-26 06:58:25 +00:00
|
|
|
#include <string>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2001-10-13 16:57:49 +00:00
|
|
|
class Module;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2012-03-26 06:58:25 +00:00
|
|
|
class StringRef;
|
2001-10-28 21:23:44 +00:00
|
|
|
|
2004-12-13 02:58:05 +00:00
|
|
|
/// This class provides the core functionality of linking in LLVM. It retains a
|
2005-04-21 20:19:05 +00:00
|
|
|
/// 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
|
2004-12-13 02:58:05 +00:00
|
|
|
/// to the caller and the Linker object is only suitable for destruction.
|
2013-03-19 15:26:24 +00:00
|
|
|
/// The Linker can link Modules from memory. By default, the linker
|
2013-03-08 22:29:44 +00:00
|
|
|
/// 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.
|
2004-12-13 02:58:05 +00:00
|
|
|
/// @brief The LLVM Linker.
|
|
|
|
class Linker {
|
|
|
|
|
|
|
|
/// @name Types
|
|
|
|
/// @{
|
|
|
|
public:
|
2011-10-11 00:24:54 +00:00
|
|
|
enum LinkerMode {
|
|
|
|
DestroySource = 0, // Allow source module to be destroyed.
|
|
|
|
PreserveSource = 1 // Preserve the source module.
|
|
|
|
};
|
2013-03-08 22:29:44 +00:00
|
|
|
|
2004-12-13 02:58:05 +00:00
|
|
|
/// @}
|
|
|
|
/// @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
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker(StringRef progname, ///< name of tool running linker
|
|
|
|
StringRef modulename, ///< name of linker's end-result module
|
2009-08-23 22:45:37 +00:00
|
|
|
LLVMContext &C, ///< Context for global info
|
|
|
|
unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
|
2005-12-13 20:00:37 +00:00
|
|
|
);
|
2004-12-13 02:58:05 +00:00
|
|
|
|
|
|
|
/// 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
|
2009-11-06 10:58:06 +00:00
|
|
|
Linker(StringRef progname, Module* aModule, unsigned Flags = 0);
|
2004-12-13 02:58:05 +00:00
|
|
|
|
|
|
|
/// Destruct the Linker.
|
|
|
|
/// @brief Destructor
|
|
|
|
~Linker();
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// This method gets the composite module into which linking is being
|
2005-04-21 20:19:05 +00:00
|
|
|
/// done. The Composite module starts out empty and accumulates modules
|
2004-12-13 02:58:05 +00:00
|
|
|
/// linked into it via the various LinkIn* methods. This method does not
|
|
|
|
/// release the Module to the caller. The Linker retains ownership and will
|
2005-04-21 20:19:05 +00:00
|
|
|
/// destruct the Module when the Linker is destructed.
|
2004-12-13 02:58:05 +00:00
|
|
|
/// @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
|
2013-03-08 22:29:44 +00:00
|
|
|
/// by calling LinkModules.
|
2004-12-13 02:58:05 +00:00
|
|
|
/// @see LinkModules
|
|
|
|
/// @returns True if an error occurs, false otherwise.
|
|
|
|
/// @brief Link in a module.
|
|
|
|
bool LinkInModule(
|
2006-11-11 11:54:25 +00:00
|
|
|
Module* Src, ///< Module linked into \p Dest
|
|
|
|
std::string* ErrorMsg = 0 /// Error/diagnostic string
|
2013-03-08 22:29:44 +00:00
|
|
|
) {
|
|
|
|
return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg);
|
2006-11-11 19:59:25 +00:00
|
|
|
}
|
2004-12-13 02:58:05 +00:00
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// This is the heart of the linker. This method will take unconditional
|
2004-12-13 02:58:05 +00:00
|
|
|
/// 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
|
2005-04-21 20:19:05 +00:00
|
|
|
/// the \p Dest module will remain. The \p Src module is linked into the
|
2004-12-13 02:58:05 +00:00
|
|
|
/// 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.
|
2011-10-11 00:24:54 +00:00
|
|
|
static bool LinkModules(Module* Dest, Module* Src, unsigned Mode,
|
|
|
|
std::string* ErrorMsg);
|
2004-12-13 02:58:05 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Implementation
|
|
|
|
/// @{
|
|
|
|
private:
|
|
|
|
/// @}
|
|
|
|
/// @name Data
|
|
|
|
/// @{
|
|
|
|
private:
|
2009-07-01 23:13:44 +00:00
|
|
|
LLVMContext& Context; ///< The context for global information
|
2004-12-13 02:58:05 +00:00
|
|
|
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
|
|
|
|
/// @}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-12-13 02:58:05 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-10-13 16:57:49 +00:00
|
|
|
#endif
|