aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
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)