diff options
author | Zachary Turner <zturner@google.com> | 2016-07-28 19:11:09 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-07-28 19:11:09 +0000 |
commit | 199f48a5f0d5aee8737880a78d81216d60cf785d (patch) | |
tree | e801928d8148e3b77a22a69e8b8962e7bb9d7c19 /llvm/lib | |
parent | 941a705b7bf155fc581632ec7d80f22a139bdac0 (diff) | |
download | bcm5719-llvm-199f48a5f0d5aee8737880a78d81216d60cf785d.tar.gz bcm5719-llvm-199f48a5f0d5aee8737880a78d81216d60cf785d.zip |
Get rid of IMsfStreamData class.
This was a pure virtual base class whose purpose was to abstract
away the notion of how you retrieve the layout of a discontiguous
stream of blocks in an Msf file. This led to too many layers of
abstraction making it difficult to figure out what was going on
and extend things. Ultimately, a stream's layout is decided by
its length and the array of block numbers that it lives on. So
rather than have an abstract base class which can return this in
any number of ways, it's more straightforward to simply store them
as fields of a trivial struct, and also to give a more appropriate
name.
This patch does that. It renames IMsfStreamData to MsfStreamLayout,
and deletes the 2 concrete implementations, DirectoryStreamData
and IndexedStreamData. MsfStreamLayout is a trivial struct
with the necessary data.
llvm-svn: 277018
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/DebugInfo/Msf/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/Msf/IndexedStreamData.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/Msf/MappedBlockStream.cpp | 63 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/SymbolStream.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp | 1 |
11 files changed, 38 insertions, 69 deletions
diff --git a/llvm/lib/DebugInfo/Msf/CMakeLists.txt b/llvm/lib/DebugInfo/Msf/CMakeLists.txt index 49a71a8409c..3be398bbbeb 100644 --- a/llvm/lib/DebugInfo/Msf/CMakeLists.txt +++ b/llvm/lib/DebugInfo/Msf/CMakeLists.txt @@ -1,6 +1,5 @@ add_llvm_library(LLVMDebugInfoMsf ByteStream.cpp - IndexedStreamData.cpp MappedBlockStream.cpp MsfBuilder.cpp MsfCommon.cpp diff --git a/llvm/lib/DebugInfo/Msf/IndexedStreamData.cpp b/llvm/lib/DebugInfo/Msf/IndexedStreamData.cpp deleted file mode 100644 index 81303aeb8f4..00000000000 --- a/llvm/lib/DebugInfo/Msf/IndexedStreamData.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===- IndexedStreamData.cpp - Standard PDB Stream Data ---------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" -#include "llvm/DebugInfo/Msf/IMsfFile.h" - -using namespace llvm; -using namespace llvm::msf; - -IndexedStreamData::IndexedStreamData(uint32_t StreamIdx, const IMsfFile &File) - : StreamIdx(StreamIdx), File(File) {} - -uint32_t IndexedStreamData::getLength() { - return File.getStreamByteSize(StreamIdx); -} - -ArrayRef<support::ulittle32_t> IndexedStreamData::getStreamBlocks() { - return File.getStreamBlockList(StreamIdx); -} diff --git a/llvm/lib/DebugInfo/Msf/MappedBlockStream.cpp b/llvm/lib/DebugInfo/Msf/MappedBlockStream.cpp index f2c80122169..06ca694174b 100644 --- a/llvm/lib/DebugInfo/Msf/MappedBlockStream.cpp +++ b/llvm/lib/DebugInfo/Msf/MappedBlockStream.cpp @@ -8,10 +8,10 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/Msf/MappedBlockStream.h" -#include "llvm/DebugInfo/Msf/DirectoryStreamData.h" -#include "llvm/DebugInfo/Msf/IMsfStreamData.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" + +#include "llvm/DebugInfo/Msf/IMsfFile.h" #include "llvm/DebugInfo/Msf/MsfError.h" +#include "llvm/DebugInfo/Msf/MsfStreamLayout.h" using namespace llvm; using namespace llvm::msf; @@ -22,9 +22,8 @@ namespace { // protected, forcing users to go through the `create` interface. class MappedBlockStreamImpl : public MappedBlockStream { public: - MappedBlockStreamImpl(std::unique_ptr<IMsfStreamData> Data, - const IMsfFile &File) - : MappedBlockStream(std::move(Data), File) {} + MappedBlockStreamImpl(const MsfStreamLayout &Layout, const IMsfFile &File) + : MappedBlockStream(Layout, File) {} }; } @@ -34,16 +33,16 @@ static Interval intersect(const Interval &I1, const Interval &I2) { std::min(I1.second, I2.second)); } -MappedBlockStream::MappedBlockStream(std::unique_ptr<IMsfStreamData> Data, +MappedBlockStream::MappedBlockStream(const MsfStreamLayout &Layout, const IMsfFile &File) - : Msf(File), Data(std::move(Data)) {} + : Msf(File), Layout(Layout) {} Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, ArrayRef<uint8_t> &Buffer) const { // Make sure we aren't trying to read beyond the end of the stream. - if (Size > Data->getLength()) + if (Size > Layout.Length) return make_error<MsfError>(msf_error_code::insufficient_buffer); - if (Offset > Data->getLength() - Size) + if (Offset > Layout.Length - Size) return make_error<MsfError>(msf_error_code::insufficient_buffer); if (tryReadContiguously(Offset, Size, Buffer)) @@ -121,14 +120,13 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, Error MappedBlockStream::readLongestContiguousChunk( uint32_t Offset, ArrayRef<uint8_t> &Buffer) const { // Make sure we aren't trying to read beyond the end of the stream. - if (Offset >= Data->getLength()) + if (Offset >= Layout.Length) return make_error<MsfError>(msf_error_code::insufficient_buffer); uint32_t First = Offset / Msf.getBlockSize(); uint32_t Last = First; - auto BlockList = Data->getStreamBlocks(); while (Last < Msf.getBlockCount() - 1) { - if (BlockList[Last] != BlockList[Last + 1] - 1) + if (Layout.Blocks[Last] != Layout.Blocks[Last + 1] - 1) break; ++Last; } @@ -138,7 +136,7 @@ Error MappedBlockStream::readLongestContiguousChunk( uint32_t BlockSpan = Last - First + 1; uint32_t ByteSpan = BytesFromFirstBlock + (BlockSpan - 1) * Msf.getBlockSize(); - auto Result = Msf.getBlockData(BlockList[First], Msf.getBlockSize()); + auto Result = Msf.getBlockData(Layout.Blocks[First], Msf.getBlockSize()); if (!Result) return Result.takeError(); Buffer = Result->drop_front(OffsetInFirstBlock); @@ -146,7 +144,7 @@ Error MappedBlockStream::readLongestContiguousChunk( return Error::success(); } -uint32_t MappedBlockStream::getLength() const { return Data->getLength(); } +uint32_t MappedBlockStream::getLength() const { return Layout.Length; } Error MappedBlockStream::commit() const { return Error::success(); } @@ -165,15 +163,14 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size, llvm::alignTo(Size - BytesFromFirstBlock, Msf.getBlockSize()) / Msf.getBlockSize(); - auto BlockList = Data->getStreamBlocks(); uint32_t RequiredContiguousBlocks = NumAdditionalBlocks + 1; - uint32_t E = BlockList[BlockNum]; + uint32_t E = Layout.Blocks[BlockNum]; for (uint32_t I = 0; I < RequiredContiguousBlocks; ++I, ++E) { - if (BlockList[I + BlockNum] != E) + if (Layout.Blocks[I + BlockNum] != E) return false; } - uint32_t FirstBlockAddr = BlockList[BlockNum]; + uint32_t FirstBlockAddr = Layout.Blocks[BlockNum]; auto Result = Msf.getBlockData(FirstBlockAddr, Msf.getBlockSize()); if (!Result) { consumeError(Result.takeError()); @@ -190,17 +187,16 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t OffsetInBlock = Offset % Msf.getBlockSize(); // Make sure we aren't trying to read beyond the end of the stream. - if (Buffer.size() > Data->getLength()) + if (Buffer.size() > Layout.Length) return make_error<MsfError>(msf_error_code::insufficient_buffer); - if (Offset > Data->getLength() - Buffer.size()) + if (Offset > Layout.Length - Buffer.size()) return make_error<MsfError>(msf_error_code::insufficient_buffer); uint32_t BytesLeft = Buffer.size(); uint32_t BytesWritten = 0; uint8_t *WriteBuffer = Buffer.data(); - auto BlockList = Data->getStreamBlocks(); while (BytesLeft > 0) { - uint32_t StreamBlockAddr = BlockList[BlockNum]; + uint32_t StreamBlockAddr = Layout.Blocks[BlockNum]; auto Result = Msf.getBlockData(StreamBlockAddr, Msf.getBlockSize()); if (!Result) @@ -224,20 +220,19 @@ Error MappedBlockStream::readBytes(uint32_t Offset, Error MappedBlockStream::writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const { // Make sure we aren't trying to write beyond the end of the stream. - if (Buffer.size() > Data->getLength()) + if (Buffer.size() > Layout.Length) return make_error<MsfError>(msf_error_code::insufficient_buffer); - if (Offset > Data->getLength() - Buffer.size()) + if (Offset > Layout.Length - Buffer.size()) return make_error<MsfError>(msf_error_code::insufficient_buffer); uint32_t BlockNum = Offset / Msf.getBlockSize(); uint32_t OffsetInBlock = Offset % Msf.getBlockSize(); uint32_t BytesLeft = Buffer.size(); - auto BlockList = Data->getStreamBlocks(); uint32_t BytesWritten = 0; while (BytesLeft > 0) { - uint32_t StreamBlockAddr = BlockList[BlockNum]; + uint32_t StreamBlockAddr = Layout.Blocks[BlockNum]; uint32_t BytesToWriteInChunk = std::min(BytesLeft, Msf.getBlockSize() - OffsetInBlock); @@ -297,15 +292,19 @@ MappedBlockStream::createIndexedStream(uint32_t StreamIdx, const IMsfFile &File) { if (StreamIdx >= File.getNumStreams()) return make_error<MsfError>(msf_error_code::no_stream); - - auto Data = llvm::make_unique<IndexedStreamData>(StreamIdx, File); - return llvm::make_unique<MappedBlockStreamImpl>(std::move(Data), File); + MsfStreamLayout L; + L.Blocks = File.getStreamBlockList(StreamIdx); + L.Length = File.getStreamByteSize(StreamIdx); + return llvm::make_unique<MappedBlockStreamImpl>(L, File); } Expected<std::unique_ptr<MappedBlockStream>> MappedBlockStream::createDirectoryStream(uint32_t Length, ArrayRef<support::ulittle32_t> Blocks, const IMsfFile &File) { - auto Data = llvm::make_unique<DirectoryStreamData>(Length, Blocks); - return llvm::make_unique<MappedBlockStreamImpl>(std::move(Data), File); + MsfStreamLayout L; + L.Blocks = Blocks; + L.Length = Length; + + return llvm::make_unique<MappedBlockStreamImpl>(L, File); } diff --git a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp index 1bad0009c37..35f79c801ba 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp @@ -9,7 +9,6 @@ #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/StreamArray.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/Msf/StreamWriter.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp index 3d1bcdfd849..c55f51d7d4a 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp @@ -10,7 +10,6 @@ #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/Msf/StreamWriter.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp index 39e9dfaf3e2..65d59a5e894 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp @@ -9,7 +9,6 @@ #include "llvm/DebugInfo/PDB/Raw/ModStream.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index f9ad8995db3..ea0a8c91304 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -10,8 +10,6 @@ #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/DebugInfo/Msf/DirectoryStreamData.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/StreamArray.h" #include "llvm/DebugInfo/Msf/StreamInterface.h" #include "llvm/DebugInfo/Msf/StreamReader.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp index 49bcb2f7dfe..5007a56f276 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -58,8 +58,7 @@ DbiStreamBuilder &PDBFileBuilder::getDbiBuilder() { return *Dbi; } -Expected<std::unique_ptr<PDBFile>> -PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) { +Expected<msf::Layout> PDBFileBuilder::finalizeMsfLayout() const { if (Info) { uint32_t Length = Info->calculateSerializedLength(); if (auto EC = Msf->setStreamSize(StreamPDB, Length)) @@ -71,7 +70,12 @@ PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) { return std::move(EC); } - auto ExpectedLayout = Msf->build(); + return Msf->build(); +} + +Expected<std::unique_ptr<PDBFile>> +PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) { + auto ExpectedLayout = finalizeMsfLayout(); if (!ExpectedLayout) return ExpectedLayout.takeError(); diff --git a/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp index 426efb8fd88..8f96e5e61f5 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp @@ -26,7 +26,6 @@ #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/MappedBlockStream.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/SymbolStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/SymbolStream.cpp index f98b5d4688b..a604df3ae9a 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/SymbolStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/SymbolStream.cpp @@ -11,7 +11,6 @@ #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/MappedBlockStream.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" diff --git a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp index f642940bbc9..6756580547a 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp @@ -13,7 +13,6 @@ #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/Msf/IndexedStreamData.h" #include "llvm/DebugInfo/Msf/MappedBlockStream.h" #include "llvm/DebugInfo/Msf/StreamReader.h" #include "llvm/DebugInfo/PDB/Raw/Hash.h" |