MCLinker.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
1//===- MCLinker.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// MCLinker is a base class inherited by target specific linker.
11// This class primarily handles common functionality used by all linkers.
12//
13//===----------------------------------------------------------------------===//
14#ifndef MCLD_CODEGEN_MCLINKER_H
15#define MCLD_CODEGEN_MCLINKER_H
16#ifdef ENABLE_UNITTEST
17#include <gtest.h>
18#endif
19#include <llvm/CodeGen/MachineFunctionPass.h>
20
21namespace llvm {
22
23class Module;
24class MachineFunction;
25
26} // namespace of llvm
27
28namespace mcld {
29
30class Module;
31class IRBuilder;
32class LinkerConfig;
33class Linker;
34class FileHandle;
35
36/** \class MCLinker
37*  \brief MCLinker provides a linking pass for standard compilation flow
38*
39*  MCLinker is responded for
40*  - provide an interface for target-specific linker
41*  - set up environment for ObjectLinker
42*  - perform linking
43*
44*  @see MachineFunctionPass ObjectLinker
45*/
46class MCLinker : public llvm::MachineFunctionPass
47{
48protected:
49  // Constructor. Although MCLinker has only two arguments,
50  // TargetMCLinker should handle
51  // - enabled attributes
52  // - the default attribute
53  // - the default link script
54  // - the standard symbols
55  MCLinker(LinkerConfig& pConfig,
56           mcld::Module& pModule,
57           FileHandle& pFileHandle);
58
59public:
60  virtual ~MCLinker();
61
62  virtual bool doInitialization(llvm::Module &pM);
63
64  virtual bool doFinalization(llvm::Module &pM);
65
66  virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn);
67
68protected:
69  void initializeInputTree(IRBuilder& pBuilder);
70
71protected:
72  LinkerConfig& m_Config;
73  mcld::Module& m_Module;
74  FileHandle& m_FileHandle;
75  IRBuilder* m_pBuilder;
76  Linker* m_pLinker;
77
78private:
79  static char m_ID;
80};
81
82} // namespace of MC Linker
83
84#endif
85
86