1 //===- MemoryAreaFactory.cpp ----------------------------------------------===//
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 #include "mcld/Support/MemoryAreaFactory.h"
10 #include "mcld/Support/RegionFactory.h"
11
12 using namespace mcld;
13
14 //==========================
15 // MemoryAreaFactory
MemoryAreaFactory(size_t pNum)16 MemoryAreaFactory::MemoryAreaFactory(size_t pNum)
17 : UniqueGCFactoryBase<sys::fs::Path, MemoryArea, 0>(pNum) {
18 // For each loaded file, MCLinker must load ELF header, section header,
19 // symbol table, and string table. So, we set the size of chunk quadruple
20 // larger than the number of input files.
21 m_pRegionFactory = new RegionFactory(pNum*4);
22 }
23
~MemoryAreaFactory()24 MemoryAreaFactory::~MemoryAreaFactory()
25 {
26 delete m_pRegionFactory;
27 }
28
produce(const sys::fs::Path & pPath,int pFlags)29 MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath, int pFlags)
30 {
31 MemoryArea* result = find(pPath);
32 if (0 == result) {
33 result = allocate();
34 new (result) MemoryArea(*m_pRegionFactory);
35 result->map(pPath, pFlags);
36 f_KeyMap.insert(std::make_pair(pPath, result));
37 }
38 return result;
39 }
40
produce(const sys::fs::Path & pPath,int pFlags,mode_t pMode)41 MemoryArea* MemoryAreaFactory::produce(const sys::fs::Path& pPath, int pFlags, mode_t pMode)
42 {
43 MemoryArea* result = find(pPath);
44 if (0 == result) {
45 result = allocate();
46 new (result) MemoryArea(*m_pRegionFactory);
47 result->map(pPath, pFlags, pMode);
48 f_KeyMap.insert(std::make_pair(pPath, result));
49 }
50 return result;
51 }
52
53