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//===----------------------------------------------------------------------===//
987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#ifndef MCLD_MC_CONTEXTFACTORY_H
1087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#define MCLD_MC_CONTEXTFACTORY_H
115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/LD/LDContext.h>
135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/UniqueGCFactory.h>
145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/Path.h>
155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class ContextFactory
195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief ContextFactory avoids the duplicated LDContext of the same file.
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker is designed for efficient memory usage. Because user can give
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker the same input file many times on the command line, MCLinker must
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  avoid opening identical file twice.
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory returns the identical reference of LDContext if it's openend.
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see LDContext
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see UniqueGCFactoryBase
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  explicit ContextFactory(size_t pNum);
365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~ContextFactory();
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
38affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  LDContext* produce();
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDContext* produce(const sys::fs::Path& pPath);
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld
435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
46