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