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 software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
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       // @todo this is copied from CtrlGraph.cpp...
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

Generated on Wed Jun 15 18:12:41 2005 for Sh by  doxygen 1.4.3-20050530