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

@@ -20,8 +20,7 @@ TEST(BitstreamReaderTest, AtEndOfStream) {
uint8_t Bytes[4] = {
0x00, 0x01, 0x02, 0x03
};
BitstreamReader Reader(Bytes);
BitstreamCursor Cursor(Reader);
BitstreamCursor Cursor(Bytes);
EXPECT_FALSE(Cursor.AtEndOfStream());
(void)Cursor.Read(8);
@@ -40,24 +39,21 @@ TEST(BitstreamReaderTest, AtEndOfStreamJump) {
uint8_t Bytes[4] = {
0x00, 0x01, 0x02, 0x03
};
BitstreamReader Reader(Bytes);
BitstreamCursor Cursor(Reader);
BitstreamCursor Cursor(Bytes);
Cursor.JumpToBit(32);
EXPECT_TRUE(Cursor.AtEndOfStream());
}
TEST(BitstreamReaderTest, AtEndOfStreamEmpty) {
BitstreamReader Reader(ArrayRef<uint8_t>{});
BitstreamCursor Cursor(Reader);
BitstreamCursor Cursor(ArrayRef<uint8_t>{});
EXPECT_TRUE(Cursor.AtEndOfStream());
}
TEST(BitstreamReaderTest, getCurrentByteNo) {
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03};
BitstreamReader Reader(Bytes);
SimpleBitstreamCursor Cursor(Reader);
SimpleBitstreamCursor Cursor(Bytes);
for (unsigned I = 0, E = 32; I != E; ++I) {
EXPECT_EQ(I / 8, Cursor.getCurrentByteNo());
@@ -68,8 +64,7 @@ TEST(BitstreamReaderTest, getCurrentByteNo) {
TEST(BitstreamReaderTest, getPointerToByte) {
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
BitstreamReader Reader(Bytes);
SimpleBitstreamCursor Cursor(Reader);
SimpleBitstreamCursor Cursor(Bytes);
for (unsigned I = 0, E = 8; I != E; ++I) {
EXPECT_EQ(Bytes + I, Cursor.getPointerToByte(I, 1));
@@ -78,25 +73,13 @@ TEST(BitstreamReaderTest, getPointerToByte) {
TEST(BitstreamReaderTest, getPointerToBit) {
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
BitstreamReader Reader(Bytes);
SimpleBitstreamCursor Cursor(Reader);
SimpleBitstreamCursor Cursor(Bytes);
for (unsigned I = 0, E = 8; I != E; ++I) {
EXPECT_EQ(Bytes + I, Cursor.getPointerToBit(I * 8, 1));
}
}
TEST(BitstreamReaderTest, jumpToPointer) {
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
BitstreamReader Reader(Bytes);
SimpleBitstreamCursor Cursor(Reader);
for (unsigned I : {0, 6, 2, 7}) {
Cursor.jumpToPointer(Bytes + I);
EXPECT_EQ(I, Cursor.getCurrentByteNo());
}
}
TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
SmallVector<uint8_t, 1> BlobData;
for (unsigned I = 0, E = 1024; I != E; ++I)
@@ -129,9 +112,8 @@ TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
}
// Stream the buffer into the reader.
BitstreamReader R(
BitstreamCursor Stream(
ArrayRef<uint8_t>((const uint8_t *)Buffer.begin(), Buffer.size()));
BitstreamCursor Stream(R);
// Header. Included in test so that we can run llvm-bcanalyzer to debug
// when there are problems.
@@ -161,8 +143,7 @@ TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
TEST(BitstreamReaderTest, shortRead) {
uint8_t Bytes[] = {8, 7, 6, 5, 4, 3, 2, 1};
for (unsigned I = 1; I != 8; ++I) {
BitstreamReader Reader(ArrayRef<uint8_t>(Bytes, I));
SimpleBitstreamCursor Cursor(Reader);
SimpleBitstreamCursor Cursor(ArrayRef<uint8_t>(Bytes, I));
EXPECT_EQ(8ull, Cursor.Read(8));
}
}