Linker.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
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
17namespace mcld {
18
19class Module;
20class LinkerConfig;
21class LinkerScript;
22
23class Target;
24class TargetLDBackend;
25
26class IRBuilder;
27class ObjectLinker;
28
29class FileHandle;
30class FileOutputBuffer;
31
32/** \class Linker
33*  \brief Linker is a modular linker.
34*/
35class Linker
36{
37public:
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(Module& pModule);
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 FileOutputBuffer.
58  bool emit(FileOutputBuffer& 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 Module& pModule, const std::string& pPath);
63
64  /// emit - To emit output mcld::Module in the pFileDescriptor.
65  bool emit(const Module& pModule, int pFileDescriptor);
66
67  bool reset();
68
69private:
70  bool initTarget();
71
72  bool initBackend();
73
74  bool initOStream();
75
76  bool initEmulator(LinkerScript& pScript);
77
78private:
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