Remove derelict serialization code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92374 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2009-12-31 23:40:17 +00:00
parent 3523993451
commit 43afbce8ba
11 changed files with 1 additions and 987 deletions

View File

@ -1,68 +0,0 @@
//==- Serialization.h - Generic Object Serialization to Bitcode ---*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file 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* Create(Deserializer& D) { return T::Create(D); }
template <typename Arg1>
static inline T* Create(Deserializer& D, Arg1& arg1) {
return T::Create(D, arg1);
}
};
#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)
SERIALIZE_INT_TRAIT(signed char)
SERIALIZE_INT_TRAIT(signed short)
SERIALIZE_INT_TRAIT(signed int)
SERIALIZE_INT_TRAIT(signed long)
#undef SERIALIZE_INT_TRAIT
} // end namespace llvm
#endif

View File

@ -1,27 +0,0 @@
//==- SerializationFwd.h - Forward references for Serialization ---*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file provides forward references for bitcode object serialization.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BITCODE_SERIALIZE_FWD
#define LLVM_BITCODE_SERIALIZE_FWD
namespace llvm {
class Serializer;
class Deserializer;
template <typename T> struct SerializeTrait;
typedef unsigned SerializedPtrID;
} // end namespace llvm
#endif

View File

@ -1,211 +0,0 @@
//==- Serialize.h - Generic Object Serialization to Bitcode -------*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file 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:
explicit Serializer(BitstreamWriter& stream);
~Serializer();
//==------------------------------------------------==//
// Template-based dispatch to emit arbitrary types.
//==------------------------------------------------==//
template <typename T>
inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
//==------------------------------------------------==//
// Methods to emit primitive types.
//==------------------------------------------------==//
void EmitInt(uint64_t X);
void EmitSInt(int64_t 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>
inline void EmitRef(const T& ref) { EmitPtr(&ref); }
// Emit a pointer and the object pointed to. (This has no relation to the
// OwningPtr<> class.)
template <typename T>
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);
EmitPtr(p2);
if (p1) SerializeTrait<T1>::Emit(*this,*p1);
if (p2) SerializeTrait<T2>::Emit(*this,*p2);
}
template <typename T1, typename T2, typename T3>
void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3) {
EmitPtr(p1);
EmitPtr(p2);
EmitPtr(p3);
if (p1) SerializeTrait<T1>::Emit(*this,*p1);
if (p2) SerializeTrait<T2>::Emit(*this,*p2);
if (p3) SerializeTrait<T3>::Emit(*this,*p3);
}
template <typename T1, typename T2, typename T3, typename T4>
void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3, T4& p4) {
EmitPtr(p1);
EmitPtr(p2);
EmitPtr(p3);
EmitPtr(p4);
if (p1) SerializeTrait<T1>::Emit(*this,*p1);
if (p2) SerializeTrait<T2>::Emit(*this,*p2);
if (p3) SerializeTrait<T3>::Emit(*this,*p3);
if (p4) SerializeTrait<T4>::Emit(*this,*p4);
}
template <typename T>
void BatchEmitOwnedPtrs(unsigned NumPtrs, T* const * Ptrs) {
for (unsigned i = 0; i < NumPtrs; ++i)
EmitPtr(Ptrs[i]);
for (unsigned i = 0; i < NumPtrs; ++i)
if (Ptrs[i]) SerializeTrait<T>::Emit(*this,*Ptrs[i]);
}
template <typename T1, typename T2>
void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) {
for (unsigned i = 0; i < NumT1Ptrs; ++i)
EmitPtr(Ptrs[i]);
EmitPtr(p2);
for (unsigned i = 0; i < NumT1Ptrs; ++i)
if (Ptrs[i]) SerializeTrait<T1>::Emit(*this,*Ptrs[i]);
if (p2) SerializeTrait<T2>::Emit(*this,*p2);
}
template <typename T1, typename T2, typename T3>
void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs,
T2* p2, T3* p3) {
for (unsigned i = 0; i < NumT1Ptrs; ++i)
EmitPtr(Ptrs[i]);
EmitPtr(p2);
EmitPtr(p3);
for (unsigned i = 0; i < NumT1Ptrs; ++i)
if (Ptrs[i]) SerializeTrait<T1>::Emit(*this,*Ptrs[i]);
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;
void FlushRecord() { if (inRecord()) EmitRecord(); }
void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
void ExitBlock();
private:
void EmitRecord();
inline bool inRecord() { return Record.size() > 0; }
SerializedPtrID getPtrId(const void* ptr);
};
} // end namespace llvm
#endif

