00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifndef SHSECTIONIMPL_HPP
00021 #define SHSECTIONIMPL_HPP
00022
00023 #include <sstream>
00024 #include "ShSection.hpp"
00025
00029 namespace SH {
00030
00031 template<class F>
00032 void ShSectionTree::dfs(F& functor) {
00033 realDfs(root, functor);
00034 }
00035
00036 template<class F>
00037 void ShSectionTree::realDfs(ShSectionNodePtr node, F& functor)
00038 {
00039 for(ShSectionNode::iterator I = node->begin(); I != node->end(); ++I) {
00040 realDfs(*I, functor);
00041 }
00042 functor(node);
00043 }
00044
00045 template<class F>
00046 std::ostream& ShSectionTree::dump(std::ostream& out, F& functor)
00047 {
00048 std::ostringstream cfgout;
00049 out << "digraph sectiontree {" << std::endl;
00050 realDump(out, cfgout, root, functor);
00051 out << cfgout.str() << std::endl;
00052 out << "}";
00053 return out;
00054 }
00055
00056 template<class F>
00057 void ShSectionTree::realDump(std::ostream& out, std::ostream& cfgout,
00058 ShSectionNodePtr node, F& functor)
00059 {
00060 out << "subgraph " << "cluster_" << node.object() << " {" << std::endl;
00061 functor(out, node);
00062 for(ShSectionNode::cfg_iterator C = node->cfgBegin(); C != node->cfgEnd(); ++C) {
00063 ShCtrlGraphNodePtr c = (*C);
00064
00065 out << "\"cfg_" << c.object() << "\"";
00066 functor(out, c);
00067 #if 0
00068 if(c->block) {
00069 for(ShBasicBlock::iterator I = c->block->begin(); I != c->block->end(); ++I) {
00070 functor(out, *I);
00071 out << "\n";
00072 }
00073 out << ">, shape=box]";
00074 } else {
00075 out << ">, shape=circle, height=0.25]";
00076 }
00077 #endif
00078 out << ";" << std::endl;
00079
00080
00081 for (ShCtrlGraphNode::SuccessorList::const_iterator I = c->successors.begin();
00082 I != c->successors.end(); ++I) {
00083 std::ostream& curout = contains(node, I->node) ? out : cfgout;
00084 curout << "\"cfg_" << c.object() << "\" ";
00085 curout << "-> ";
00086 curout << "\"cfg_" << I->node.object() << "\" ";
00087
00088 curout << "[style=dashed, label=\"" << I->cond.name() << "\"]";
00089 curout << ";" << std::endl;
00090 }
00091
00092 if (c->follower) {
00093 std::ostream& curout = contains(node, c->follower) ? out : cfgout;
00094 curout << "\"cfg_" << c.object() << "\" ";
00095 curout << "-> ";
00096 curout << "\"cfg_" << c->follower.object() << "\";" << std::endl;
00097 }
00098 }
00099
00100 for(ShSectionNode::iterator S = node->begin(); S != node->end(); ++S) {
00101 realDump(out, cfgout, *S, functor);
00102 }
00103 out << "}" << std::endl;
00104 }
00105
00106 }
00107
00108
00109
00110 #endif