Bitcode: Decouple block info block state from reader.

As proposed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2016-October/106630.html

Move block info block state to a new class, BitstreamBlockInfo.
Clients may set the block info for a particular cursor with the
BitstreamCursor::setBlockInfo() method.

At this point BitstreamReader is not much more than a container for an
ArrayRef<uint8_t>, so remove it and replace all uses with direct uses
of memory buffers.

Differential Revision: https://reviews.llvm.org/D26259

llvm-svn: 286207
This commit is contained in:
Peter Collingbourne
2016-11-08 04:17:11 +00:00
parent 939c7d916e
commit 77c89b6958
15 changed files with 156 additions and 251 deletions

View File

@@ -233,7 +233,7 @@ protected:
BitcodeReaderBase(MemoryBuffer *Buffer) : Buffer(Buffer) {}
std::unique_ptr<MemoryBuffer> Buffer;
std::unique_ptr<BitstreamReader> StreamFile;
BitstreamBlockInfo BlockInfo;
BitstreamCursor Stream;
std::error_code initStream();
@@ -256,8 +256,8 @@ std::error_code BitcodeReaderBase::initStream() {
if (SkipBitcodeWrapperHeader(BufPtr, BufEnd, true))
return error("Invalid bitcode wrapper header");
StreamFile.reset(new BitstreamReader(ArrayRef<uint8_t>(BufPtr, BufEnd)));
Stream.init(&*StreamFile);
Stream = BitstreamCursor(ArrayRef<uint8_t>(BufPtr, BufEnd));
Stream.setBlockInfo(&BlockInfo);
return std::error_code();
}
@@ -2211,8 +2211,7 @@ std::error_code BitcodeReader::parseMetadataStrings(ArrayRef<uint64_t> Record,
return error("Invalid record: metadata strings corrupt offset");
StringRef Lengths = Blob.slice(0, StringsOffset);
SimpleBitstreamCursor R(*StreamFile);
R.jumpToPointer(Lengths.begin());
SimpleBitstreamCursor R(Lengths);
StringRef Strings = Blob.drop_front(StringsOffset);
do {
@@ -3759,9 +3758,12 @@ std::error_code BitcodeReader::parseBitcodeVersion() {
}
}
bool BitcodeReaderBase::readBlockInfo() {
return Stream.ReadBlockInfoBlock();
Optional<BitstreamBlockInfo> NewBlockInfo = Stream.ReadBlockInfoBlock();
if (!NewBlockInfo)
return true;
BlockInfo = std::move(*NewBlockInfo);
return false;
}
std::error_code BitcodeReader::parseModule(uint64_t ResumeBit,