StubFactory.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
1//===- StubFactory.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 MCLD_LD_STUB_FACTORY_H
11#define MCLD_LD_STUB_FACTORY_H
12#ifdef ENABLE_UNITTEST
13#include <gtest.h>
14#endif
15
16#include <llvm/Support/DataTypes.h>
17#include <vector>
18
19namespace mcld
20{
21
22class Stub;
23class Relocation;
24class RelocationFactory;
25class BranchIslandFactory;
26class FragmentLinker;
27
28/** \class StubFactory
29 *  \brief the clone factory of Stub
30 *
31 */
32class StubFactory
33{
34public:
35  StubFactory();
36
37  ~StubFactory();
38
39  /// addPrototype - register a stub prototype
40  void addPrototype(Stub* pPrototype);
41
42  /// create - create a stub if needed, otherwise return NULL
43  Stub* create(Relocation& pReloc,
44               uint64_t pTargetSymValue,
45               FragmentLinker& pLinker,
46               RelocationFactory& pRelocFactory,
47               BranchIslandFactory& pBRIslandFactory);
48
49private:
50  /// findPrototype - find if there is a registered stub prototype for the given
51  ///                 relocation
52  Stub* findPrototype(const Relocation& pReloc,
53                      const uint64_t pSource,
54                      uint64_t pTargetSymValue);
55
56private:
57 typedef std::vector<Stub*> StubPoolType;
58
59private:
60  StubPoolType m_StubPool; // stub pool
61};
62
63} // namespace of mcld
64
65#endif
66