View File

@ -1,7 +1,4 @@
add_llvm_library(LLVMBitReader
BitReader.cpp
BitcodeReader.cpp
Deserialize.cpp
DeserializeAPFloat.cpp
DeserializeAPInt.cpp
)
)

View File

@ -1,450 +0,0 @@
//==- Deserialize.cpp - Generic Object Serialization to Bitcode --*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the internal methods used for object serialization.
//
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/Deserialize.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
Deserializer::Deserializer(BitstreamReader& stream)
: Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) {
StreamStart = Stream.GetCurrentBitNo();
}
Deserializer::~Deserializer() {
assert (RecIdx >= Record.size() &&
"Still scanning bitcode record when deserialization completed.");
#ifdef DEBUG_BACKPATCH
for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I)
assert (I->first.hasFinalPtr() &&
"Some pointers were not backpatched.");
#endif
}
bool Deserializer::inRecord() {
if (Record.size() > 0) {
if (RecIdx >= Record.size()) {
RecIdx = 0;
Record.clear();
AbbrevNo = 0;
return false;
}
else
return true;
}
return false;
}
bool Deserializer::AdvanceStream() {
assert (!inRecord() &&
"Cannot advance stream. Still processing a record.");
if (AbbrevNo == bitc::ENTER_SUBBLOCK ||
AbbrevNo >= bitc::UNABBREV_RECORD)
return true;
while (!Stream.AtEndOfStream()) {
uint64_t Pos = Stream.GetCurrentBitNo();
AbbrevNo = Stream.ReadCode();
switch (AbbrevNo) {
case bitc::ENTER_SUBBLOCK: {
unsigned id = Stream.ReadSubBlockID();
// Determine the extent of the block. This is useful for jumping around
// the stream. This is hack: we read the header of the block, save
// the length, and then revert the bitstream to a location just before
// the block is entered.
uint64_t BPos = Stream.GetCurrentBitNo();
Stream.ReadVBR(bitc::CodeLenWidth); // Skip the code size.
Stream.SkipToWord();
unsigned NumWords = Stream.Read(bitc::BlockSizeWidth);
Stream.JumpToBit(BPos);
BlockStack.push_back(Location(Pos,id,NumWords));
break;
}
case bitc::END_BLOCK: {
bool x = Stream.ReadBlockEnd();
assert(!x && "Error at block end."); x=x;
BlockStack.pop_back();
continue;
}
case bitc::DEFINE_ABBREV:
Stream.ReadAbbrevRecord();
continue;
default:
break;
}
return true;
}
return false;
}
void Deserializer::ReadRecord() {
while (AdvanceStream() && AbbrevNo == bitc::ENTER_SUBBLOCK) {
assert (!BlockStack.empty());
Stream.EnterSubBlock(BlockStack.back().BlockID);
AbbrevNo = 0;
}
if (Stream.AtEndOfStream())
return;
assert (Record.empty());
assert (AbbrevNo >= bitc::UNABBREV_RECORD);
RecordCode = Stream.ReadRecord(AbbrevNo,Record);
assert (Record.size() > 0);
}
void Deserializer::SkipBlock() {
assert (!inRecord());
if (AtEnd())
return;
AdvanceStream();
assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
BlockStack.pop_back();
Stream.SkipBlock();
AbbrevNo = 0;
AdvanceStream();
}
bool Deserializer::SkipToBlock(unsigned BlockID) {
assert (!inRecord());
AdvanceStream();
assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
unsigned BlockLevel = BlockStack.size();
while (!AtEnd() &&
BlockLevel == BlockStack.size() &&
getCurrentBlockID() != BlockID)
SkipBlock();
return !(AtEnd() || BlockLevel != BlockStack.size());
}
Deserializer::Location Deserializer::getCurrentBlockLocation() {
if (!inRecord())
AdvanceStream();
return BlockStack.back();
}
bool Deserializer::JumpTo(const Location& Loc) {
assert (!inRecord());
AdvanceStream();
assert (!BlockStack.empty() || AtEnd());
uint64_t LastBPos = StreamStart;
while (!BlockStack.empty()) {
LastBPos = BlockStack.back().BitNo;
// Determine of the current block contains the location of the block
// we are looking for.
if (BlockStack.back().contains(Loc)) {
// We found the enclosing block. We must first POP it off to
// destroy any accumulated context within the block scope. We then
// jump to the position of the block and enter it.
Stream.JumpToBit(LastBPos);
if (BlockStack.size() == Stream.BlockScope.size())
Stream.PopBlockScope();
BlockStack.pop_back();
AbbrevNo = 0;
AdvanceStream();
assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
Stream.EnterSubBlock(BlockStack.back().BlockID);
break;
}
// This block does not contain the block we are looking for. Pop it.
if (BlockStack.size() == Stream.BlockScope.size())
Stream.PopBlockScope();
BlockStack.pop_back();
}
// Check if we have popped our way to the outermost scope. If so,
// we need to adjust our position.
if (BlockStack.empty()) {
assert (Stream.BlockScope.empty());
Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart : LastBPos);
AbbrevNo = 0;
AdvanceStream();
}
assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
assert (!BlockStack.empty());
while (!AtEnd() && BlockStack.back() != Loc) {
if (BlockStack.back().contains(Loc)) {
Stream.EnterSubBlock(BlockStack.back().BlockID);
AbbrevNo = 0;
AdvanceStream();
continue;
}
else
SkipBlock();
}
if (AtEnd())
return false;
assert (BlockStack.back() == Loc);
return true;
}
void Deserializer::Rewind() {
while (!Stream.BlockScope.empty())
Stream.PopBlockScope();
while (!BlockStack.empty())
BlockStack.pop_back();
Stream.JumpToBit(StreamStart);
AbbrevNo = 0;
}
unsigned Deserializer::getCurrentBlockID() {
if (!inRecord())
AdvanceStream();
return BlockStack.back().BlockID;
}
unsigned Deserializer::getRecordCode() {
if (!inRecord()) {
AdvanceStream();
assert (AbbrevNo >= bitc::UNABBREV_RECORD);
ReadRecord();
}
return RecordCode;
}
bool Deserializer::FinishedBlock(Location BlockLoc) {
if (!inRecord())
AdvanceStream();
for (llvm::SmallVector<Location,8>::reverse_iterator
I=BlockStack.rbegin(), E=BlockStack.rend(); I!=E; ++I)
if (*I == BlockLoc)
return false;
return true;
}
unsigned Deserializer::getAbbrevNo() {
if (!inRecord())
AdvanceStream();
return AbbrevNo;
}
bool Deserializer::AtEnd() {
if (inRecord())
return false;
if (!AdvanceStream())
return true;
return false;
}
uint64_t Deserializer::ReadInt() {
// FIXME: Any error recovery/handling with incomplete or bad files?
if (!inRecord())
ReadRecord();
return Record[RecIdx++];
}
int64_t Deserializer::ReadSInt() {
uint64_t x = ReadInt();
int64_t magnitude = x >> 1;
return x & 0x1 ? -magnitude : magnitude;
}
char* Deserializer::ReadCStr(char* cstr, unsigned MaxLen, bool isNullTerm) {
if (cstr == NULL)
MaxLen = 0; // Zero this just in case someone does something funny.
unsigned len = ReadInt();
assert (MaxLen == 0 || (len + (isNullTerm ? 1 : 0)) <= MaxLen);
if (!cstr)
cstr = new char[len + (isNullTerm ? 1 : 0)];
assert (cstr != NULL);
for (unsigned i = 0; i < len; ++i)
cstr[i] = (char) ReadInt();
if (isNullTerm)
cstr[len] = '\0';
return cstr;
}
void Deserializer::ReadCStr(std::vector<char>& buff, bool isNullTerm,
unsigned Idx) {
unsigned len = ReadInt();
// If Idx is beyond the current before size, reduce Idx to refer to the
// element after the last element.
if (Idx > buff.size())
Idx = buff.size();
buff.reserve(len+Idx);
buff.resize(Idx);
for (unsigned i = 0; i < len; ++i)
buff.push_back((char) ReadInt());
if (isNullTerm)
buff.push_back('\0');
}
void Deserializer::RegisterPtr(const SerializedPtrID& PtrId,
const void* Ptr) {
MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
assert (!HasFinalPtr(E) && "Pointer already registered.");
#ifdef DEBUG_BACKPATCH
dbgs() << "RegisterPtr: " << PtrId << " => " << Ptr << "\n";
#endif
SetPtr(E,Ptr);
}
void Deserializer::ReadUIntPtr(uintptr_t& PtrRef,
const SerializedPtrID& PtrId,
bool AllowBackpatch) {
if (PtrId == 0) {
PtrRef = 0;
return;
}
MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
if (HasFinalPtr(E)) {
PtrRef = GetFinalPtr(E);
#ifdef DEBUG_BACKPATCH
dbgs() << "ReadUintPtr: " << PtrId
<< " <-- " << (void*) GetFinalPtr(E) << '\n';
#endif
}
else {
assert (AllowBackpatch &&
"Client forbids backpatching for this pointer.");
#ifdef DEBUG_BACKPATCH
dbgs() << "ReadUintPtr: " << PtrId << " (NO PTR YET)\n";
#endif
// Register backpatch. Check the freelist for a BPNode.
BPNode* N;
if (FreeList) {
N = FreeList;
FreeList = FreeList->Next;
}
else // No available BPNode. Allocate one.
N = (BPNode*) Allocator.Allocate<BPNode>();
new (N) BPNode(GetBPNode(E),PtrRef);
SetBPNode(E,N);
}
}
uintptr_t Deserializer::ReadInternalRefPtr() {
SerializedPtrID PtrId = ReadPtrID();
assert (PtrId != 0 && "References cannot refer the NULL address.");
MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
assert (HasFinalPtr(E) &&
"Cannot backpatch references. Object must be already deserialized.");
return GetFinalPtr(E);
}
void BPEntry::SetPtr(BPNode*& FreeList, void* P) {
BPNode* Last = NULL;
for (BPNode* N = Head; N != NULL; N=N->Next) {
Last = N;
N->PtrRef |= reinterpret_cast<uintptr_t>(P);
}
if (Last) {
Last->Next = FreeList;
FreeList = Head;
}
Ptr = const_cast<void*>(P);
}
#define INT_READ(TYPE)\
void SerializeTrait<TYPE>::Read(Deserializer& D, TYPE& X) {\
X = (TYPE) D.ReadInt(); }
INT_READ(bool)
INT_READ(unsigned char)
INT_READ(unsigned short)
INT_READ(unsigned int)
INT_READ(unsigned long)
#define SINT_READ(TYPE)\
void SerializeTrait<TYPE>::Read(Deserializer& D, TYPE& X) {\
X = (TYPE) D.ReadSInt(); }
INT_READ(signed char)
INT_READ(signed short)
INT_READ(signed int)
INT_READ(signed long)

