mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
06717a6185
Import the RestructureCFGPass from the `feature/the-comb` branch on the `revamb` repository.
70 lines
2.0 KiB
C++
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);
|
|
}
|
|
}
|