Skip to content
Snippets Groups Projects
Commit a8023c1c authored by Rafael Espindola's avatar Rafael Espindola
Browse files

Last batch of cleanups to Linker.h.

Update comments, fix * placement, fix method names that are not
used in clang, add a linkInModule that takes a Mode and put it
in Linker.cpp.

llvm-svn: 181099
parent 0229acaa
No related branches found
No related tags found
No related merge requests found
...@@ -15,98 +15,38 @@ ...@@ -15,98 +15,38 @@
namespace llvm { namespace llvm {
class Module; class Module;
class LLVMContext;
class StringRef; class StringRef;
/// This class provides the core functionality of linking in LLVM. It retains a /// This class provides the core functionality of linking in LLVM. It keeps a
/// Module object which is the composite of the modules and libraries linked /// pointer to the merged module so far. It doesn't take ownership of the
/// into it. The composite Module can be retrieved via the getModule() method. /// module since it is assumed that the user of this class will want to do
/// In this case the Linker still retains ownership of the Module. If the /// something with it after the linking.
/// 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.
class Linker { class Linker {
/// @name Types
/// @{
public: public:
enum LinkerMode { enum LinkerMode {
DestroySource = 0, // Allow source module to be destroyed. DestroySource = 0, // Allow source module to be destroyed.
PreserveSource = 1 // Preserve the source module. PreserveSource = 1 // Preserve the source module.
}; };
/// @} Linker(Module *M);
/// @name Constructors
/// @{
public:
/// 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(Module* aModule);
/// Destruct the Linker.
/// @brief Destructor
~Linker(); ~Linker();
Module *getModule() const { return Composite; }
/// @}
/// @name Accessors /// \brief Link \p Src into the composite. The source is destroyed if
/// @{ /// \p Mode is DestroySource and preserved if it is PreserveSource.
public: /// If \p ErrorMsg is not null, information about any error is written
/// This method gets the composite module into which linking is being /// to it.
/// done. The Composite module starts out empty and accumulates modules /// Returns true on error.
/// linked into it via the various LinkIn* methods. This method does not bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);
/// release the Module to the caller. The Linker retains ownership and will bool linkInModule(Module *Src, std::string *ErrorMsg) {
/// destruct the Module when the Linker is destructed. return linkInModule(Src, Linker::DestroySource, ErrorMsg);
/// @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);
} }
/// This is the heart of the linker. This method will take unconditional static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
/// control of the \p Src module and link it into the \p Dest module. The std::string *ErrorMsg);
/// \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);
/// @}
/// @name Implementation
/// @{
private: private:
/// @} Module *Composite;
/// @name Data
/// @{
private:
Module* Composite; ///< The composite module linked together
/// @}
}; };
} // End llvm namespace } // End llvm namespace
......
...@@ -24,3 +24,7 @@ Linker::Linker(Module* aModule) : ...@@ -24,3 +24,7 @@ Linker::Linker(Module* aModule) :
Linker::~Linker() { Linker::~Linker() {
} }
bool Linker::linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg) {
return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg);
}
...@@ -89,7 +89,7 @@ LTOCodeGenerator::~LTOCodeGenerator() { ...@@ -89,7 +89,7 @@ LTOCodeGenerator::~LTOCodeGenerator() {
} }
bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {
bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg); bool ret = _linker.linkInModule(mod->getLLVVMModule(), &errMsg);
const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs(); const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
for (int i = 0, e = undefs.size(); i != e; ++i) for (int i = 0, e = undefs.size(); i != e; ++i)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment