Don't attribute in file headers anymore. See llvmdev for the
[oota-llvm.git] / include / llvm / Bitcode / Serialization.h
1 //==- Serialization.h - Generic Object Serialization to Bitcode ---*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines traits for primitive types used for both object
11 // serialization and deserialization.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_BITCODE_SERIALIZE
16 #define LLVM_BITCODE_SERIALIZE
17
18 #include "llvm/Bitcode/SerializationFwd.h"
19
20 namespace llvm {
21   
22 /// SerializeTrait - SerializeTrait bridges between the Serializer/Deserializer
23 ///  and the functions that serialize objects of specific types.  The default
24 ///  behavior is to call static methods of the class for the object being
25 ///  serialized, but this behavior can be changed by specializing this
26 ///  template.  Classes only need to implement the methods corresponding
27 ///  to the serialization scheme they want to support.  For example, "Read"
28 ///  and "ReadVal" correspond to different deserialization schemes which make
29 ///  sense for different types; a class need only implement one of them.
30 ///  Serialization and deserialization of pointers are specially handled
31 ///  by the Serializer and Deserializer using the EmitOwnedPtr, etc. methods.
32 ///  To serialize the actual object referred to by a pointer, the class
33 ///  of the object either must implement the methods called by the default
34 ///  behavior of SerializeTrait, or specialize SerializeTrait.  This latter
35 ///  is useful when one cannot add methods to an existing class (for example).
36 template <typename T>
37 struct SerializeTrait {
38   static inline void Emit(Serializer& S, const T& X) { X.Emit(S); }
39   static inline void Read(Deserializer& D, T& X) { X.Read(D); }
40   static inline T* Create(Deserializer& D) { return T::Create(D); }
41 };
42
43 #define SERIALIZE_INT_TRAIT(TYPE)\
44 template <> struct SerializeTrait<TYPE> {\
45   static void Emit(Serializer& S, TYPE X);\
46   static void Read(Deserializer& S, TYPE& X); };
47
48 SERIALIZE_INT_TRAIT(bool)
49 SERIALIZE_INT_TRAIT(unsigned char)
50 SERIALIZE_INT_TRAIT(unsigned short)
51 SERIALIZE_INT_TRAIT(unsigned int)
52 SERIALIZE_INT_TRAIT(unsigned long)
53   
54 SERIALIZE_INT_TRAIT(signed char)
55 SERIALIZE_INT_TRAIT(signed short)
56 SERIALIZE_INT_TRAIT(signed int)
57 SERIALIZE_INT_TRAIT(signed long)
58
59 #undef SERIALIZE_INT_TRAIT
60   
61 } // end namespace llvm
62
63 #endif