Linker.h revision 6f75755c9204b1d8817ae5a65a2f7e5af0ec3f70
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;
21
22class Target;
23class TargetLDBackend;
24
25class IRBuilder;
26class ObjectLinker;
27
28class FileHandle;
29class MemoryArea;
30
31/** \class Linker
32*  \brief Linker is a modular linker.
33*/
34class Linker
35{
36public:
37  Linker();
38
39  ~Linker();
40
41  /// config - To set up target-dependent options in pConfig.
42  bool config(LinkerConfig& pConfig);
43
44  /// resolve - To read participatory input files and build up mcld::Module
45  bool resolve(Module& pModule, IRBuilder& pBuilder);
46
47  /// layout - To serialize the final result of the output mcld::Module
48  bool layout();
49
50  /// link - A convenient way to resolve and to layout the output mcld::Module.
51  bool link(Module& pModule, IRBuilder& pBuilder);
52
53  /// emit - To emit output mcld::Module to a output MemoryArea
54  bool emit(MemoryArea& pOutput);
55
56  /// emit - To open a file for output in pPath and to emit output mcld::Module
57  /// to the file.
58  bool emit(const std::string& pPath);
59
60  /// emit - To emit output mcld::Module in the pFileDescriptor.
61  bool emit(int pFileDescriptor);
62
63  bool reset();
64
65private:
66  bool initTarget();
67
68  bool initBackend();
69
70  bool initEmulator();
71
72  bool initOStream();
73
74private:
75  LinkerConfig* m_pConfig;
76  IRBuilder* m_pIRBuilder;
77
78  const Target* m_pTarget;
79  TargetLDBackend* m_pBackend;
80  ObjectLinker* m_pObjLinker;
81};
82
83} // namespace of MC Linker
84
85#endif
86
87