1 //==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the internal methods used for object serialization.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Bitcode/Serialize.h"
19 Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
20 : Stream(stream), inBlock(BlockID >= 8) {
22 if (inBlock) Stream.EnterSubblock(8,3);
25 Serializer::~Serializer() {
35 void Serializer::EmitRecord() {
36 assert(Record.size() > 0 && "Cannot emit empty record.");
37 Stream.EmitRecord(8,Record);
41 void Serializer::EmitInt(unsigned X) {
45 void Serializer::EmitCStr(const char* s, const char* end) {
46 Record.push_back(end - s);
56 void Serializer::EmitCStr(const char* s) {
57 EmitCStr(s,s+strlen(s));
60 unsigned Serializer::getPtrId(const void* ptr) {
64 MapTy::iterator I = PtrMap.find(ptr);
66 if (I == PtrMap.end()) {
67 unsigned id = PtrMap.size()+1;
71 else return I->second;
74 #define INT_EMIT(TYPE)\
75 void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
78 INT_EMIT(unsigned char)
79 INT_EMIT(unsigned short)
80 INT_EMIT(unsigned int)
81 INT_EMIT(unsigned long)