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