mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-16 11:30:51 +00:00
ff37ccc570
Deserializer. There were issues with Visual C++ barfing when instantiating SerializeTrait<T> when "T" was an abstract class AND SerializeTrait<T>::ReadVal was *never* called: template <typename T> struct SerializeTrait { <SNIP> static inline T ReadVal(Deserializer& D) { T::ReadVal(D); } <SNIP> }; Visual C++ would complain about "T" being an abstract class, even though ReadVal was never instantiated (although one of the other member functions were). Removing this from the trait is not a big deal. It was used hardly ever, and users who want "read-by-value" deserialization can simply call the appropriate methods directly instead of relying on trait-based-dispatch. The trait dispatch for serialization/deserialization is simply sugar in many cases (like this one). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43624 91177308-0d34-0410-b5e6-96231b3b80d8
59 lines
2.4 KiB
C++
59 lines
2.4 KiB
C++
//==- Serialization.h - Generic Object Serialization to Bitcode ---*- C++ -*-=//
|
|
//
|
|
// 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 defines traits for primitive types used for both object
|
|
// serialization and deserialization.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_BITCODE_SERIALIZE
|
|
#define LLVM_BITCODE_SERIALIZE
|
|
|
|
#include "llvm/Bitcode/SerializationFwd.h"
|
|
|
|
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* Materialize(Deserializer& D) { return T::Materialize(D); }
|
|
};
|
|
|
|
#define SERIALIZE_INT_TRAIT(TYPE)\
|
|
template <> struct SerializeTrait<TYPE> {\
|
|
static void Emit(Serializer& S, TYPE X);\
|
|
static void Read(Deserializer& S, TYPE& X); };
|
|
|
|
SERIALIZE_INT_TRAIT(bool)
|
|
SERIALIZE_INT_TRAIT(unsigned char)
|
|
SERIALIZE_INT_TRAIT(unsigned short)
|
|
SERIALIZE_INT_TRAIT(unsigned int)
|
|
SERIALIZE_INT_TRAIT(unsigned long)
|
|
|
|
#undef SERIALIZE_INT_TRAIT
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|