mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-27 23:13:27 +00:00
Implemented serialization of signed integers.
llvm-svn: 43828
This commit is contained in:
parent
5b53732be2
commit
f4bc385d1b
@ -95,6 +95,8 @@ public:
|
||||
~Deserializer();
|
||||
|
||||
uint64_t ReadInt();
|
||||
int64_t ReadSInt();
|
||||
|
||||
bool ReadBool() {
|
||||
return ReadInt() ? true : false;
|
||||
}
|
||||
|
@ -50,6 +50,11 @@ SERIALIZE_INT_TRAIT(unsigned char)
|
||||
SERIALIZE_INT_TRAIT(unsigned short)
|
||||
SERIALIZE_INT_TRAIT(unsigned int)
|
||||
SERIALIZE_INT_TRAIT(unsigned long)
|
||||
|
||||
SERIALIZE_INT_TRAIT(signed char)
|
||||
SERIALIZE_INT_TRAIT(signed short)
|
||||
SERIALIZE_INT_TRAIT(signed int)
|
||||
SERIALIZE_INT_TRAIT(signed long)
|
||||
|
||||
#undef SERIALIZE_INT_TRAIT
|
||||
|
||||
|
@ -37,7 +37,9 @@ public:
|
||||
template <typename T>
|
||||
inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
|
||||
|
||||
void EmitInt(unsigned X);
|
||||
void EmitInt(uint64_t X);
|
||||
void EmitSInt(int64_t X);
|
||||
|
||||
void EmitBool(bool X) { EmitInt(X); }
|
||||
void EmitCStr(const char* beg, const char* end);
|
||||
void EmitCStr(const char* cstr);
|
||||
|
@ -105,6 +105,12 @@ uint64_t Deserializer::ReadInt() {
|
||||
return Record[RecIdx++];
|
||||
}
|
||||
|
||||
int64_t Deserializer::ReadSInt() {
|
||||
uint64_t x = ReadInt();
|
||||
int64_t magnitude = x >> 1;
|
||||
return x & 0x1 ? -magnitude : magnitude;
|
||||
}
|
||||
|
||||
char* Deserializer::ReadCStr(char* cstr, unsigned MaxLen, bool isNullTerm) {
|
||||
if (cstr == NULL)
|
||||
MaxLen = 0; // Zero this just in case someone does something funny.
|
||||
@ -226,3 +232,12 @@ INT_READ(unsigned char)
|
||||
INT_READ(unsigned short)
|
||||
INT_READ(unsigned int)
|
||||
INT_READ(unsigned long)
|
||||
|
||||
#define SINT_READ(TYPE)\
|
||||
void SerializeTrait<TYPE>::Read(Deserializer& D, TYPE& X) {\
|
||||
X = (TYPE) D.ReadSInt(); }
|
||||
|
||||
INT_READ(signed char)
|
||||
INT_READ(signed short)
|
||||
INT_READ(signed int)
|
||||
INT_READ(signed long)
|
||||
|
@ -48,11 +48,18 @@ void Serializer::ExitBlock() {
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
||||
void Serializer::EmitInt(unsigned X) {
|
||||
void Serializer::EmitInt(uint64_t X) {
|
||||
assert (BlockLevel > 0);
|
||||
Record.push_back(X);
|
||||
}
|
||||
|
||||
void Serializer::EmitSInt(int64_t X) {
|
||||
if (X >= 0)
|
||||
EmitInt(X << 1);
|
||||
else
|
||||
EmitInt((-X << 1) | 1);
|
||||
}
|
||||
|
||||
void Serializer::EmitCStr(const char* s, const char* end) {
|
||||
Record.push_back(end - s);
|
||||
|
||||
@ -91,3 +98,11 @@ INT_EMIT(unsigned char)
|
||||
INT_EMIT(unsigned short)
|
||||
INT_EMIT(unsigned int)
|
||||
INT_EMIT(unsigned long)
|
||||
|
||||
#define SINT_EMIT(TYPE)\
|
||||
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitSInt(X); }
|
||||
|
||||
SINT_EMIT(signed char)
|
||||
SINT_EMIT(signed short)
|
||||
SINT_EMIT(signed int)
|
||||
SINT_EMIT(signed long)
|
||||
|
Loading…
x
Reference in New Issue
Block a user