From 8cf51c340dcb0c150a5dcb8c820c758c781404d9 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 3 Aug 2016 16:53:21 +0000 Subject: [msf] Make FPM reader use MappedBlockStream. MappedBlockSTream can work with any sequence of block data where the ordering is specified by a list of block numbers. So rather than manually stitch them together in the case of the FPM, reuse this functionality so that we can treat the FPM as if it were contiguous. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D23066 llvm-svn: 277609 --- llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp') diff --git a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp index 0a3b2b96ab4..bbcfbfca810 100644 --- a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp +++ b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp @@ -26,6 +26,19 @@ public: }; } +static void initializeFpmStreamLayout(const MSFLayout &Layout, + MSFStreamLayout &FpmLayout) { + uint32_t NumFpmIntervals = msf::getNumFpmIntervals(Layout); + support::ulittle32_t FpmBlock = Layout.SB->FreeBlockMapBlock; + assert(FpmBlock == 1 || FpmBlock == 2); + while (NumFpmIntervals > 0) { + FpmLayout.Blocks.push_back(FpmBlock); + FpmBlock += msf::getFpmIntervalLength(Layout); + --NumFpmIntervals; + } + FpmLayout.Length = msf::getFullFpmByteSize(Layout); +} + typedef std::pair Interval; static Interval intersect(const Interval &I1, const Interval &I2) { return std::make_pair(std::max(I1.first, I2.first), @@ -66,6 +79,14 @@ MappedBlockStream::createDirectoryStream(const MSFLayout &Layout, return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData); } +std::unique_ptr +MappedBlockStream::createFpmStream(const MSFLayout &Layout, + const ReadableStream &MsfData) { + MSFStreamLayout SL; + initializeFpmStreamLayout(Layout, SL); + return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData); +} + Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) const { // Make sure we aren't trying to read beyond the end of the stream. @@ -324,6 +345,14 @@ WritableMappedBlockStream::createDirectoryStream( return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData); } +std::unique_ptr +WritableMappedBlockStream::createFpmStream(const MSFLayout &Layout, + const WritableStream &MsfData) { + MSFStreamLayout SL; + initializeFpmStreamLayout(Layout, SL); + return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData); +} + Error WritableMappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, ArrayRef &Buffer) const { return ReadInterface.readBytes(Offset, Size, Buffer); -- cgit v1.2.3