llvm.org GIT mirror llvm / fca8863
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181099 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
3 changed file(s) with 23 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
1414 namespace llvm {
1515
1616 class Module;
17 class LLVMContext;
1817 class StringRef;
1918
20 /// This class provides the core functionality of linking in LLVM. It retains a
21 /// Module object which is the composite of the modules and libraries linked
22 /// into it. The composite Module can be retrieved via the getModule() method.
23 /// In this case the Linker still retains ownership of the Module. If the
24 /// releaseModule() method is used, the ownership of the Module is transferred
25 /// to the caller and the Linker object is only suitable for destruction.
26 /// The Linker can link Modules from memory. By default, the linker
27 /// will generate error and warning messages to stderr but this capability can
28 /// be turned off with the QuietWarnings and QuietErrors flags. It can also be
29 /// instructed to verbosely print out the linking actions it is taking with
30 /// the Verbose flag.
31 /// @brief The LLVM Linker.
19 /// This class provides the core functionality of linking in LLVM. It keeps a
20 /// pointer to the merged module so far. It doesn't take ownership of the
21 /// module since it is assumed that the user of this class will want to do
22 /// something with it after the linking.
3223 class Linker {
33
34 /// @name Types
35 /// @{
3624 public:
3725 enum LinkerMode {
3826 DestroySource = 0, // Allow source module to be destroyed.
3927 PreserveSource = 1 // Preserve the source module.
4028 };
4129
42 /// @}
43 /// @name Constructors
44 /// @{
45 public:
46 /// Construct the Linker with a previously defined module, \p aModule. Use
47 /// \p progname for the name of the program in error messages.
48 /// @brief Construct with existing module
49 Linker(Module* aModule);
30 Linker(Module *M);
31 ~Linker();
32 Module *getModule() const { return Composite; }
5033
51 /// Destruct the Linker.
52 /// @brief Destructor
53 ~Linker();
54
55 /// @}
56 /// @name Accessors
57 /// @{
58 public:
59 /// This method gets the composite module into which linking is being
60 /// done. The Composite module starts out empty and accumulates modules
61 /// linked into it via the various LinkIn* methods. This method does not
62 /// release the Module to the caller. The Linker retains ownership and will
63 /// destruct the Module when the Linker is destructed.
64 /// @see releaseModule
65 /// @brief Get the linked/composite module.
66 Module* getModule() const { return Composite; }
67
68 /// @}
69 /// @name Mutators
70 /// @{
71 public:
72 /// This method links the \p Src module into the Linker's Composite module
73 /// by calling LinkModules.
74 /// @see LinkModules
75 /// @returns True if an error occurs, false otherwise.
76 /// @brief Link in a module.
77 bool LinkInModule(
78 Module* Src, ///< Module linked into \p Dest
79 std::string* ErrorMsg = 0 /// Error/diagnostic string
80 ) {
81 return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg);
34 /// \brief Link \p Src into the composite. The source is destroyed if
35 /// \p Mode is DestroySource and preserved if it is PreserveSource.
36 /// If \p ErrorMsg is not null, information about any error is written
37 /// to it.
38 /// Returns true on error.
39 bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);
40 bool linkInModule(Module *Src, std::string *ErrorMsg) {
41 return linkInModule(Src, Linker::DestroySource, ErrorMsg);
8242 }
8343
84 /// This is the heart of the linker. This method will take unconditional
85 /// control of the \p Src module and link it into the \p Dest module. The
86 /// \p Src module will be destructed or subsumed by this method. In either
87 /// case it is not usable by the caller after this method is invoked. Only
88 /// the \p Dest module will remain. The \p Src module is linked into the
89 /// Linker's composite module such that types, global variables, functions,
90 /// and etc. are matched and resolved. If an error occurs, this function
91 /// returns true and ErrorMsg is set to a descriptive message about the
92 /// error.
93 /// @returns True if an error occurs, false otherwise.
94 /// @brief Generically link two modules together.
95 static bool LinkModules(Module* Dest, Module* Src, unsigned Mode,
96 std::string* ErrorMsg);
44 static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,
45 std::string *ErrorMsg);
9746
98 /// @}
99 /// @name Implementation
100 /// @{
10147 private:
102 /// @}
103 /// @name Data
104 /// @{
105 private:
106 Module* Composite; ///< The composite module linked together
107 /// @}
108
48 Module *Composite;
10949 };
11050
11151 } // End llvm namespace
2323
2424 Linker::~Linker() {
2525 }
26
27 bool Linker::linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg) {
28 return LinkModules(Composite, Src, Linker::DestroySource, ErrorMsg);
29 }
8888 }
8989
9090 bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {
91 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
91 bool ret = _linker.linkInModule(mod->getLLVVMModule(), &errMsg);
9292
9393 const std::vector &undefs = mod->getAsmUndefinedRefs();
9494 for (int i = 0, e = undefs.size(); i != e; ++i)