mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-18 10:31:57 +00:00
0a6d98e10e
Added detection of end-of-stream in deserializer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43736 91177308-0d34-0410-b5e6-96231b3b80d8
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
//==- 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"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
namespace llvm {
|
|
|
|
class Serializer {
|
|
BitstreamWriter& Stream;
|
|
SmallVector<uint64_t,10> Record;
|
|
unsigned BlockLevel;
|
|
|
|
typedef DenseMap<const void*,unsigned> MapTy;
|
|
MapTy PtrMap;
|
|
|
|
public:
|
|
Serializer(BitstreamWriter& stream, unsigned BlockID = 8);
|
|
|
|
~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);
|
|
void EmitCStr(const char* cstr);
|
|
|
|
void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
|
|
|
|
template <typename T>
|
|
void EmitRef(const T& ref) { EmitPtr(&ref); }
|
|
|
|
template <typename T>
|
|
void EmitOwnedPtr(T* ptr) {
|
|
EmitPtr(ptr);
|
|
if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
|
|
}
|
|
|
|
void Flush() { if (inRecord()) EmitRecord(); }
|
|
|
|
void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
|
|
void ExitBlock();
|
|
|
|
private:
|
|
void EmitRecord();
|
|
inline bool inRecord() { return Record.size() > 0; }
|
|
unsigned getPtrId(const void* ptr);
|
|
};
|
|
|
|
} // end namespace llvm
|
|
#endif
|