View File

@ -1,24 +0,0 @@
//===-- SerializeAPInt.cpp - Serialization for APFloat ---------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements deserialization of APFloat.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APFloat.h"
#include "llvm/Bitcode/Deserialize.h"
using namespace llvm;
APFloat APFloat::ReadVal(Deserializer& D) {
APInt x;
D.Read(x);
return APFloat(x);
}

View File

@ -1,33 +0,0 @@
//===-- DeserializeAPInt.cpp - Deserialization for APInts ------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements deserialization of APInts.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APInt.h"
#include "llvm/Bitcode/Deserialize.h"
#include <cassert>
using namespace llvm;
void APInt::Read(Deserializer& D) {
BitWidth = D.ReadInt();
if (isSingleWord())
VAL = D.ReadInt();
else {
uint32_t NumWords = D.ReadInt();
assert (NumWords > 1);
pVal = new uint64_t[NumWords];
assert (pVal && "Allocation in deserialization of APInt failed.");
for (unsigned i = 0; i < NumWords; ++i)
pVal[i] = D.ReadInt();
}
}

View File

@ -2,8 +2,5 @@ add_llvm_library(LLVMBitWriter
BitWriter.cpp
BitcodeWriter.cpp
BitcodeWriterPass.cpp
Serialize.cpp
SerializeAPFloat.cpp
SerializeAPInt.cpp
ValueEnumerator.cpp
)

