Split Serialization.h into separate headers: Serialize.h and
[oota-llvm.git] / include / llvm / Bitcode / Serialize.h
1 //==- Serialize.h - 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 interface for generic object serialization to
11 // LLVM bitcode.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_BITCODE_SERIALIZE_OUTPUT
16 #define LLVM_BITCODE_SERIALIZE_OUTPUT
17
18 #include "llvm/Bitcode/Serialization.h"
19 #include "llvm/Bitcode/BitstreamWriter.h"
20 #include "llvm/ADT/SmallVector.h"
21
22 namespace llvm {
23
24 class Serializer {
25   BitstreamWriter& Stream;
26   SmallVector<uint64_t,10> Record;
27   bool inBlock;
28 public:
29   Serializer(BitstreamWriter& stream, unsigned BlockID = 0);
30   ~Serializer();
31   
32   template <typename T>
33   inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
34   
35   void EmitInt(unsigned X);
36   void EmitBool(bool X) { EmitInt(X); }
37   void EmitCStr(const char* beg, const char* end);
38   void EmitCStr(const char* cstr);    
39
40   void Flush() { if (inRecord()) EmitRecord(); }
41   
42 private:
43   void EmitRecord();
44   inline bool inRecord() { return Record.size() > 0; }  
45 };
46
47 } // end namespace llvm
48 #endif