From 149f8e76d1eed5037c583bad599a27154ce3d9a9 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 3 Mar 2015 17:36:10 +0100 Subject: [PATCH] implement basic deserialization of BasicBlock's --- src/core/BasicBlock.cxx | 77 +++++++++++++++++++++++++++++++++++++++++ src/core/BasicBlock.hxx | 3 ++ 2 files changed, 80 insertions(+) diff --git a/src/core/BasicBlock.cxx b/src/core/BasicBlock.cxx index 0dec430..5e2efd7 100644 --- a/src/core/BasicBlock.cxx +++ b/src/core/BasicBlock.cxx @@ -1,5 +1,9 @@ #include "BasicBlock.hxx" #include "gui/qt.hxx" +#include "core/InformationManager.hxx" + +#include +#include void BasicBlock::serialize(QXmlStreamWriter& stream) { stream.writeStartElement("block"); @@ -12,3 +16,76 @@ void BasicBlock::serialize(QXmlStreamWriter& stream) { stream.writeTextElement("next", QString::number(getNextBlock(1), 16)); stream.writeEndElement(); // "block" } + +BasicBlock* BasicBlock::deserialize(QXmlStreamReader& stream, InformationManager* manager) { + Q_ASSERT(stream.name() == "block"); + + QString name = stream.attributes().value("id").toString(); + uint64_t start_address(0), end_address(0), next_blocks[2] = {0, 0}; + BasicBlock* block; + + + while (QXmlStreamReader::NoToken != stream.readNext()) { + while (QXmlStreamReader::Characters == stream.tokenType() && + stream.isWhitespace()) + stream.readNext(); + if (QXmlStreamReader::EndElement == stream.tokenType()) + break; + + if(QXmlStreamReader::StartElement != stream.tokenType()) + return NULL; + + if (stream.name() == "start") { + stream.readNext(); + if (QXmlStreamReader::Characters != stream.tokenType()) + return NULL; + + start_address = stream.text().toULongLong(NULL, 16); + stream.readNext(); + + if(QXmlStreamReader::EndElement != stream.tokenType()) + return NULL; + } + if (stream.name() == "end") { + stream.readNext(); + if (QXmlStreamReader::Characters != stream.tokenType()) + return NULL; + + end_address = stream.text().toULongLong(NULL, 16); + stream.readNext(); + + if(QXmlStreamReader::EndElement != stream.tokenType()) + return NULL; + } + if (stream.name() == "next") { + stream.readNext(); + if (QXmlStreamReader::Characters != stream.tokenType()) + return NULL; + + uint64_t newblock = stream.text().toULongLong(NULL, 16); + stream.readNext(); + + if (next_blocks[0] == 0) { + next_blocks[0] = newblock; + } else { + if (0 != next_blocks[1]) + return NULL; + next_blocks[1] = newblock; + } + + if(QXmlStreamReader::EndElement != stream.tokenType()) + return NULL; + } + } + + block = manager->newBasicBlock(start_address); + block->end_address = end_address; + block->next_blocks[0] = next_blocks[0]; + block->next_blocks[1] = next_blocks[1]; + + assert(stream.name() == "block"); + assert(block->getName() == name.toStdString()); + + manager->finishBasicBlock(block); + return block; +} diff --git a/src/core/BasicBlock.hxx b/src/core/BasicBlock.hxx index c7ae26e..bec0da3 100644 --- a/src/core/BasicBlock.hxx +++ b/src/core/BasicBlock.hxx @@ -8,6 +8,7 @@ class Disassembler; class InformationManager; class QXmlStreamWriter; +class QXmlStreamReader; class BasicBlock { public: @@ -48,6 +49,8 @@ public: } void serialize(QXmlStreamWriter& stream); + static BasicBlock* deserialize(QXmlStreamReader& stream, InformationManager* manager); + private: BasicBlock(uint64_t start_address, InformationManager* manager) : start_address(start_address) -- 2.39.5