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_STUBFACTORY_H_ 10 #define MCLD_LD_STUBFACTORY_H_ 11 12 #include <llvm/Support/DataTypes.h> 13 14 #include <vector> 15 16 namespace mcld { 17 18 class BranchIslandFactory; 19 class IRBuilder; 20 class FragmentRef; 21 class Relocation; 22 class Stub; 23 24 /** \class StubFactory 25 * \brief the clone factory of Stub 26 * 27 */ 28 class StubFactory { 29 public: 30 ~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, 38 IRBuilder& pBuilder, 39 BranchIslandFactory& pBRIslandFactory); 40 41 Stub* create(FragmentRef& pFragRef, 42 IRBuilder& pBuilder, 43 BranchIslandFactory& pBRIslandFactory); 44 45 private: 46 /// 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, 50 uint64_t pTargetSymValue) const; 51 52 Stub* findPrototype(const FragmentRef& pFragRef) const; 53 54 private: 55 typedef std::vector<Stub*> StubPoolType; 56 57 private: 58 StubPoolType m_StubPool; // stub pool 59 }; 60 61 } // namespace mcld 62 63 #endif // MCLD_LD_STUBFACTORY_H_ 64