diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-10-23 21:29:33 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-10-23 21:29:33 +0000 |
commit | bd3501887f415024e59d6c396d26c302f4fba8f9 (patch) | |
tree | f2ff4d65385fff1863a991358b3d1e33e7d2c5f2 /llvm/lib/Bitcode/Writer/Serialize.cpp | |
parent | 4ca0ca7e64a396e90d28f30d2b8582693f0858df (diff) | |
download | bcm5719-llvm-bd3501887f415024e59d6c396d26c302f4fba8f9.tar.gz bcm5719-llvm-bd3501887f415024e59d6c396d26c302f4fba8f9.zip |
Added preliminary implementation of generic object serialization to bitcode.
llvm-svn: 43261
Diffstat (limited to 'llvm/lib/Bitcode/Writer/Serialize.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/Serialize.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/Serialize.cpp b/llvm/lib/Bitcode/Writer/Serialize.cpp new file mode 100644 index 00000000000..9fbb97de69f --- /dev/null +++ b/llvm/lib/Bitcode/Writer/Serialize.cpp @@ -0,0 +1,52 @@ +//==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Ted Kremenek and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the internal methods used for object serialization. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Bitcode/Serialization.h" + +using namespace llvm; + +Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID) + : Stream(stream), inBlock(BlockID >= 8) { + + if (inBlock) Stream.EnterSubblock(8,3); +} + +Serializer::~Serializer() { + if (inRecord()) + EmitRecord(); + + if (inBlock) + Stream.ExitBlock(); + + Stream.FlushToWord(); +} + +void Serializer::EmitRecord() { + assert(Record.size() > 0 && "Cannot emit empty record."); + Stream.EmitRecord(8,Record); + Record.clear(); +} + +void Serializer::EmitInt(unsigned X, unsigned bits) { + Record.push_back(X); +} + +void Serializer::EmitCString(const char* cstr) { + unsigned l = strlen(cstr); + Record.push_back(l); + + for (unsigned i = 0; i < l; i++) + Record.push_back(cstr[i]); + + EmitRecord(); +} |