blob: d73a92c59a018c9e760bf83a5c7dc5464f35b7d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
//==- Serialize.h - 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 interface for generic object serialization to
// LLVM bitcode.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BITCODE_SERIALIZE_OUTPUT
#define LLVM_BITCODE_SERIALIZE_OUTPUT
#include "llvm/Bitcode/Serialization.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseMap.h"
namespace llvm {
class Serializer {
BitstreamWriter& Stream;
SmallVector<uint64_t,10> Record;
unsigned BlockLevel;
typedef DenseMap<const void*,unsigned> MapTy;
MapTy PtrMap;
public:
Serializer(BitstreamWriter& stream);
~Serializer();
template <typename T>
inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
void EmitInt(unsigned X);
void EmitBool(bool X) { EmitInt(X); }
void EmitCStr(const char* beg, const char* end);
void EmitCStr(const char* cstr);
void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
template <typename T>
void EmitRef(const T& ref) { EmitPtr(&ref); }
template <typename T>
void EmitOwnedPtr(T* ptr) {
EmitPtr(ptr);
if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
}
void FlushRecord() { if (inRecord()) EmitRecord(); }
void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
void ExitBlock();
private:
void EmitRecord();
inline bool inRecord() { return Record.size() > 0; }
unsigned getPtrId(const void* ptr);
};
} // end namespace llvm
#endif
|