a7a07812c389778591bc49e1e978e58d8570608e
[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 
26 /// \p Dest module. If an error occurs, true is returned, otherwise false. If
27 /// \p 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.
29 /// @returns true if there's an error
30 /// @brief Link two modules together
31 bool LinkModules(
32   Module* Dest,          ///< Module into which \p Src is linked
33   const Module* Src,     ///< Module linked into \p Dest
34   std::string* ErrorMsg  ///< Optional error message string
35 );
36
37 /// This function links the bytecode \p Files into the \p HeadModule. No 
38 /// matching of symbols is done. It simply calls loads each module and calls
39 /// LinkModules for each one.
40 /// @returns true if an error occurs, false otherwise
41 bool LinkFiles (
42   const char * progname, ///< Name of the program being linked (for output)
43   Module * HeadModule,   ///< Main (resulting) module to be linked into
44   const std::vector<std::string> & Files, ///< Files to link in
45   bool Verbose ///< Link verbosely, indicating each action
46 );
47
48 /// This function links one archive, \p Filename,  that contains bytecode into
49 /// \p HeadModule.  If an error occurs, true is returned, otherwise false. If
50 /// \p ErrorMsg is not null and an error occurs, \p *ErrorMsg will be set to a
51 /// readable string that indicates the nature of the error.
52 /// @returns true if there's an error
53 /// @brief Link in one archive.
54 bool LinkInArchive( 
55   Module* HeadModule,          ///< Main (resulting) module to be linked into
56   const std::string& Filename, ///< Filename of the archive to link
57   std::string* ErrorMsg,       ///< Error message if an error occurs.
58   bool Verbose                 ///< Link verbosely, indicating each action
59 );
60
61 /// This function provides the ability to handle the -L and -l options on a 
62 /// linker's command line. It will link into \p HeadModule any modules found in
63 /// the \p Libraries (which might be found in the \p LibPaths). 
64 /// @brief Link libraries into a module
65 void LinkLibraries (
66   const char * progname,   ///< Name of the program being linked (for output)
67   Module* HeadModule,      ///< Main (resulting) module to be linked into
68   const std::vector<std::string> & Libraries, ///< Set of libraries to link in
69   const std::vector<std::string> & LibPaths,  ///< Set of library paths
70   bool Verbose, ///< Link verbosely, indicating each action
71   bool Native ///< Linking is for a native executable
72 );
73
74 /// This function looks at Module \p M and returns a set of strings, 
75 /// \p DefinedSymbols, that is the publicly visible defined symbols in 
76 /// module \p M.
77 void GetAllDefinedSymbols (Module *M, std::set<std::string> &DefinedSymbols);
78
79 /// This function looks at Module \p M and returns a set of strings, 
80 /// \p UnefinedSymbols, that is the publicly visible undefined symbols in 
81 /// module \p M.
82 void GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols);
83
84 /// This function looks through a set of \p Paths to find a library with the
85 /// name \p Filename. If \p SharedObjectOnly is true, it only finds a match
86 /// if the file is a shared library.
87 std::string FindLib(const std::string &Filename,
88                     const std::vector<std::string> &Paths,
89                     bool SharedObjectOnly = false);
90   
91 } // End llvm namespace
92
93 #endif