blob: b3adf98514759474ee66d6db48829ea5e5db7387 [file] [log] [blame]
Shih-wei Liao22add6f2012-12-15 17:21:00 -08001//===- 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//===----------------------------------------------------------------------===//
Stephen Hines37b74a32014-11-26 18:48:20 -08009#ifndef MCLD_LD_STUBFACTORY_H_
10#define MCLD_LD_STUBFACTORY_H_
Shih-wei Liao22add6f2012-12-15 17:21:00 -080011
12#include <llvm/Support/DataTypes.h>
Stephen Hines37b74a32014-11-26 18:48:20 -080013
Shih-wei Liao22add6f2012-12-15 17:21:00 -080014#include <vector>
15
Shih-wei Liaod0fbbb22013-01-03 06:23:31 -080016namespace mcld {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080017
Shih-wei Liao22add6f2012-12-15 17:21:00 -080018class BranchIslandFactory;
Stephen Hines6f757552013-03-04 19:51:03 -080019class IRBuilder;
Stephen Hinescfcb2242016-03-08 00:18:09 -080020class FragmentRef;
Stephen Hines37b74a32014-11-26 18:48:20 -080021class Relocation;
22class Stub;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080023
24/** \class StubFactory
25 * \brief the clone factory of Stub
26 *
27 */
Stephen Hines37b74a32014-11-26 18:48:20 -080028class StubFactory {
29 public:
Shih-wei Liao22add6f2012-12-15 17:21:00 -080030 ~StubFactory();
31
32 /// addPrototype - register a stub prototype
33 void addPrototype(Stub* pPrototype);
34
35 /// create - create a stub if needed, otherwise return NULL
36 Stub* create(Relocation& pReloc,
37 uint64_t pTargetSymValue,
Stephen Hines6f757552013-03-04 19:51:03 -080038 IRBuilder& pBuilder,
Shih-wei Liao22add6f2012-12-15 17:21:00 -080039 BranchIslandFactory& pBRIslandFactory);
40
Stephen Hinescfcb2242016-03-08 00:18:09 -080041 Stub* create(FragmentRef& pFragRef,
42 IRBuilder& pBuilder,
43 BranchIslandFactory& pBRIslandFactory);
44
Stephen Hines37b74a32014-11-26 18:48:20 -080045 private:
Shih-wei Liao22add6f2012-12-15 17:21:00 -080046 /// findPrototype - find if there is a registered stub prototype for the given
47 /// relocation
48 Stub* findPrototype(const Relocation& pReloc,
49 const uint64_t pSource,
Stephen Hinescfcb2242016-03-08 00:18:09 -080050 uint64_t pTargetSymValue) const;
51
52 Stub* findPrototype(const FragmentRef& pFragRef) const;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080053
Stephen Hines37b74a32014-11-26 18:48:20 -080054 private:
55 typedef std::vector<Stub*> StubPoolType;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080056
Stephen Hines37b74a32014-11-26 18:48:20 -080057 private:
58 StubPoolType m_StubPool; // stub pool
Shih-wei Liao22add6f2012-12-15 17:21:00 -080059};
60
Stephen Hines37b74a32014-11-26 18:48:20 -080061} // namespace mcld
Shih-wei Liao22add6f2012-12-15 17:21:00 -080062
Stephen Hines37b74a32014-11-26 18:48:20 -080063#endif // MCLD_LD_STUBFACTORY_H_