blob: 6ee09aaa34465d85ca2bd33d0dbd5915dda725fb (
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
69
70
71
72
73
74
|
//=- Deserialize.h - Generic Object Deserialization from 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 deserialization from
// LLVM bitcode.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BITCODE_SERIALIZE_INPUT
#define LLVM_BITCODE_SERIALIZE_INPUT
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/Serialization.h"
#include <vector>
namespace llvm {
class Deserializer {
BitstreamReader& Stream;
SmallVector<uint64_t,10> Record;
unsigned RecIdx;
public:
Deserializer(BitstreamReader& stream);
~Deserializer();
template <typename T>
inline T& Read(T& X) {
SerializeTrait<T>::Read(*this,X);
return X;
}
template <typename T>
inline T* Materialize() {
return SerializeTrait<T>::Materialize(*this);
}
uint64_t ReadInt();
bool ReadBool() { return ReadInt() ? true : false; }
// FIXME: Substitute a better implementation which calculates the minimum
// number of bits needed to serialize the enum.
template <typename EnumT>
EnumT ReadEnum(unsigned MinVal, unsigned MaxVal) {
return static_cast<EnumT>(ReadInt(32));
}
char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
private:
void ReadRecord();
inline bool inRecord() {
if (Record.size() > 0) {
if (RecIdx >= Record.size()) {
RecIdx = 0;
Record.clear();
return false;
}
else return true;
}
else return false;
}
};
} // end namespace llvm
#endif
|