2007-10-24 21:06:40 +02:00
|
|
|
//==- Serialization.h - Generic Object Serialization to Bitcode ---*- C++ -*-=//
|
2007-10-23 23:29:33 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-23 23:29:33 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-10-25 20:19:29 +02:00
|
|
|
// This file defines traits for primitive types used for both object
|
|
|
|
// serialization and deserialization.
|
2007-10-23 23:29:33 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_BITCODE_SERIALIZE
|
|
|
|
#define LLVM_BITCODE_SERIALIZE
|
|
|
|
|
2007-10-25 20:19:29 +02:00
|
|
|
#include "llvm/Bitcode/SerializationFwd.h"
|
2007-10-23 23:29:33 +02:00
|
|
|
|
2007-10-25 20:19:29 +02:00
|
|
|
namespace llvm {
|
2007-10-23 23:29:33 +02:00
|
|
|
|
2007-10-26 22:23:27 +02:00
|
|
|
/// 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); }
|
2007-11-13 01:25:08 +01:00
|
|
|
static inline T* Create(Deserializer& D) { return T::Create(D); }
|
2008-04-03 18:44:37 +02:00
|
|
|
|
|
|
|
template <typename Arg1>
|
|
|
|
static inline T* Create(Deserializer& D, Arg1& arg1) {
|
|
|
|
return T::Create(D, arg1);
|
|
|
|
}
|
2007-10-26 22:23:27 +02:00
|
|
|
};
|
|
|
|
|
2007-10-24 21:06:40 +02:00
|
|
|
#define SERIALIZE_INT_TRAIT(TYPE)\
|
|
|
|
template <> struct SerializeTrait<TYPE> {\
|
|
|
|
static void Emit(Serializer& S, TYPE X);\
|
2007-11-01 23:23:34 +01:00
|
|
|
static void Read(Deserializer& S, TYPE& X); };
|
2007-10-23 23:29:33 +02:00
|
|
|
|
2007-10-24 21:06:40 +02:00
|
|
|
SERIALIZE_INT_TRAIT(bool)
|
|
|
|
SERIALIZE_INT_TRAIT(unsigned char)
|
|
|
|
SERIALIZE_INT_TRAIT(unsigned short)
|
|
|
|
SERIALIZE_INT_TRAIT(unsigned int)
|
|
|
|
SERIALIZE_INT_TRAIT(unsigned long)
|
2007-11-07 19:24:34 +01:00
|
|
|
|
|
|
|
SERIALIZE_INT_TRAIT(signed char)
|
|
|
|
SERIALIZE_INT_TRAIT(signed short)
|
|
|
|
SERIALIZE_INT_TRAIT(signed int)
|
|
|
|
SERIALIZE_INT_TRAIT(signed long)
|
2007-10-23 23:29:33 +02:00
|
|
|
|
2007-10-24 21:06:40 +02:00
|
|
|
#undef SERIALIZE_INT_TRAIT
|
2007-10-24 00:17:03 +02:00
|
|
|
|
2007-10-23 23:29:33 +02:00
|
|
|
} // end namespace llvm
|
2007-10-24 21:06:40 +02:00
|
|
|
|
2007-10-23 23:29:33 +02:00
|
|
|
#endif
|