Files
revng-revng/lib/RestructureCFGPass/ASTNode.cpp
T
Andrea Gussoni 06717a6185 Import RestructureCFGPass from revamb branch
Import the RestructureCFGPass from the `feature/the-comb` branch on the
`revamb` repository.
2019-01-14 15:45:08 +01:00

70 lines
2.0 KiB
C++

/// \file ASTNode.cpp
/// \brief
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
// Standard includes
#include <cstdlib>
#include <fstream>
#include <iostream>
// Local includes
#include "ASTNode.h"
void CodeNode::dump(std::ofstream &ASTFile) {
ASTFile << "\"" << this->getName() << "\" [";
ASTFile << "label=\"" << this->getName();
ASTFile << "\"";
ASTFile << ",shape=\"box\",color=\"red\"];\n";
}
void IfNode::dump(std::ofstream &ASTFile) {
ASTFile << "\"" << this->getName() << "\" [";
ASTFile << "label=\"" << this->getName();
ASTFile << "\"";
ASTFile << ",shape=\"invhouse\",color=\"blue\"];\n";
if (this->getThen() != nullptr) {
ASTFile << "\"" << this->getName() << "\""
<< " -> \"" << this->getThen()->getName() << "\""
<< " [color=green,label=\"then\"];\n";
this->getThen()->dump(ASTFile);
}
if (this->getElse() != nullptr) {
ASTFile << "\"" << this->getName() << "\""
<< " -> \"" << this->getElse()->getName() << "\""
<< " [color=green,label=\"else\"];\n";
this->getElse()->dump(ASTFile);
}
}
void ScsNode::dump(std::ofstream &ASTFile) {
ASTFile << "\"" << this->getName() << "\" [";
ASTFile << "label=\"" << this->getName();
ASTFile << "\"";
ASTFile << ",shape=\"circle\",color=\"black\"];\n";
revng_assert(this->getBody() != nullptr);
ASTFile << "\"" << this->getName() << "\""
<< " -> \"" << this->getBody()->getName() << "\""
<< " [color=green,label=\"body\"];\n";
this->getBody()->dump(ASTFile);
}
void SequenceNode::dump(std::ofstream &ASTFile) {
ASTFile << "\"" << this->getName() << "\" [";
ASTFile << "label=\"" << this->getName();
ASTFile << "\"";
ASTFile << ",shape=\"box\",color=\"black\"];\n";
for (ASTNode *Successor : this->nodes()) {
ASTFile << "\"" << this->getName() << "\""
<< " -> \"" << Successor->getName() << "\""
<< " [color=green,label=\"elem\"];\n";
Successor->dump(ASTFile);
}
}