15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- ContextFactory.h ---------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_MC_CONTEXTFACTORY_H_
1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_MC_CONTEXTFACTORY_H_
115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/LD/LDContext.h"
1337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/UniqueGCFactory.h"
1437b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/Path.h"
155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1637b74a387bb3993387029859c2d9d051c41c724eStephen Hinesnamespace mcld {
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class ContextFactory
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief ContextFactory avoids the duplicated LDContext of the same file.
195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker is designed for efficient memory usage. Because user can give
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker the same input file many times on the command line, MCLinker must
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  avoid opening identical file twice.
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory returns the identical reference of LDContext if it's openend.
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see LDContext
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see UniqueGCFactoryBase
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
3137b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0> {
3237b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  explicit ContextFactory(size_t pNum);
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~ContextFactory();
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
36affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  LDContext* produce();
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDContext* produce(const sys::fs::Path& pPath);
3837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  LDContext* produce(const char* pPath);
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
4137b74a387bb3993387029859c2d9d051c41c724eStephen Hines}  // namespace mcld
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
4337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // MCLD_MC_CONTEXTFACTORY_H_
44