aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode/BitstreamReader.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-06 21:50:39 +0000
committerChris Lattner <sabre@nondot.org>2009-04-06 21:50:39 +0000
commitdcd006bf7be859367f35db2417a42c83451431e8 (patch)
treeccd65cdbf61fb29290e6f534ff8e6a9ead5d7ead /include/llvm/Bitcode/BitstreamReader.h
parent8f3434647d3d39b49475239e3be1b8afb06415cf (diff)
add a new Blob encoding abbreviation for bitcode files that emits
elements in a form that is efficient for the reader to just get a pointer in memory and start reading. APIs to do efficient reading and writing are still todo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode/BitstreamReader.h')
-rw-r--r--include/llvm/Bitcode/BitstreamReader.h29
1 files changed, 25 insertions, 4 deletions
diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h
index da78731f2d..281f8a412b 100644
--- a/include/llvm/Bitcode/BitstreamReader.h
+++ b/include/llvm/Bitcode/BitstreamReader.h
@@ -149,7 +149,7 @@ public:
}
// If we run out of data, stop at the end of the stream.
- if (LastChar == NextChar) {
+ if (NextChar == LastChar) {
CurWord = 0;
BitsInCurWord = 0;
return 0;
@@ -380,9 +380,7 @@ public:
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
if (Op.isLiteral()) {
ReadAbbreviatedLiteral(Op, Vals);
- } else if (Op.getEncoding() != BitCodeAbbrevOp::Array) {
- ReadAbbreviatedField(Op, Vals);
- } else {
+ } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
// Array case. Read the number of elements as a vbr6.
unsigned NumElts = ReadVBR(6);
@@ -393,6 +391,29 @@ public:
// Read all the elements.
for (; NumElts; --NumElts)
ReadAbbreviatedField(EltEnc, Vals);
+ } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
+ // Blob case. Read the number of bytes as a vbr6.
+ unsigned NumElts = ReadVBR(6);
+ SkipToWord(); // 32-bit alignment
+
+ // Figure out where the end of this blob will be including tail padding.
+ const unsigned char *NewEnd = NextChar+((NumElts+3)&~3);
+
+ // If this would read off the end of the bitcode file, just set the
+ // record to empty and return.
+ if (NewEnd > LastChar) {
+ Vals.append(NumElts, 0);
+ NextChar = LastChar;
+ break;
+ }
+
+ // Otherwise, read the number of bytes.
+ for (; NumElts; ++NextChar, --NumElts)
+ Vals.push_back(*NextChar);
+ // Skip over tail padding.
+ NextChar = NewEnd;
+ } else {
+ ReadAbbreviatedField(Op, Vals);
}
}