aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/Writer/Serialize.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-05 21:36:35 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-05 21:36:35 +0000
commit0a6d98e10e3b5080861bc1e06c2053d7941f319a (patch)
tree864684a5e5e7b95e1e2b6c38a2903a4eeae4bc25 /lib/Bitcode/Writer/Serialize.cpp
parenteb57ea7ea2378b77bc995371c1888193b960cd03 (diff)
Added support in serializer and deserializer to create arbitrary blocks.
Added detection of end-of-stream in deserializer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43736 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Writer/Serialize.cpp')
-rw-r--r--lib/Bitcode/Writer/Serialize.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/Bitcode/Writer/Serialize.cpp b/lib/Bitcode/Writer/Serialize.cpp
index 58baf104c7..f25a1542d3 100644
--- a/lib/Bitcode/Writer/Serialize.cpp
+++ b/lib/Bitcode/Writer/Serialize.cpp
@@ -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 @@ void Serializer::EmitRecord() {
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 @@ unsigned Serializer::getPtrId(const void* ptr) {
else return I->second;
}
+
#define INT_EMIT(TYPE)\
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }