1 //===- Relocation.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_RELOCATIONFACTORY_H_
10 #define MCLD_LD_RELOCATIONFACTORY_H_
11 #include "mcld/Config/Config.h"
12 #include "mcld/Fragment/Relocation.h"
13 #include "mcld/Support/GCFactory.h"
14 
15 namespace mcld {
16 
17 class FragmentRef;
18 class LinkerConfig;
19 
20 /** \class RelocationFactory
21  *  \brief RelocationFactory provides the interface for generating target
22  *  relocation
23  *
24  */
25 class RelocationFactory
26     : public GCFactory<Relocation, MCLD_RELOCATIONS_PER_INPUT> {
27  public:
28   typedef Relocation::Type Type;
29   typedef Relocation::Address Address;
30   typedef Relocation::DWord DWord;
31   typedef Relocation::SWord SWord;
32 
33  public:
34   RelocationFactory();
35 
36   void setConfig(const LinkerConfig& pConfig);
37 
38   // ----- production ----- //
39   /// produce - produce a relocation entry
40   /// @param pType - the type of the relocation entry
41   /// @param pFragRef - the place to apply the relocation
42   /// @param pAddend - the addend of the relocation entry
43   Relocation* produce(Type pType, FragmentRef& pFragRef, Address pAddend = 0);
44 
45   /// produceEmptyEntry - produce an empty relocation which
46   /// occupied memory space but all contents set to zero.
47   Relocation* produceEmptyEntry();
48 
49   void destroy(Relocation* pRelocation);
50 
51  private:
52   const LinkerConfig* m_pConfig;
53 };
54 
55 }  // namespace mcld
56 
57 #endif  // MCLD_LD_RELOCATIONFACTORY_H_
58