1 //===- MemoryRegion.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/MemoryRegion.h> 10 #include <mcld/Support/RegionFactory.h> 11 12 #include <llvm/Support/ManagedStatic.h> 13 14 using namespace mcld; 15 16 static llvm::ManagedStatic<RegionFactory> g_RegionFactory; 17 18 //===----------------------------------------------------------------------===// 19 // MemoryRegion 20 //===----------------------------------------------------------------------===// 21 MemoryRegion::MemoryRegion() 22 : m_pParent(NULL), m_VMAStart(0), m_Length(0) { 23 } 24 25 MemoryRegion::MemoryRegion(MemoryRegion::Address pVMAStart, size_t pSize) 26 : m_pParent(NULL), m_VMAStart(pVMAStart), m_Length(pSize) { 27 } 28 29 MemoryRegion::~MemoryRegion() 30 { 31 } 32 33 MemoryRegion* MemoryRegion::Create(void* pStart, size_t pSize) 34 { 35 return g_RegionFactory->produce(static_cast<Address>(pStart), pSize); 36 } 37 38 MemoryRegion* MemoryRegion::Create(void* pStart, size_t pSize, Space& pSpace) 39 { 40 MemoryRegion* result = g_RegionFactory->produce(static_cast<Address>(pStart), 41 pSize); 42 result->setParent(pSpace); 43 pSpace.addRegion(*result); 44 return result; 45 } 46 47 void MemoryRegion::Destroy(MemoryRegion*& pRegion) 48 { 49 if (NULL == pRegion) 50 return; 51 52 if (pRegion->hasParent()) 53 pRegion->parent()->removeRegion(*pRegion); 54 g_RegionFactory->destruct(pRegion); 55 pRegion = NULL; 56 } 57 58