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
10#ifndef ALONE_LINKER_H
11#define ALONE_LINKER_H
12
13#include <string>
14
15namespace mcld {
16
17class Module;
18class IRBuilder;
19class LinkerConfig;
20class Linker;
21class Input;
22class MemoryArea;
23
24namespace sys { namespace fs {
25
26class Path;
27
28} } // end namespace sys::fs
29
30} // end namespace mcld
31
32namespace alone {
33
34class LinkerConfig;
35
36class Linker {
37public:
38  enum ErrorCode {
39    kSuccess,
40    kDoubleConfig,
41    kDelegateLDInfo,
42    kFindNameSpec,
43    kOpenObjectFile,
44    kOpenMemory,
45    kNotConfig,
46    kNotSetUpOutput,
47    kOpenOutput,
48    kReadSections,
49    kReadSymbols,
50    kAddAdditionalSymbols,
51    kMaxErrorCode
52  };
53
54  static const char *GetErrorString(enum ErrorCode pErrCode);
55
56private:
57  const mcld::LinkerConfig *mLDConfig;
58  mcld::Module *mModule;
59  mcld::Linker *mLinker;
60  mcld::IRBuilder *mBuilder;
61  std::string mSOName;
62  std::string mOutputPath;
63  int mOutputHandler;
64
65public:
66  Linker();
67
68  Linker(const LinkerConfig& pConfig);
69
70  ~Linker();
71
72  enum ErrorCode config(const LinkerConfig& pConfig);
73
74  enum ErrorCode addNameSpec(const std::string &pNameSpec);
75
76  enum ErrorCode addObject(const std::string &pObjectPath);
77
78  enum ErrorCode addObject(void* pMemory, size_t pSize);
79
80  enum ErrorCode addCode(void* pMemory, size_t pSize);
81
82  enum ErrorCode setOutput(const std::string &pPath);
83
84  enum ErrorCode setOutput(int pFileHandler);
85
86  enum ErrorCode link();
87
88private:
89  enum ErrorCode extractFiles(const LinkerConfig& pConfig);
90};
91
92} // end namespace alone
93
94#endif // ALONE_LINKER_H
95