MemoryArea.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
1//===- MemoryArea.h -------------------------------------------------------===// 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#ifndef MCLD_SUPPORT_MEMORYAREA_H 10#define MCLD_SUPPORT_MEMORYAREA_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/ADT/Uncopyable.h> 16 17#include <llvm/ADT/OwningPtr.h> 18#include <llvm/ADT/StringRef.h> 19#include <llvm/Support/MemoryBuffer.h> 20 21namespace mcld { 22 23/** \class MemoryArea 24 * \brief MemoryArea is used to manage input read-only memory space. 25 */ 26class MemoryArea : private Uncopyable 27{ 28 friend class MemoryAreaFactory; 29public: 30 // constructor by file handler. 31 // If the given file handler is read-only, client can not request a region 32 // that out of the file size. 33 // @param pFileHandle - file handler 34 explicit MemoryArea(llvm::StringRef pFilename); 35 36 explicit MemoryArea(const char* pMemBuffer, size_t pSize); 37 38 // request - create a MemoryRegion within a sufficient space 39 // find an existing space to hold the MemoryRegion. 40 // if MemoryArea does not find such space, then it creates a new space and 41 // assign a MemoryRegion into the space. 42 llvm::StringRef request(size_t pOffset, size_t pLength); 43 44 size_t size() const; 45 46private: 47 llvm::OwningPtr<llvm::MemoryBuffer> m_pMemoryBuffer; 48}; 49 50} // namespace of mcld 51 52#endif 53