aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode/Writer/Serialize.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-10-23 21:29:33 +0000
committerTed Kremenek <kremenek@apple.com>2007-10-23 21:29:33 +0000
commitbe1a026a8d1c9aee03f2d5674ff1f20bc914d547 (patch)
treed0e33a53d4003e7301e40f581ce83f6eb6d6b9b0 /lib/Bitcode/Writer/Serialize.cpp
parent37af99953d1b1e140491bb40f18b6c9eaf857d9c (diff)
downloadexternal_llvm-be1a026a8d1c9aee03f2d5674ff1f20bc914d547.zip
external_llvm-be1a026a8d1c9aee03f2d5674ff1f20bc914d547.tar.gz
external_llvm-be1a026a8d1c9aee03f2d5674ff1f20bc914d547.tar.bz2
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
Diffstat (limited to 'lib/Bitcode/Writer/Serialize.cpp')
-rw-r--r--lib/Bitcode/Writer/Serialize.cpp52
1 files changed, 52 insertions, 0 deletions
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();
+}