summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Bitcode
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-11-08 04:17:11 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-11-08 04:17:11 +0000
commit77c89b6958f51a0b26c4849d37a200c1bc0319df (patch)
tree7ac81d7f4f32b81635db74539ad07fdbd1a6c535 /llvm/unittests/Bitcode
parent939c7d916e1631cf2a005b4ba6c03726ecbe0f85 (diff)
downloadbcm5719-llvm-77c89b6958f51a0b26c4849d37a200c1bc0319df.tar.gz
bcm5719-llvm-77c89b6958f51a0b26c4849d37a200c1bc0319df.zip
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
Diffstat (limited to 'llvm/unittests/Bitcode')
-rw-r--r--llvm/unittests/Bitcode/BitstreamReaderTest.cpp35
1 files changed, 8 insertions, 27 deletions
diff --git a/llvm/unittests/Bitcode/BitstreamReaderTest.cpp b/llvm/unittests/Bitcode/BitstreamReaderTest.cpp
index 986023ee3e9..704eb803f9c 100644
--- a/llvm/unittests/Bitcode/BitstreamReaderTest.cpp
+++ b/llvm/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));
}
}
OpenPOWER on IntegriCloud