summaryrefslogtreecommitdiff
path: root/include/mcld/MC/ContextFactory.h
blob: 169dbfa3daf21642a6010a199b0b2b907f0a582e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===- ContextFactory.h ---------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef MCLD_MC_CONTEXTFACTORY_H
#define MCLD_MC_CONTEXTFACTORY_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif

#include <mcld/LD/LDContext.h>
#include <mcld/Support/UniqueGCFactory.h>
#include <mcld/Support/Path.h>

namespace mcld
{
/** \class ContextFactory
 *  \brief ContextFactory avoids the duplicated LDContext of the same file.
 *
 *  MCLinker is designed for efficient memory usage. Because user can give
 *  MCLinker the same input file many times on the command line, MCLinker must
 *  avoid opening identical file twice.
 *
 *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
 *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
 *  ContextFactory returns the identical reference of LDContext if it's openend.
 *
 *  @see LDContext
 *  @see UniqueGCFactoryBase
 */
class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
{
public:
  explicit ContextFactory(size_t pNum);
  ~ContextFactory();

  LDContext* produce();
  LDContext* produce(const sys::fs::Path& pPath);
};

} // namespace of mcld

#endif