Rename some GC classes so that their roll will hopefully be clearer.
[oota-llvm.git] / include / llvm / Bitcode / Serialize.h
index 60d9cb2c992d39054e00823efcf3445e7cf9ef56..eae9e7cdc8918ffa796869918c0e64e582640064 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Ted Kremenek and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -31,30 +31,45 @@ class Serializer {
   MapTy PtrMap;
   
 public:
-  Serializer(BitstreamWriter& stream);
+  explicit Serializer(BitstreamWriter& stream);
   ~Serializer();
+
+  //==------------------------------------------------==//
+  // Template-based dispatch to emit arbitrary types.
+  //==------------------------------------------------==//
   
-  template <typename T>
+  template <typename T> 
   inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
   
+  //==------------------------------------------------==//
+  // Methods to emit primitive types.
+  //==------------------------------------------------==//  
+  
   void EmitInt(uint64_t X);
   void EmitSInt(int64_t X);
   
-  void EmitBool(bool X) { EmitInt(X); }
+  inline void EmitBool(bool X) { EmitInt(X); }
   void EmitCStr(const char* beg, const char* end);
   void EmitCStr(const char* cstr);
   
   void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
   
   template <typename T>
-  void EmitRef(const T& ref) { EmitPtr(&ref); }
+  inline void EmitRef(const T& ref) { EmitPtr(&ref); }
   
+  // Emit a pointer and the object pointed to.  (This has no relation to the
+  // OwningPtr<> class.)
   template <typename T>
-  void EmitOwnedPtr(T* ptr) {
+  inline void EmitOwnedPtr(T* ptr) {
     EmitPtr(ptr);
     if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
   }
   
+  
+  //==------------------------------------------------==//
+  // Batch emission of pointers.
+  //==------------------------------------------------==//
+    
   template <typename T1, typename T2>
   void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
     EmitPtr(p1);
@@ -124,6 +139,61 @@ public:
     if (p2) SerializeTrait<T2>::Emit(*this,*p2);
     if (p3) SerializeTrait<T3>::Emit(*this,*p3);
   }
+  
+  //==------------------------------------------------==//
+  // Emitter Functors
+  //==------------------------------------------------==//
+  
+  template <typename T>
+  struct Emitter0 {
+    Serializer& S;    
+    Emitter0(Serializer& s) : S(s) {}
+    void operator()(const T& x) const {
+      SerializeTrait<T>::Emit(S,x);
+    }
+  };
+  
+  template <typename T, typename Arg1>
+  struct Emitter1 {
+    Serializer& S;
+    Arg1 A1;
+    
+    Emitter1(Serializer& s, Arg1 a1) : S(s), A1(a1) {}
+    void operator()(const T& x) const {
+      SerializeTrait<T>::Emit(S,x,A1);
+    }
+  };
+  
+  template <typename T, typename Arg1, typename Arg2>
+  struct Emitter2 {
+    Serializer& S;
+    Arg1 A1;
+    Arg2 A2;
+    
+    Emitter2(Serializer& s, Arg1 a1, Arg2 a2) : S(s), A1(a1), A2(a2) {}
+    void operator()(const T& x) const {
+      SerializeTrait<T>::Emit(S,x,A1,A2);
+    }
+  };
+  
+  template <typename T>
+  Emitter0<T> MakeEmitter() {
+    return Emitter0<T>(*this);
+  }
+  
+  template <typename T, typename Arg1>
+  Emitter1<T,Arg1> MakeEmitter(Arg1 a1) {
+    return Emitter1<T,Arg1>(*this,a1);
+  }
+  
+  template <typename T, typename Arg1, typename Arg2>
+  Emitter2<T,Arg1,Arg2> MakeEmitter(Arg1 a1, Arg2 a2) {
+    return Emitter2<T,Arg1,Arg2>(*this,a1,a2);
+  }
+  
+  //==------------------------------------------------==//
+  // Misc. query and block/record manipulation methods.
+  //==------------------------------------------------==//  
     
   bool isRegistered(const void* p) const;