2007-10-24 19:06:40 +00:00
|
|
|
//==- Serialize.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 the interface for generic object serialization to
|
|
|
|
// LLVM bitcode.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_BITCODE_SERIALIZE_OUTPUT
|
|
|
|
#define LLVM_BITCODE_SERIALIZE_OUTPUT
|
|
|
|
|
|
|
|
#include "llvm/Bitcode/Serialization.h"
|
|
|
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2007-10-25 00:10:21 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-10-24 19:06:40 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Serializer {
|
|
|
|
BitstreamWriter& Stream;
|
|
|
|
SmallVector<uint64_t,10> Record;
|
|
|
|
bool inBlock;
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-31 18:23:21 +00:00
|
|
|
typedef DenseMap<const void*,unsigned> MapTy;
|
2007-10-25 00:10:21 +00:00
|
|
|
MapTy PtrMap;
|
|
|
|
|
2007-10-24 19:06:40 +00:00
|
|
|
public:
|
|
|
|
Serializer(BitstreamWriter& stream, unsigned BlockID = 0);
|
|
|
|
~Serializer();
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
|
|
|
|
|
|
|
|
void EmitInt(unsigned X);
|
|
|
|
void EmitBool(bool X) { EmitInt(X); }
|
|
|
|
void EmitCStr(const char* beg, const char* end);
|
2007-10-25 00:10:21 +00:00
|
|
|
void EmitCStr(const char* cstr);
|
|
|
|
|
2007-10-31 18:23:21 +00:00
|
|
|
void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void EmitRef(const T& ref) { EmitPtr(&ref); }
|
2007-10-25 00:10:21 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void EmitOwnedPtr(T* ptr) {
|
|
|
|
EmitPtr(ptr);
|
2007-10-25 18:42:52 +00:00
|
|
|
if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
|
2007-10-25 00:10:21 +00:00
|
|
|
}
|
2007-10-24 19:06:40 +00:00
|
|
|
|
|
|
|
void Flush() { if (inRecord()) EmitRecord(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void EmitRecord();
|
2007-10-25 00:10:21 +00:00
|
|
|
inline bool inRecord() { return Record.size() > 0; }
|
2007-10-31 18:23:21 +00:00
|
|
|
unsigned getPtrId(const void* ptr);
|
2007-10-24 19:06:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|