diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-08 04:17:11 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-08 04:17:11 +0000 |
commit | 8fc9b4d314c49fa3e20f1f91d09d6160502a8e1e (patch) | |
tree | f038f307c00821a5de4cb9e9f406930823f122b4 /unittests/Bitcode | |
parent | ef0facce3e2f2af8795a3cfba188dd87fe357f3c (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286207 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Bitcode')
-rw-r--r-- | unittests/Bitcode/BitstreamReaderTest.cpp | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/unittests/Bitcode/BitstreamReaderTest.cpp b/unittests/Bitcode/BitstreamReaderTest.cpp index 986023ee3e9..704eb803f9c 100644 --- a/unittests/Bitcode/BitstreamReaderTest.cpp +++ b/unittests/Bitcode/BitstreamReaderTest.cpp @@ -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)); } } |