aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-10-26 20:23:27 +0000
committerTed Kremenek <kremenek@apple.com>2007-10-26 20:23:27 +0000
commit6a13dfdc6da8afa6eec20627e8315a9d77905d61 (patch)
tree3758f5b7fb1f0798ddaba897c187a49255e51930 /include/llvm/Bitcode
parentf1fc54f9516b1a6729bfaf70c543aa61b1b15123 (diff)
Added default implementation of SerializeTrait<> that dispatches to
calling member functions of the target type to perform type-specific serialization. Added version of ReadPtr that allows passing references to uintptr_t (useful for smart pointers). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43396 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r--include/llvm/Bitcode/Deserialize.h4
-rw-r--r--include/llvm/Bitcode/Serialization.h22
2 files changed, 25 insertions, 1 deletions
diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h
index 6eaba51ecc..4a9b06381a 100644
--- a/include/llvm/Bitcode/Deserialize.h
+++ b/include/llvm/Bitcode/Deserialize.h
@@ -99,7 +99,9 @@ public:
return x;
}
- void ReadPtr(void*& PtrRef);
+ void ReadPtr(void*& PtrRef);
+ void ReadPtr(uintptr_t& PtrRef) { ReadPtr(reinterpret_cast<void*&>(PtrRef)); }
+
void RegisterPtr(unsigned PtrId, void* Ptr);
diff --git a/include/llvm/Bitcode/Serialization.h b/include/llvm/Bitcode/Serialization.h
index 76aadb2342..1923bb4bd3 100644
--- a/include/llvm/Bitcode/Serialization.h
+++ b/include/llvm/Bitcode/Serialization.h
@@ -19,6 +19,28 @@
namespace llvm {
+/// SerializeTrait - SerializeTrait bridges between the Serializer/Deserializer
+/// and the functions that serialize objects of specific types. The default
+/// behavior is to call static methods of the class for the object being
+/// serialized, but this behavior can be changed by specializing this
+/// template. Classes only need to implement the methods corresponding
+/// to the serialization scheme they want to support. For example, "Read"
+/// and "ReadVal" correspond to different deserialization schemes which make
+/// sense for different types; a class need only implement one of them.
+/// Serialization and deserialization of pointers are specially handled
+/// by the Serializer and Deserializer using the EmitOwnedPtr, etc. methods.
+/// To serialize the actual object referred to by a pointer, the class
+/// of the object either must implement the methods called by the default
+/// behavior of SerializeTrait, or specialize SerializeTrait. This latter
+/// is useful when one cannot add methods to an existing class (for example).
+template <typename T>
+struct SerializeTrait {
+ static inline void Emit(Serializer& S, const T& X) { X.Emit(S); }
+ static inline void Read(Deserializer& D, T& X) { X.Read(D); }
+ static inline T ReadVal(Deserializer& D) { T::ReadVal(D); }
+ static inline T* Materialize(Deserializer& D) { T::Materialize(D); }
+};
+
#define SERIALIZE_INT_TRAIT(TYPE)\
template <> struct SerializeTrait<TYPE> {\
static void Emit(Serializer& S, TYPE X);\