summaryrefslogtreecommitdiff
path: root/include/mcld/CodeGen/SectLinker.h
blob: cbc721473af66ee23913da35de5a7c4f1825d87e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//===- SectLinker.h -------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//SectLinker is a base class inherited by target specific linker.
//This class primarily handles common functionality used by all linkers.
//
//===----------------------------------------------------------------------===//

#ifndef SECTION_LINKER_H
#define SECTION_LINKER_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif
#include <llvm/CodeGen/MachineFunctionPass.h>
#include <mcld/Support/PositionDependentOption.h>
#include <vector>

namespace llvm
{
  class Module;
  class MachineFunction;
} // namespace of llvm

namespace mcld
{
  class MCLDFile;
  class MCLDDriver;
  class TargetLDBackend;
  class AttributeFactory;
  class SectLinkerOption;

  /** \class SectLinker
   *  \brief SectLinker provides a linking pass for standard compilation flow
   *
   *  SectLinker is responded for
   *  - provide an interface for target-specific SectLinekr
   *  - set up environment for MCLDDriver
   *  - control AsmPrinter, make sure AsmPrinter has already prepared
   *    all MCSectionDatas for linking
   *
   *  SectLinker resolves the absolue paths of input arguments.
   *
   *  @see MachineFunctionPass MCLDDriver
   */
  class SectLinker : public llvm::MachineFunctionPass
  {
  protected:
    // Constructor. Although SectLinker has only two arguments,
    // TargetSectLinker should handle
    // - enabled attributes
    // - the default attribute
    // - the default link script
    // - the standard symbols
    SectLinker(SectLinkerOption &pOption,
               TargetLDBackend &pLDBackend);

  public:
    virtual ~SectLinker();

    /// addTargetOptions - target SectLinker can hook this function to add
    /// target-specific inputs
    virtual void addTargetOptions(llvm::Module &pM,
                                  SectLinkerOption &pOption)
    { }

    /// doInitialization - Read all parameters and set up the AsmPrinter.
    /// If your pass overrides this, it must make sure to explicitly call
    /// this implementation.
    virtual bool doInitialization(llvm::Module &pM);

    /// doFinalization - Shut down the AsmPrinter, and do really linking.
    /// If you override this in your pass, you must make sure to call it
    /// explicitly.
    virtual bool doFinalization(llvm::Module &pM);

    /// runOnMachineFunction
    /// redirect to AsmPrinter
    virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn);

  protected:
    void initializeInputTree(const PositionDependentOptions &pOptions) const;

    AttributeFactory* attrFactory()
    { return m_pAttrFactory; }

  private:
    SectLinkerOption *m_pOption;

  protected:
    TargetLDBackend *m_pLDBackend;
    MCLDDriver *m_pLDDriver;
    AttributeFactory *m_pAttrFactory;

  private:
    static char m_ID;
  };

} // namespace of MC Linker

#endif