[llvm-commits] [llvm] r43736 - in /llvm/trunk: include/llvm/Bitcode/Deserialize.h include/llvm/Bitcode/Serialize.h lib/Bitcode/Reader/Deserialize.cpp lib/Bitcode/Writer/Serialize.cpp
Ted Kremenek
kremenek at apple.com
Mon Nov 5 13:36:35 PST 2007
Author: kremenek
Date: Mon Nov 5 15:36:35 2007
New Revision: 43736
URL: http://llvm.org/viewvc/llvm-project?rev=43736&view=rev
Log:
Added support in serializer and deserializer to create arbitrary blocks.
Added detection of end-of-stream in deserializer.
Modified:
llvm/trunk/include/llvm/Bitcode/Deserialize.h
llvm/trunk/include/llvm/Bitcode/Serialize.h
llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp
llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
Modified: llvm/trunk/include/llvm/Bitcode/Deserialize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Deserialize.h?rev=43736&r1=43735&r2=43736&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Deserialize.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Deserialize.h Mon Nov 5 15:36:35 2007
@@ -153,6 +153,8 @@
void RegisterPtr(const void* Ptr) {
RegisterPtr(ReadInt(),Ptr);
}
+
+ bool AtEnd();
private:
void ReadRecord();
Modified: llvm/trunk/include/llvm/Bitcode/Serialize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Serialize.h?rev=43736&r1=43735&r2=43736&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Serialize.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Serialize.h Mon Nov 5 15:36:35 2007
@@ -25,7 +25,7 @@
class Serializer {
BitstreamWriter& Stream;
SmallVector<uint64_t,10> Record;
- bool inBlock;
+ unsigned BlockLevel;
typedef DenseMap<const void*,unsigned> MapTy;
MapTy PtrMap;
@@ -56,6 +56,9 @@
void Flush() { if (inRecord()) EmitRecord(); }
+ void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
+ void ExitBlock();
+
private:
void EmitRecord();
inline bool inRecord() { return Record.size() > 0; }
Modified: llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp?rev=43736&r1=43735&r2=43736&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp Mon Nov 5 15:36:35 2007
@@ -47,10 +47,15 @@
// FIXME: Check if we haven't run off the edge of the stream.
// FIXME: Handle abbreviations.
+ assert (Record.size() == 0);
+
unsigned Code;
while (true) {
+ if (Stream.AtEndOfStream())
+ return;
+
Code = Stream.ReadCode();
if (Code == bitc::ENTER_SUBBLOCK) {
@@ -71,7 +76,16 @@
assert (Record.size() == 0);
Stream.ReadRecord(Code,Record);
- assert (Record.size() > 0);
+ assert (Record.size() > 0 || Stream.AtEndOfStream());
+}
+
+bool Deserializer::AtEnd() {
+ if (inRecord())
+ return false;
+
+ ReadRecord();
+
+ return Stream.AtEndOfStream();
}
uint64_t Deserializer::ReadInt() {
Modified: llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/Serialize.cpp?rev=43736&r1=43735&r2=43736&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/Serialize.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/Serialize.cpp Mon Nov 5 15:36:35 2007
@@ -17,16 +17,17 @@
using namespace llvm;
Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
- : Stream(stream), inBlock(BlockID >= 8) {
+ : Stream(stream), BlockLevel(0) {
- if (inBlock) Stream.EnterSubblock(8,3);
+ if (BlockID >= 8)
+ EnterBlock(8,3);
}
Serializer::~Serializer() {
if (inRecord())
EmitRecord();
- if (inBlock)
+ while (BlockLevel > 0)
Stream.ExitBlock();
Stream.FlushToWord();
@@ -38,7 +39,21 @@
Record.clear();
}
+void Serializer::EnterBlock(unsigned BlockID,unsigned CodeLen) {
+ Flush();
+ Stream.EnterSubblock(BlockID,CodeLen);
+ ++BlockLevel;
+}
+
+void Serializer::ExitBlock() {
+ assert (BlockLevel > 0);
+ --BlockLevel;
+ Flush();
+ Stream.ExitBlock();
+}
+
void Serializer::EmitInt(unsigned X) {
+ assert (BlockLevel > 0);
Record.push_back(X);
}
@@ -71,6 +86,7 @@
else return I->second;
}
+
#define INT_EMIT(TYPE)\
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
More information about the llvm-commits
mailing list