LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/Msf - MappedBlockStream.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 5 5 100.0 %
Date: 2016-07-29 04:53:09 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MappedBlockStream.h - Discontiguous stream data in an Msf -*- C++
       2             : //-*-===//
       3             : //
       4             : //                     The LLVM Compiler Infrastructure
       5             : //
       6             : // This file is distributed under the University of Illinois Open Source
       7             : // License. See LICENSE.TXT for details.
       8             : //
       9             : //===----------------------------------------------------------------------===//
      10             : 
      11             : #ifndef LLVM_DEBUGINFO_MSF_MAPPEDBLOCKSTREAM_H
      12             : #define LLVM_DEBUGINFO_MSF_MAPPEDBLOCKSTREAM_H
      13             : 
      14             : #include "llvm/ADT/ArrayRef.h"
      15             : #include "llvm/ADT/DenseMap.h"
      16             : #include "llvm/ADT/STLExtras.h"
      17             : #include "llvm/DebugInfo/Msf/MsfStreamLayout.h"
      18             : #include "llvm/DebugInfo/Msf/StreamInterface.h"
      19             : #include "llvm/Support/Allocator.h"
      20             : #include "llvm/Support/Endian.h"
      21             : #include "llvm/Support/Error.h"
      22             : #include <cstdint>
      23             : #include <vector>
      24             : 
      25             : namespace llvm {
      26             : namespace msf {
      27             : 
      28             : struct MsfLayout;
      29             : 
      30             : /// MappedBlockStream represents data stored in an Msf file into chunks of a
      31             : /// particular size (called the Block Size), and whose chunks may not be
      32             : /// necessarily contiguous.  The arrangement of these chunks within the file
      33             : /// is described by some other metadata contained within the Msf file.  In
      34             : /// the case of a standard Msf Stream, the layout of the stream's blocks
      35             : /// is described by the Msf "directory", but in the case of the directory
      36             : /// itself, the layout is described by an array at a fixed location within
      37             : /// the Msf.  MappedBlockStream provides methods for reading from and writing
      38             : /// to one of these streams transparently, as if it were a contiguous sequence
      39             : /// of bytes.
      40         141 : class MappedBlockStream : public ReadableStream {
      41             :   friend class WritableMappedBlockStream;
      42             : 
      43             : public:
      44             :   static std::unique_ptr<MappedBlockStream>
      45             :   createStream(uint32_t BlockSize, uint32_t NumBlocks,
      46             :                const MsfStreamLayout &Layout, const ReadableStream &MsfData);
      47             : 
      48             :   static std::unique_ptr<MappedBlockStream>
      49             :   createIndexedStream(const MsfLayout &Layout, const ReadableStream &MsfData,
      50             :                       uint32_t StreamIndex);
      51             : 
      52             :   static std::unique_ptr<MappedBlockStream>
      53             :   createDirectoryStream(const MsfLayout &Layout, const ReadableStream &MsfData);
      54             : 
      55             :   Error readBytes(uint32_t Offset, uint32_t Size,
      56             :                   ArrayRef<uint8_t> &Buffer) const override;
      57             :   Error readLongestContiguousChunk(uint32_t Offset,
      58             :                                    ArrayRef<uint8_t> &Buffer) const override;
      59             : 
      60             :   uint32_t getLength() const override;
      61             : 
      62             :   uint32_t getNumBytesCopied() const;
      63             : 
      64             :   llvm::BumpPtrAllocator &getAllocator() { return Pool; }
      65             : 
      66             :   void invalidateCache();
      67             : 
      68             :   uint32_t getBlockSize() const { return BlockSize; }
      69             :   uint32_t getNumBlocks() const { return NumBlocks; }
      70             :   uint32_t getStreamLength() const { return StreamLayout.Length; }
      71             : 
      72             : protected:
      73             :   MappedBlockStream(uint32_t BlockSize, uint32_t NumBlocks,
      74             :                     const MsfStreamLayout &StreamLayout,
      75             :                     const ReadableStream &MsfData);
      76             : 
      77             : private:
      78             :   const MsfStreamLayout &getStreamLayout() const { return StreamLayout; }
      79             :   void fixCacheAfterWrite(uint32_t Offset, ArrayRef<uint8_t> Data) const;
      80             : 
      81             :   Error readBytes(uint32_t Offset, MutableArrayRef<uint8_t> Buffer) const;
      82             :   bool tryReadContiguously(uint32_t Offset, uint32_t Size,
      83             :                            ArrayRef<uint8_t> &Buffer) const;
      84             : 
      85             :   const uint32_t BlockSize;
      86             :   const uint32_t NumBlocks;
      87             :   const MsfStreamLayout StreamLayout;
      88             :   const ReadableStream &MsfData;
      89             : 
      90             :   typedef MutableArrayRef<uint8_t> CacheEntry;
      91             :   mutable llvm::BumpPtrAllocator Pool;
      92             :   mutable DenseMap<uint32_t, std::vector<CacheEntry>> CacheMap;
      93             : };
      94             : 
      95           4 : class WritableMappedBlockStream : public WritableStream {
      96             : public:
      97             :   static std::unique_ptr<WritableMappedBlockStream>
      98             :   createStream(uint32_t BlockSize, uint32_t NumBlocks,
      99             :                const MsfStreamLayout &Layout, const WritableStream &MsfData);
     100             : 
     101             :   static std::unique_ptr<WritableMappedBlockStream>
     102             :   createIndexedStream(const MsfLayout &Layout, const WritableStream &MsfData,
     103             :                       uint32_t StreamIndex);
     104             : 
     105             :   static std::unique_ptr<WritableMappedBlockStream>
     106             :   createDirectoryStream(const MsfLayout &Layout, const WritableStream &MsfData);
     107             : 
     108             :   Error readBytes(uint32_t Offset, uint32_t Size,
     109             :                   ArrayRef<uint8_t> &Buffer) const override;
     110             :   Error readLongestContiguousChunk(uint32_t Offset,
     111             :                                    ArrayRef<uint8_t> &Buffer) const override;
     112             :   uint32_t getLength() const override;
     113             : 
     114             :   Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override;
     115             : 
     116             :   Error commit() const override;
     117             : 
     118             :   const MsfStreamLayout &getStreamLayout() const {
     119          76 :     return ReadInterface.getStreamLayout();
     120             :   }
     121         152 :   uint32_t getBlockSize() const { return ReadInterface.getBlockSize(); }
     122             :   uint32_t getNumBlocks() const { return ReadInterface.getNumBlocks(); }
     123          38 :   uint32_t getStreamLength() const { return ReadInterface.getStreamLength(); }
     124             : 
     125             : protected:
     126             :   WritableMappedBlockStream(uint32_t BlockSize, uint32_t NumBlocks,
     127             :                             const MsfStreamLayout &StreamLayout,
     128             :                             const WritableStream &MsfData);
     129             : 
     130             : private:
     131             :   MappedBlockStream ReadInterface;
     132             : 
     133             :   const WritableStream &WriteInterface;
     134             : };
     135             : 
     136             : } // end namespace pdb
     137             : } // end namespace llvm
     138             : 
     139             : #endif // LLVM_DEBUGINFO_MSF_MAPPEDBLOCKSTREAM_H

Generated by: LCOV version 1.12