[llvm-commits] [llvm] r43828 - in /llvm/trunk: include/llvm/Bitcode/Deserialize.h include/llvm/Bitcode/Serialization.h include/llvm/Bitcode/Serialize.h lib/Bitcode/Reader/Deserialize.cpp lib/Bitcode/Writer/Serialize.cpp
Ted Kremenek
kremenek at apple.com
Wed Nov 7 10:24:34 PST 2007
Author: kremenek
Date: Wed Nov 7 12:24:34 2007
New Revision: 43828
URL: http://llvm.org/viewvc/llvm-project?rev=43828&view=rev
Log:
Implemented serialization of signed integers.
Modified:
llvm/trunk/include/llvm/Bitcode/Deserialize.h
llvm/trunk/include/llvm/Bitcode/Serialization.h
llvm/trunk/include/llvm/Bitcode/Serialize.h
llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp
llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
Modified: llvm/trunk/include/llvm/Bitcode/Deserialize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Deserialize.h?rev=43828&r1=43827&r2=43828&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Deserialize.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Deserialize.h Wed Nov 7 12:24:34 2007
@@ -95,6 +95,8 @@
~Deserializer();
uint64_t ReadInt();
+ int64_t ReadSInt();
+
bool ReadBool() {
return ReadInt() ? true : false;
}
Modified: llvm/trunk/include/llvm/Bitcode/Serialization.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Serialization.h?rev=43828&r1=43827&r2=43828&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Serialization.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Serialization.h Wed Nov 7 12:24:34 2007
@@ -50,6 +50,11 @@
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
Modified: llvm/trunk/include/llvm/Bitcode/Serialize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Serialize.h?rev=43828&r1=43827&r2=43828&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Serialize.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Serialize.h Wed Nov 7 12:24:34 2007
@@ -37,7 +37,9 @@
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);
Modified: llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp?rev=43828&r1=43827&r2=43828&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp Wed Nov 7 12:24:34 2007
@@ -105,6 +105,12 @@
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 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)
Modified: llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/Serialize.cpp?rev=43828&r1=43827&r2=43828&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/Serialize.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/Serialize.cpp Wed Nov 7 12:24:34 2007
@@ -48,11 +48,18 @@
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 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)
More information about the llvm-commits
mailing list