aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-07 18:24:34 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-07 18:24:34 +0000
commit2e6452ca0ce5b5e5612059cc13c7ec28cc30e6ec (patch)
treefda98341bd5fb79b154394cfe27f87944eeda1dd /lib/Bitcode
parent29121848b912b1e062760e5d14c6fbec63b16d9b (diff)
downloadexternal_llvm-2e6452ca0ce5b5e5612059cc13c7ec28cc30e6ec.zip
external_llvm-2e6452ca0ce5b5e5612059cc13c7ec28cc30e6ec.tar.gz
external_llvm-2e6452ca0ce5b5e5612059cc13c7ec28cc30e6ec.tar.bz2
Implemented serialization of signed integers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43828 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/Deserialize.cpp15
-rw-r--r--lib/Bitcode/Writer/Serialize.cpp17
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp
index d4ed26b..99cb5d2 100644
--- a/lib/Bitcode/Reader/Deserialize.cpp
+++ b/lib/Bitcode/Reader/Deserialize.cpp
@@ -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)
diff --git a/lib/Bitcode/Writer/Serialize.cpp b/lib/Bitcode/Writer/Serialize.cpp
index 4395b90..b97462b 100644
--- a/lib/Bitcode/Writer/Serialize.cpp
+++ b/lib/Bitcode/Writer/Serialize.cpp
@@ -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)