1 //==- Serialize.h - 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 interface for generic object serialization to
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_BITCODE_SERIALIZE_OUTPUT
16 #define LLVM_BITCODE_SERIALIZE_OUTPUT
18 #include "llvm/Bitcode/Serialization.h"
19 #include "llvm/Bitcode/BitstreamWriter.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/DenseMap.h"
26 BitstreamWriter& Stream;
27 SmallVector<uint64_t,10> Record;
30 typedef DenseMap<const void*,unsigned> MapTy;
34 Serializer(BitstreamWriter& stream, unsigned BlockID = 8);
39 inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
41 void EmitInt(unsigned X);
42 void EmitBool(bool X) { EmitInt(X); }
43 void EmitCStr(const char* beg, const char* end);
44 void EmitCStr(const char* cstr);
46 void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
49 void EmitRef(const T& ref) { EmitPtr(&ref); }
52 void EmitOwnedPtr(T* ptr) {
54 if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
57 void Flush() { if (inRecord()) EmitRecord(); }
61 inline bool inRecord() { return Record.size() > 0; }
62 unsigned getPtrId(const void* ptr);
65 } // end namespace llvm