diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-12-18 18:25:55 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-12-18 18:25:55 +0000 |
commit | b955939c2d6d704e117e4aa46e2960a9b7f34921 (patch) | |
tree | 89a6e9c717f93f75992f414c05cffc8cf7509280 /include/llvm/Bitcode | |
parent | d079b4ea0a2f1a06b6727b6f1d1f7db94dfb3386 (diff) | |
download | external_llvm-b955939c2d6d704e117e4aa46e2960a9b7f34921.zip external_llvm-b955939c2d6d704e117e4aa46e2960a9b7f34921.tar.gz external_llvm-b955939c2d6d704e117e4aa46e2960a9b7f34921.tar.bz2 |
Added some sectioning comments to Serialize.h.
Added additional serialization functors for use with std::foreach.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45162 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r-- | include/llvm/Bitcode/Serialize.h | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/include/llvm/Bitcode/Serialize.h b/include/llvm/Bitcode/Serialize.h index b0b39de..5e6eaa0 100644 --- a/include/llvm/Bitcode/Serialize.h +++ b/include/llvm/Bitcode/Serialize.h @@ -33,39 +33,41 @@ class Serializer { public: 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); } - template <typename T> - struct Emitter { - Serializer &S; - - Emitter(Serializer& s) : S(s) {} - void operator()(const T& x) const { S.Emit(x); } - }; - - template <typename T> - Emitter<T> MakeEmitter() { return Emitter<T>(*this); } + //==------------------------------------------------==// + // 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); } 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); @@ -135,6 +137,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; |