1//===- raw_mem_ostream.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_RAW_MEMORY_AREA_OSTREAM_H 10#define MCLD_RAW_MEMORY_AREA_OSTREAM_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14#include <string> 15 16#include <llvm/Support/raw_ostream.h> 17 18namespace mcld { 19 20class MemoryArea; 21 22class raw_mem_ostream : public llvm::raw_ostream 23{ 24public: 25 /// constructor - pMemoryArea must be writable. 26 explicit raw_mem_ostream(MemoryArea &pMemoryArea); 27 28 ~raw_mem_ostream(); 29 30 MemoryArea& getMemoryArea() { 31 flush(); 32 return m_MemoryArea; 33 } 34 35private: 36 /// write_impl - See raw_ostream::write_impl. 37 virtual void write_impl(const char *pPtr, size_t pSize); 38 39 /// current_pos - Return the current position within the stream, not 40 /// counting the bytes currently in the buffer. 41 virtual uint64_t current_pos() const; 42 43private: 44 MemoryArea& m_MemoryArea; 45 uint64_t m_Position; 46}; 47 48} // namespace of mcld 49 50#endif 51 52