+ /// This method returns an error string suitable for printing to the user.
+ /// The return value will be empty unless an error occurred in one of the
+ /// LinkIn* methods. In those cases, the LinkIn* methods will have returned
+ /// 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 stderr.
+ /// @brief Get the text of the last error that occurred.
+ const std::string &getLastError() const { return Error; }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ /// Add a path to the list of paths that the Linker will search. The Linker
+ /// accumulates the set of libraries added
+ /// library paths for the target platform. The standard libraries will
+ /// always be searched last. The added libraries will be searched in the
+ /// order added.
+ /// @brief Add a path.
+ void addPath(const sys::Path& path);
+
+ /// Add a set of paths to the list of paths that the linker will search. The
+ /// Linker accumulates the set of libraries added. The \p paths will be
+ /// added to the end of the Linker's list. Order will be retained.
+ /// @brief Add a set of paths.
+ void addPaths(const std::vector<std::string>& paths);
+
+ /// This method augments the Linker's list of library paths with the system
+ /// paths of the host operating system, include LLVM_LIB_SEARCH_PATH.
+ /// @brief Add the system paths.
+ void addSystemPaths();
+
+ /// Control optional linker behavior by setting a group of flags. The flags
+ /// are defined in the ControlFlags enumeration.
+ /// @see ControlFlags
+ /// @brief Set control flags.
+ void setFlags(unsigned flags) { Flags = flags; }
+
+ /// This method links the \p Src module into the Linker's Composite module
+ /// by calling LinkModules. All the other LinkIn* methods eventually
+ /// result in calling this method to link a Module into the Linker's
+ /// composite.
+ /// @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
+ /// 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);
+
+ /// @}
+ /// @name Implementation
+ /// @{
+ private:
+ bool warning(StringRef message);
+ bool error(StringRef message);
+ void verbose(StringRef message);
+
+ /// @}
+ /// @name Data
+ /// @{
+ private:
+ 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.
+ std::string Error; ///< Text of error that occurred.
+ std::string ProgramName; ///< Name of the program being linked
+ /// @}
+
+};
+
+} // End llvm namespace
+
+#endif