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