blob: 9fbb97de69f97c09dd6ec24b7c2adbd5e6f736ee [file] [log] [blame]
Ted Kremenek0b2d7aa2007-10-23 21:29:33 +00001//==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Ted Kremenek and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the internal methods used for object serialization.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Bitcode/Serialization.h"
15
16using namespace llvm;
17
18Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
19 : Stream(stream), inBlock(BlockID >= 8) {
20
21 if (inBlock) Stream.EnterSubblock(8,3);
22}
23
24Serializer::~Serializer() {
25 if (inRecord())
26 EmitRecord();
27
28 if (inBlock)
29 Stream.ExitBlock();
30
31 Stream.FlushToWord();
32}
33
34void Serializer::EmitRecord() {
35 assert(Record.size() > 0 && "Cannot emit empty record.");
36 Stream.EmitRecord(8,Record);
37 Record.clear();
38}
39
40void Serializer::EmitInt(unsigned X, unsigned bits) {
41 Record.push_back(X);
42}
43
44void Serializer::EmitCString(const char* cstr) {
45 unsigned l = strlen(cstr);
46 Record.push_back(l);
47
48 for (unsigned i = 0; i < l; i++)
49 Record.push_back(cstr[i]);
50
51 EmitRecord();
52}