Split Serialization.h into separate headers: Serialize.h and

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
This commit is contained in:
Ted Kremenek
2007-10-24 19:06:40 +00:00
parent be3e348c7c
commit 6e9b496643
5 changed files with 186 additions and 127 deletions

View File

@ -11,7 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/Serialization.h"
#include "llvm/Bitcode/Deserialize.h"
using namespace llvm;
@ -27,31 +27,29 @@ Deserializer::~Deserializer() {
void Deserializer::ReadRecord() {
// FIXME: Check if we haven't run off the edge of the stream.
// FIXME: Handle abbreviations.
unsigned Code = Stream.ReadCode();
// FIXME: Check for the correct code.
assert (Record.size() == 0);
Stream.ReadRecord(Code,Record);
unsigned Code = Stream.ReadCode();
assert (Record.size() == 0);
Stream.ReadRecord(Code,Record);
assert (Record.size() > 0);
}
uint64_t Deserializer::ReadInt(unsigned Bits) {
uint64_t Deserializer::ReadInt() {
// FIXME: Any error recovery/handling with incomplete or bad files?
if (!inRecord())
ReadRecord();
// FIXME: check for loss of precision in read (compare to Bits)
return Record[RecIdx++];
}
char* Deserializer::ReadCString(char* cstr, unsigned MaxLen, bool isNullTerm) {
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(32);
unsigned len = ReadInt();
// FIXME: perform dynamic checking of lengths?
assert (MaxLen == 0 || (len + (isNullTerm ? 1 : 0)) <= MaxLen);
if (!cstr)
@ -60,7 +58,7 @@ char* Deserializer::ReadCString(char* cstr, unsigned MaxLen, bool isNullTerm) {
assert (cstr != NULL);
for (unsigned i = 0; i < len; ++i)
cstr[i] = ReadInt(8);
cstr[i] = (char) ReadInt();
if (isNullTerm)
cstr[len+1] = '\0';
@ -68,16 +66,27 @@ char* Deserializer::ReadCString(char* cstr, unsigned MaxLen, bool isNullTerm) {
return cstr;
}
void Deserializer::ReadCString(std::vector<char>& buff, bool isNullTerm) {
buff.clear();
void Deserializer::ReadCStr(std::vector<char>& buff, bool isNullTerm) {
unsigned len = ReadInt();
unsigned len = ReadInt(32);
buff.clear();
buff.reserve(len);
for (unsigned i = 0; i < len; ++i)
buff.push_back(ReadInt(8));
buff.push_back((char) ReadInt());
if (isNullTerm)
buff.push_back('\0');
}
#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)
INT_READ(unsigned long long)