• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <string>
16 
17 namespace mcld {
18 
19 class Module;
20 class LinkerConfig;
21 class LinkerScript;
22 
23 class Target;
24 class TargetLDBackend;
25 
26 class IRBuilder;
27 class ObjectLinker;
28 
29 class FileHandle;
30 class MemoryArea;
31 
32 /** \class Linker
33 *  \brief Linker is a modular linker.
34 */
35 class Linker
36 {
37 public:
38   Linker();
39 
40   ~Linker();
41 
42   /// emulate - To set up target-dependent options and default linker script.
43   bool emulate(LinkerScript& pScript, LinkerConfig& pConfig);
44 
45   /// normalize - To normalize the command line language into mcld::Module.
46   bool normalize(Module& pModule, IRBuilder& pBuilder);
47 
48   /// resolve - To build up the topology of mcld::Module.
49   bool resolve();
50 
51   /// layout - To serialize the final result of the output mcld::Module.
52   bool layout();
53 
54   /// link - A convenient way to resolve and to layout the output mcld::Module.
55   bool link(Module& pModule, IRBuilder& pBuilder);
56 
57   /// emit - To emit output mcld::Module to a output MemoryArea
58   bool emit(MemoryArea& pOutput);
59 
60   /// emit - To open a file for output in pPath and to emit output mcld::Module
61   /// to the file.
62   bool emit(const std::string& pPath);
63 
64   /// emit - To emit output mcld::Module in the pFileDescriptor.
65   bool emit(int pFileDescriptor);
66 
67   bool reset();
68 
69 private:
70   bool initTarget();
71 
72   bool initBackend();
73 
74   bool initOStream();
75 
76   bool initEmulator(LinkerScript& pScript);
77 
78 private:
79   LinkerConfig* m_pConfig;
80   IRBuilder* m_pIRBuilder;
81 
82   const Target* m_pTarget;
83   TargetLDBackend* m_pBackend;
84   ObjectLinker* m_pObjLinker;
85 };
86 
87 } // namespace of MC Linker
88 
89 #endif
90 
91