• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ContextFactory.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_MC_CONTEXTFACTORY_H
10 #define MCLD_MC_CONTEXTFACTORY_H
11 
12 #include <mcld/LD/LDContext.h>
13 #include <mcld/Support/UniqueGCFactory.h>
14 #include <mcld/Support/Path.h>
15 
16 namespace mcld
17 {
18 /** \class ContextFactory
19  *  \brief ContextFactory avoids the duplicated LDContext of the same file.
20  *
21  *  MCLinker is designed for efficient memory usage. Because user can give
22  *  MCLinker the same input file many times on the command line, MCLinker must
23  *  avoid opening identical file twice.
24  *
25  *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
26  *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
27  *  ContextFactory returns the identical reference of LDContext if it's openend.
28  *
29  *  @see LDContext
30  *  @see UniqueGCFactoryBase
31  */
32 class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
33 {
34 public:
35   explicit ContextFactory(size_t pNum);
36   ~ContextFactory();
37 
38   LDContext* produce();
39   LDContext* produce(const sys::fs::Path& pPath);
40 };
41 
42 } // namespace of mcld
43 
44 #endif
45 
46