View File

@ -1,115 +0,0 @@
//==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the internal methods used for object serialization.
//
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/Serialize.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
using namespace llvm;
Serializer::Serializer(BitstreamWriter& stream)
: Stream(stream), BlockLevel(0) {}
Serializer::~Serializer() {
if (inRecord())
EmitRecord();
while (BlockLevel > 0)
Stream.ExitBlock();
Stream.FlushToWord();
}
void Serializer::EmitRecord() {
assert(Record.size() > 0 && "Cannot emit empty record.");
Stream.EmitRecord(8,Record);
Record.clear();
}
void Serializer::EnterBlock(unsigned BlockID,unsigned CodeLen) {
FlushRecord();
Stream.EnterSubblock(BlockID,CodeLen);
++BlockLevel;
}
void Serializer::ExitBlock() {
assert (BlockLevel > 0);
--BlockLevel;
FlushRecord();
Stream.ExitBlock();
}
void Serializer::EmitInt(uint64_t X) {
assert (BlockLevel > 0);
Record.push_back(X);
}
void Serializer::EmitSInt(int64_t X) {
if (X >= 0)
EmitInt(X << 1);
else
EmitInt((-X << 1) | 1);
}
void Serializer::EmitCStr(const char* s, const char* end) {
Record.push_back(end - s);
while(s != end) {
Record.push_back(*s);
++s;
}
}
void Serializer::EmitCStr(const char* s) {
EmitCStr(s,s+strlen(s));
}
SerializedPtrID Serializer::getPtrId(const void* ptr) {
if (!ptr)
return 0;
MapTy::iterator I = PtrMap.find(ptr);
if (I == PtrMap.end()) {
unsigned id = PtrMap.size()+1;
#ifdef DEBUG_BACKPATCH
dbgs() << "Registered PTR: " << ptr << " => " << id << "\n";
#endif
PtrMap[ptr] = id;
return id;
}
else return I->second;
}
bool Serializer::isRegistered(const void* ptr) const {
MapTy::const_iterator I = PtrMap.find(ptr);
return I != PtrMap.end();
}
#define INT_EMIT(TYPE)\
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
INT_EMIT(bool)
INT_EMIT(unsigned char)
INT_EMIT(unsigned short)
INT_EMIT(unsigned int)
INT_EMIT(unsigned long)
#define SINT_EMIT(TYPE)\
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitSInt(X); }
SINT_EMIT(signed char)
SINT_EMIT(signed short)
SINT_EMIT(signed int)
SINT_EMIT(signed long)

View File

@ -1,21 +0,0 @@
//===-- SerializeAPInt.cpp - Serialization for APFloat ---------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements serialization of APFloat.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APFloat.h"
#include "llvm/Bitcode/Serialize.h"
using namespace llvm;
void APFloat::Emit(Serializer& S) const {
S.Emit(bitcastToAPInt());
}

View File

@ -1,31 +0,0 @@
//===-- SerializeAPInt.cpp - Serialization for APInts ----------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements serialization of APInts.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APInt.h"
#include "llvm/Bitcode/Serialize.h"
#include <cassert>
using namespace llvm;
void APInt::Emit(Serializer& S) const {
S.EmitInt(BitWidth);
if (isSingleWord())
S.EmitInt(VAL);
else {
uint32_t NumWords = getNumWords();
S.EmitInt(NumWords);
for (unsigned i = 0; i < NumWords; ++i)
S.EmitInt(pVal[i]);
}
}