Document this as clobbering the second arg, make the second arg be non-const
[oota-llvm.git] / include / llvm / Linker.h
1 //===- llvm/Linker.h - Module Linker Interface ------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the 
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interface to the module/file/archive linker.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LINKER_H
15 #define LLVM_LINKER_H
16
17 #include <string>
18 #include <vector>
19 #include <set>
20
21 namespace llvm {
22
23 class Module;
24
25 /// This is the heart of the linker. The \p Src module is linked into the \p
26 /// Dest module. If an error occurs, true is returned, otherwise false. If \p
27 /// ErrorMsg is not null and an error occurs, \p *ErrorMsg will be set to a
28 /// readable string that indicates the nature of the error.  Note that this can
29 /// destroy the Src module in arbitrary ways.
30 ///
31 /// @returns true if there's an error
32 /// @brief Link two modules together
33 bool LinkModules(
34   Module* Dest,          ///< Module into which \p Src is linked
35   Module* Src,     ///< Module linked into \p Dest
36   std::string* ErrorMsg  ///< Optional error message string
37 );
38
39 /// This function links the bytecode \p Files into the \p HeadModule. No 
40 /// matching of symbols is done. It simply calls loads each module and calls
41 /// LinkModules for each one.
42 /// @returns true if an error occurs, false otherwise
43 bool LinkFiles (
44   const char * progname, ///< Name of the program being linked (for output)
45   Module * HeadModule,   ///< Main (resulting) module to be linked into
46   const std::vector<std::string> & Files, ///< Files to link in
47   bool Verbose ///< Link verbosely, indicating each action
48 );
49
50 /// This function links one archive, \p Filename,  that contains bytecode into
51 /// \p HeadModule.  If an error occurs, true is returned, otherwise false. If
52 /// \p ErrorMsg is not null and an error occurs, \p *ErrorMsg will be set to a
53 /// readable string that indicates the nature of the error.
54 /// @returns true if there's an error
55 /// @brief Link in one archive.
56 bool LinkInArchive( 
57   Module* HeadModule,          ///< Main (resulting) module to be linked into
58   const std::string& Filename, ///< Filename of the archive to link
59   std::string* ErrorMsg,       ///< Error message if an error occurs.
60   bool Verbose                 ///< Link verbosely, indicating each action
61 );
62
63 /// This function provides the ability to handle the -L and -l options on a 
64 /// linker's command line. It will link into \p HeadModule any modules found in
65 /// the \p Libraries (which might be found in the \p LibPaths). 
66 /// @brief Link libraries into a module
67 void LinkLibraries (
68   const char * progname,   ///< Name of the program being linked (for output)
69   Module* HeadModule,      ///< Main (resulting) module to be linked into
70   const std::vector<std::string> & Libraries, ///< Set of libraries to link in
71   const std::vector<std::string> & LibPaths,  ///< Set of library paths
72   bool Verbose, ///< Link verbosely, indicating each action
73   bool Native ///< Linking is for a native executable
74 );
75
76 /// This function looks at Module \p M and returns a set of strings, 
77 /// \p DefinedSymbols, that is the publicly visible defined symbols in 
78 /// module \p M.
79 void GetAllDefinedSymbols (Module *M, std::set<std::string> &DefinedSymbols);
80
81 /// This function looks at Module \p M and returns a set of strings, 
82 /// \p UnefinedSymbols, that is the publicly visible undefined symbols in 
83 /// module \p M.
84 void GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols);
85
86 /// This function looks through a set of \p Paths to find a library with the
87 /// name \p Filename. If \p SharedObjectOnly is true, it only finds a match
88 /// if the file is a shared library.
89 std::string FindLib(const std::string &Filename,
90                     const std::vector<std::string> &Paths,
91                     bool SharedObjectOnly = false);
92   
93 } // End llvm namespace
94
95 #endif