From be1a026a8d1c9aee03f2d5674ff1f20bc914d547 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 23 Oct 2007 21:29:33 +0000 Subject: Added preliminary implementation of generic object serialization to bitcode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43261 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/Serialize.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/Bitcode/Writer/Serialize.cpp (limited to 'lib/Bitcode/Writer/Serialize.cpp') diff --git a/lib/Bitcode/Writer/Serialize.cpp b/lib/Bitcode/Writer/Serialize.cpp new file mode 100644 index 0000000..9fbb97d --- /dev/null +++ b/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(); +} -- cgit v1.1