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
This commit is contained in:
Chris Lattner
2009-04-06 21:50:39 +00:00
parent 8f3434647d
commit dcd006bf7b
4 changed files with 56 additions and 10 deletions

View File

@ -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);
}
}