From 8fc9b4d314c49fa3e20f1f91d09d6160502a8e1e Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 8 Nov 2016 04:17:11 +0000 Subject: 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, 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 --- unittests/Bitcode/BitstreamReaderTest.cpp | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'unittests/Bitcode') 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{}); - BitstreamCursor Cursor(Reader); + BitstreamCursor Cursor(ArrayRef{}); 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 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((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(Bytes, I)); - SimpleBitstreamCursor Cursor(Reader); + SimpleBitstreamCursor Cursor(ArrayRef(Bytes, I)); EXPECT_EQ(8ull, Cursor.Read(8)); } } -- cgit v1.2.3