Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShSectionImpl.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
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       // @todo this is copied from CtrlGraph.cpp...
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

Generated on Thu Jul 28 17:33:05 2005 for Sh by  doxygen 1.4.3-20050530