mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-14 04:57:33 +00:00
6e9b496643
Deserialize.h Serialization.h now includes trait speciailizations for unsigned long, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43307 91177308-0d34-0410-b5e6-96231b3b80d8
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
//=- Deserialize.h - Generic Object Deserialization from 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 deserialization from
|
|
// LLVM bitcode.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_BITCODE_SERIALIZE_INPUT
|
|
#define LLVM_BITCODE_SERIALIZE_INPUT
|
|
|
|
#include "llvm/Bitcode/BitstreamReader.h"
|
|
#include "llvm/Bitcode/Serialization.h"
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
class Deserializer {
|
|
BitstreamReader& Stream;
|
|
SmallVector<uint64_t,10> Record;
|
|
unsigned RecIdx;
|
|
public:
|
|
Deserializer(BitstreamReader& stream);
|
|
~Deserializer();
|
|
|
|
template <typename T>
|
|
inline T& Read(T& X) {
|
|
SerializeTrait<T>::Read(*this,X);
|
|
return X;
|
|
}
|
|
|
|
template <typename T>
|
|
inline T* Materialize() {
|
|
return SerializeTrait<T>::Materialize(*this);
|
|
}
|
|
|
|
uint64_t ReadInt();
|
|
bool ReadBool() { return ReadInt() ? true : false; }
|
|
|
|
// FIXME: Substitute a better implementation which calculates the minimum
|
|
// number of bits needed to serialize the enum.
|
|
template <typename EnumT>
|
|
EnumT ReadEnum(unsigned MinVal, unsigned MaxVal) {
|
|
return static_cast<EnumT>(ReadInt(32));
|
|
}
|
|
|
|
char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
|
|
void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
|
|
|
|
private:
|
|
void ReadRecord();
|
|
|
|
inline bool inRecord() {
|
|
if (Record.size() > 0) {
|
|
if (RecIdx >= Record.size()) {
|
|
RecIdx = 0;
|
|
Record.clear();
|
|
return false;
|
|
}
|
|
else return true;
|
|
}
|
|
else return false;
|
|
}
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|