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