Added "ReadEnum" and "WriteEnum" to serialization classes.
authorTed Kremenek <kremenek@apple.com>
Tue, 23 Oct 2007 22:17:03 +0000 (22:17 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 23 Oct 2007 22:17:03 +0000 (22:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43265 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/Serialization.h

index 2d633115a2a4069f0c0287a4319bd7d19d3da53b..356a75c104bc303216b1411431cb3e1da408a16e 100644 (file)
@@ -35,7 +35,12 @@ public:
   template <typename T>
   inline void Emit(const T& X) { SerializeTrait<T>::Serialize(*this,X); }
     
-  void EmitInt(unsigned X, unsigned bits);  
+  void EmitInt(unsigned X, unsigned bits);
+  
+  // FIXME: Substitute a better implementation which calculates the minimum
+  // number of bits needed to serialize the enum.
+  void EmitEnum(unsigned X, unsigned MinVal, unsigned MaxVal) { EmitInt(X,32); }
+  
   void EmitCString(const char* cstr);
 
   void Flush() { if (inRecord()) EmitRecord(); }
@@ -55,7 +60,7 @@ public:
   ~Deserializer();
 
   template <typename T>
-  inline void Read(T& X) { SerializeTrait<T>::Deserialize(*this,X); }
+  inline T& Read(T& X) { SerializeTrait<T>::Deserialize(*this,X); return X; }
 
   template <typename T>
   inline T* Materialize() {
@@ -67,6 +72,13 @@ public:
   uint64_t ReadInt(unsigned bits = 32);
   bool ReadBool() { return ReadInt(1); }
   
+  // FIXME: Substitute a better implementation which calculates the minimum
+  // number of bits needed to serialize the enum.
+  template <typename EnumT>
+  EnumT ReadEnum(unsigned MinVal, unsigned MaxVal) { 
+    return static_cast<EnumT>(ReadInt(32));
+  }
+  
   char* ReadCString(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
   void ReadCString(std::vector<char>& buff, bool isNullTerm=false);
   
@@ -97,7 +109,6 @@ struct SerializeIntTrait {
     X = (uintty) S.ReadInt(Bits);
   }
 };
-
   
 template <> struct SerializeTrait<bool>
   : public SerializeIntTrait<bool,1> {};
@@ -111,5 +122,7 @@ template <> struct SerializeTrait<short>
 template <> struct SerializeTrait<unsigned>
   : public SerializeIntTrait<unsigned,32> {};
 
+  
+  
 } // end namespace llvm
 #endif