X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FLinker.h;h=4f37459eb403f38a8f85a82b0844fbaa799f32e2;hb=5e47632b8fa1a98283c09ca88cf09600862e4849;hp=4bb69ae419e061c9ab80a999b512e3857f17531e;hpb=456b97297c62593db98decb78054e40622200ec2;p=oota-llvm.git diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 4bb69ae419e..4f37459eb40 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -1,95 +1,59 @@ //===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// +// The LLVM Compiler Infrastructure // -// This file defines the interface to the module/file/archive linker. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLVM_LINKER_H #define LLVM_LINKER_H +#include "llvm/ADT/SmallPtrSet.h" #include -#include -#include namespace llvm { class Module; +class StringRef; +class StructType; + +/// 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 { + public: + enum LinkerMode { + DestroySource = 0, // Allow source module to be destroyed. + PreserveSource = 1 // Preserve the source module. + }; + + Linker(Module *M); + ~Linker(); + + Module *getModule() const { return Composite; } + void deleteModule(); + + /// \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); + } + + static bool LinkModules(Module *Dest, Module *Src, unsigned Mode, + std::string *ErrorMsg); + + private: + Module *Composite; + SmallPtrSet IdentifiedStructTypes; +}; -/// This is the heart of the linker. The \p Src module is linked into the \p -/// Dest module. If an error occurs, true is returned, otherwise false. If \p -/// ErrorMsg is not null and an error occurs, \p *ErrorMsg will be set to a -/// readable string that indicates the nature of the error. Note that this can -/// destroy the Src module in arbitrary ways. -/// -/// @returns true if there's an error -/// @brief Link two modules together -bool LinkModules( - Module* Dest, ///< Module into which \p Src is linked - Module* Src, ///< Module linked into \p Dest - std::string* ErrorMsg ///< Optional error message string -); - -/// This function links the bytecode \p Files into the \p HeadModule. No -/// matching of symbols is done. It simply calls loads each module and calls -/// LinkModules for each one. -/// @returns true if an error occurs, false otherwise -bool LinkFiles ( - const char * progname, ///< Name of the program being linked (for output) - Module * HeadModule, ///< Main (resulting) module to be linked into - const std::vector & Files, ///< Files to link in - bool Verbose ///< Link verbosely, indicating each action -); - -/// This function links one archive, \p Filename, that contains bytecode into -/// \p HeadModule. If an error occurs, true is returned, otherwise false. If -/// \p ErrorMsg is not null and an error occurs, \p *ErrorMsg will be set to a -/// readable string that indicates the nature of the error. -/// @returns true if there's an error -/// @brief Link in one archive. -bool LinkInArchive( - Module* HeadModule, ///< Main (resulting) module to be linked into - const std::string& Filename, ///< Filename of the archive to link - std::string* ErrorMsg, ///< Error message if an error occurs. - bool Verbose ///< Link verbosely, indicating each action -); - -/// This function provides the ability to handle the -L and -l options on a -/// linker's command line. It will link into \p HeadModule any modules found in -/// the \p Libraries (which might be found in the \p LibPaths). -/// @brief Link libraries into a module -void LinkLibraries ( - const char * progname, ///< Name of the program being linked (for output) - Module* HeadModule, ///< Main (resulting) module to be linked into - const std::vector & Libraries, ///< Set of libraries to link in - const std::vector & LibPaths, ///< Set of library paths - bool Verbose, ///< Link verbosely, indicating each action - bool Native ///< Linking is for a native executable -); - -/// This function looks at Module \p M and returns a set of strings, -/// \p DefinedSymbols, that is the publicly visible defined symbols in -/// module \p M. -void GetAllDefinedSymbols (Module *M, std::set &DefinedSymbols); - -/// This function looks at Module \p M and returns a set of strings, -/// \p UnefinedSymbols, that is the publicly visible undefined symbols in -/// module \p M. -void GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols); - -/// This function looks through a set of \p Paths to find a library with the -/// name \p Filename. If \p SharedObjectOnly is true, it only finds a match -/// if the file is a shared library. -std::string FindLib(const std::string &Filename, - const std::vector &Paths, - bool SharedObjectOnly = false); - } // End llvm namespace #endif