1 //===- Linker.h -----------------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef MCLD_LINKER_H_
10 #define MCLD_LINKER_H_
11 
12 #include <string>
13 
14 namespace mcld {
15 
16 class FileHandle;
17 class FileOutputBuffer;
18 class IRBuilder;
19 class LinkerConfig;
20 class LinkerScript;
21 class Module;
22 class ObjectLinker;
23 class Target;
24 class TargetLDBackend;
25 
26 /** \class Linker
27 *  \brief Linker is a modular linker.
28 */
29 class Linker {
30  public:
31   Linker();
32 
33   ~Linker();
34 
35   /// emulate - To set up target-dependent options and default linker script.
36   bool emulate(LinkerScript& pScript, LinkerConfig& pConfig);
37 
38   /// normalize - To normalize the command line language into mcld::Module.
39   bool normalize(Module& pModule, IRBuilder& pBuilder);
40 
41   /// resolve - To build up the topology of mcld::Module.
42   bool resolve(Module& pModule);
43 
44   /// layout - To serialize the final result of the output mcld::Module.
45   bool layout();
46 
47   /// link - A convenient way to resolve and to layout the output mcld::Module.
48   bool link(Module& pModule, IRBuilder& pBuilder);
49 
50   /// emit - To emit output mcld::Module to a FileOutputBuffer.
51   bool emit(FileOutputBuffer& pOutput);
52 
53   /// emit - To open a file for output in pPath and to emit output mcld::Module
54   /// to the file.
55   bool emit(const Module& pModule, const std::string& pPath);
56 
57   /// emit - To emit output mcld::Module in the pFileDescriptor.
58   bool emit(const Module& pModule, int pFileDescriptor);
59 
60   bool reset();
61 
62  private:
63   bool initTarget();
64 
65   bool initBackend();
66 
67   bool initOStream();
68 
69   bool initEmulator(LinkerScript& pScript);
70 
71  private:
72   LinkerConfig* m_pConfig;
73   IRBuilder* m_pIRBuilder;
74 
75   const Target* m_pTarget;
76   TargetLDBackend* m_pBackend;
77   ObjectLinker* m_pObjLinker;
78 };
79 
80 }  // namespace mcld
81 
82 #endif  // MCLD_LINKER_H_
83