mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 22:24:07 +00:00
Added support in serializer and deserializer to create arbitrary blocks.
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
This commit is contained in:
@ -153,6 +153,8 @@ public:
|
|||||||
void RegisterPtr(const void* Ptr) {
|
void RegisterPtr(const void* Ptr) {
|
||||||
RegisterPtr(ReadInt(),Ptr);
|
RegisterPtr(ReadInt(),Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AtEnd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReadRecord();
|
void ReadRecord();
|
||||||
|
@ -25,7 +25,7 @@ namespace llvm {
|
|||||||
class Serializer {
|
class Serializer {
|
||||||
BitstreamWriter& Stream;
|
BitstreamWriter& Stream;
|
||||||
SmallVector<uint64_t,10> Record;
|
SmallVector<uint64_t,10> Record;
|
||||||
bool inBlock;
|
unsigned BlockLevel;
|
||||||
|
|
||||||
typedef DenseMap<const void*,unsigned> MapTy;
|
typedef DenseMap<const void*,unsigned> MapTy;
|
||||||
MapTy PtrMap;
|
MapTy PtrMap;
|
||||||
@ -56,6 +56,9 @@ public:
|
|||||||
|
|
||||||
void Flush() { if (inRecord()) EmitRecord(); }
|
void Flush() { if (inRecord()) EmitRecord(); }
|
||||||
|
|
||||||
|
void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
|
||||||
|
void ExitBlock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EmitRecord();
|
void EmitRecord();
|
||||||
inline bool inRecord() { return Record.size() > 0; }
|
inline bool inRecord() { return Record.size() > 0; }
|
||||||
|
@ -47,10 +47,15 @@ void Deserializer::ReadRecord() {
|
|||||||
// FIXME: Check if we haven't run off the edge of the stream.
|
// FIXME: Check if we haven't run off the edge of the stream.
|
||||||
// FIXME: Handle abbreviations.
|
// FIXME: Handle abbreviations.
|
||||||
|
|
||||||
|
assert (Record.size() == 0);
|
||||||
|
|
||||||
unsigned Code;
|
unsigned Code;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
if (Stream.AtEndOfStream())
|
||||||
|
return;
|
||||||
|
|
||||||
Code = Stream.ReadCode();
|
Code = Stream.ReadCode();
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
if (Code == bitc::ENTER_SUBBLOCK) {
|
||||||
@ -71,7 +76,16 @@ void Deserializer::ReadRecord() {
|
|||||||
|
|
||||||
assert (Record.size() == 0);
|
assert (Record.size() == 0);
|
||||||
Stream.ReadRecord(Code,Record);
|
Stream.ReadRecord(Code,Record);
|
||||||
assert (Record.size() > 0);
|
assert (Record.size() > 0 || Stream.AtEndOfStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Deserializer::AtEnd() {
|
||||||
|
if (inRecord())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ReadRecord();
|
||||||
|
|
||||||
|
return Stream.AtEndOfStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Deserializer::ReadInt() {
|
uint64_t Deserializer::ReadInt() {
|
||||||
|
@ -17,16 +17,17 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
|
Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
|
||||||
: Stream(stream), inBlock(BlockID >= 8) {
|
: Stream(stream), BlockLevel(0) {
|
||||||
|
|
||||||
if (inBlock) Stream.EnterSubblock(8,3);
|
if (BlockID >= 8)
|
||||||
|
EnterBlock(8,3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serializer::~Serializer() {
|
Serializer::~Serializer() {
|
||||||
if (inRecord())
|
if (inRecord())
|
||||||
EmitRecord();
|
EmitRecord();
|
||||||
|
|
||||||
if (inBlock)
|
while (BlockLevel > 0)
|
||||||
Stream.ExitBlock();
|
Stream.ExitBlock();
|
||||||
|
|
||||||
Stream.FlushToWord();
|
Stream.FlushToWord();
|
||||||
@ -38,7 +39,21 @@ void Serializer::EmitRecord() {
|
|||||||
Record.clear();
|
Record.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Serializer::EnterBlock(unsigned BlockID,unsigned CodeLen) {
|
||||||
|
Flush();
|
||||||
|
Stream.EnterSubblock(BlockID,CodeLen);
|
||||||
|
++BlockLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Serializer::ExitBlock() {
|
||||||
|
assert (BlockLevel > 0);
|
||||||
|
--BlockLevel;
|
||||||
|
Flush();
|
||||||
|
Stream.ExitBlock();
|
||||||
|
}
|
||||||
|
|
||||||
void Serializer::EmitInt(unsigned X) {
|
void Serializer::EmitInt(unsigned X) {
|
||||||
|
assert (BlockLevel > 0);
|
||||||
Record.push_back(X);
|
Record.push_back(X);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +86,7 @@ unsigned Serializer::getPtrId(const void* ptr) {
|
|||||||
else return I->second;
|
else return I->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define INT_EMIT(TYPE)\
|
#define INT_EMIT(TYPE)\
|
||||||
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
|
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user