llvm.org GIT mirror llvm / 2e6452c
Implemented serialization of signed integers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43828 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
5 changed file(s) with 41 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
9494 ~Deserializer();
9595
9696 uint64_t ReadInt();
97 int64_t ReadSInt();
98
9799 bool ReadBool() {
98100 return ReadInt() ? true : false;
99101 }
4949 SERIALIZE_INT_TRAIT(unsigned short)
5050 SERIALIZE_INT_TRAIT(unsigned int)
5151 SERIALIZE_INT_TRAIT(unsigned long)
52
53 SERIALIZE_INT_TRAIT(signed char)
54 SERIALIZE_INT_TRAIT(signed short)
55 SERIALIZE_INT_TRAIT(signed int)
56 SERIALIZE_INT_TRAIT(signed long)
5257
5358 #undef SERIALIZE_INT_TRAIT
5459
3636 template
3737 inline void Emit(const T& X) { SerializeTrait::Emit(*this,X); }
3838
39 void EmitInt(unsigned X);
39 void EmitInt(uint64_t X);
40 void EmitSInt(int64_t X);
41
4042 void EmitBool(bool X) { EmitInt(X); }
4143 void EmitCStr(const char* beg, const char* end);
4244 void EmitCStr(const char* cstr);
104104 return Record[RecIdx++];
105105 }
106106
107 int64_t Deserializer::ReadSInt() {
108 uint64_t x = ReadInt();
109 int64_t magnitude = x >> 1;
110 return x & 0x1 ? -magnitude : magnitude;
111 }
112
107113 char* Deserializer::ReadCStr(char* cstr, unsigned MaxLen, bool isNullTerm) {
108114 if (cstr == NULL)
109115 MaxLen = 0; // Zero this just in case someone does something funny.
225231 INT_READ(unsigned short)
226232 INT_READ(unsigned int)
227233 INT_READ(unsigned long)
234
235 #define SINT_READ(TYPE)\
236 void SerializeTrait::Read(Deserializer& D, TYPE& X) {\
237 X = (TYPE) D.ReadSInt(); }
238
239 INT_READ(signed char)
240 INT_READ(signed short)
241 INT_READ(signed int)
242 INT_READ(signed long)
4747 Stream.ExitBlock();
4848 }
4949
50 void Serializer::EmitInt(unsigned X) {
50 void Serializer::EmitInt(uint64_t X) {
5151 assert (BlockLevel > 0);
5252 Record.push_back(X);
53 }
54
55 void Serializer::EmitSInt(int64_t X) {
56 if (X >= 0)
57 EmitInt(X << 1);
58 else
59 EmitInt((-X << 1) | 1);
5360 }
5461
5562 void Serializer::EmitCStr(const char* s, const char* end) {
9097 INT_EMIT(unsigned short)
9198 INT_EMIT(unsigned int)
9299 INT_EMIT(unsigned long)
100
101 #define SINT_EMIT(TYPE)\
102 void SerializeTrait::Emit(Serializer&S, TYPE X) { S.EmitSInt(X); }
103
104 SINT_EMIT(signed char)
105 SINT_EMIT(signed short)
106 SINT_EMIT(signed int)
107 SINT_EMIT(signed long)