1//===- SectLinker.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//SectLinker 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_SECTION_LINKER_H
15#define MCLD_SECTION_LINKER_H
16#ifdef ENABLE_UNITTEST
17#include <gtest.h>
18#endif
19#include <llvm/CodeGen/MachineFunctionPass.h>
20#include <mcld/Support/PositionDependentOption.h>
21#include <vector>
22
23namespace llvm
24{
25class Module;
26class MachineFunction;
27} // namespace of llvm
28
29namespace mcld
30{
31class MCLDInfo;
32class MCLDFile;
33class MCLDDriver;
34class TargetLDBackend;
35class AttributeFactory;
36class SectLinkerOption;
37class MemoryAreaFactory;
38
39/** \class SectLinker
40*  \brief SectLinker provides a linking pass for standard compilation flow
41*
42*  SectLinker is responded for
43*  - provide an interface for target-specific SectLinekr
44*  - set up environment for MCLDDriver
45*  - control AsmPrinter, make sure AsmPrinter has already prepared
46*    all SectionDatas for linking
47*
48*  SectLinker resolves the absolue paths of input arguments.
49*
50*  @see MachineFunctionPass MCLDDriver
51*/
52class SectLinker : public llvm::MachineFunctionPass
53{
54protected:
55  // Constructor. Although SectLinker has only two arguments,
56  // TargetSectLinker should handle
57  // - enabled attributes
58  // - the default attribute
59  // - the default link script
60  // - the standard symbols
61  SectLinker(SectLinkerOption &pOption,
62             TargetLDBackend &pLDBackend);
63
64public:
65  virtual ~SectLinker();
66
67  /// doInitialization - Read all parameters and set up the AsmPrinter.
68  /// If your pass overrides this, it must make sure to explicitly call
69  /// this implementation.
70  virtual bool doInitialization(llvm::Module &pM);
71
72  /// doFinalization - Shut down the AsmPrinter, and do really linking.
73  /// If you override this in your pass, you must make sure to call it
74  /// explicitly.
75  virtual bool doFinalization(llvm::Module &pM);
76
77  /// runOnMachineFunction
78  /// redirect to AsmPrinter
79  virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn);
80
81protected:
82  void initializeInputTree(const PositionDependentOptions &pOptions) const;
83
84  void initializeInputOutput(MCLDInfo& pLDInfo);
85
86  MemoryAreaFactory* memAreaFactory()
87  { return m_pMemAreaFactory; }
88
89private:
90  SectLinkerOption *m_pOption;
91
92protected:
93  TargetLDBackend *m_pLDBackend;
94  MCLDDriver *m_pLDDriver;
95  MemoryAreaFactory *m_pMemAreaFactory;
96
97private:
98  static char m_ID;
99};
100
101} // namespace of MC Linker
102
103#endif
104
105