ShInternals.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 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 SHINTERNALS_HPP 
00021 #define SHINTERNALS_HPP
00022 
00023 #include <map>
00024 #include "ShDllExport.hpp"
00025 #include "ShVariableNode.hpp"
00026 #include "ShCtrlGraph.hpp"
00027 #include "ShBackend.hpp"
00028 #include "ShProgramNode.hpp"
00029 #include "ShStructural.hpp"
00030 #include <map>
00031 
00032 namespace SH { 
00033 
00034 typedef std::map<ShVariableNodePtr, ShVariableNodePtr> ShVarMap;
00035 
00036 struct
00037 SH_DLLEXPORT ShVariableReplacer {
00038 
00039   ShVariableReplacer(ShVarMap& v);
00040 
00041   // assignment operator could not be generated: declaration only
00042   ShVariableReplacer& operator=(ShVariableReplacer const&);
00043 
00044   // replaces variables in node based on varMap
00045   void operator()(const ShCtrlGraphNodePtr& node);
00046 
00047   // replaces variables in a ShProgramNode::VarList based on varMap 
00048   void operator()(ShProgramNode::VarList &varList);
00049 
00050   // replaces variables in a ShStructuralNode and all Structural
00051   // Nodes in its region.
00052   void operator()(const ShStructuralNodePtr& node);
00053 
00054   // replaces node in a single variable using varMap
00055   void repVar(ShVariable& var);
00056 
00057   ShVarMap& varMap;
00058 };
00059 
00060 
00065 class
00066 SH_DLLEXPORT ShVarTransformMap {
00067 private:
00068   ShVarMap m_NewToOldMap;
00069 
00070 public:
00071   ShVarTransformMap() {}
00072   explicit ShVarTransformMap(const ShVarTransformMap &m)
00073     : m_NewToOldMap(m.m_NewToOldMap)
00074   {}
00075   ShVarTransformMap & operator=(const ShVarTransformMap &m)
00076   {
00077     m_NewToOldMap = m.m_NewToOldMap;
00078     return *this;
00079   }
00080 
00082   void clear() { m_NewToOldMap.clear(); }
00083 
00087   void add_variable_transform(const ShVariableNodePtr& origVar, const ShVariableNodePtr& newVar);
00088 
00092   ShVariableNodePtr get_original_variable(const ShVariableNodePtr& newVar) const
00093   {
00094     ShVarMap::const_iterator i = m_NewToOldMap.find(newVar);
00095     return (i != m_NewToOldMap.end() ? i->second : newVar);
00096   }
00097 };
00098 
00099 
00100 }
00101 
00102 #endif
00103 

Generated on Thu Feb 16 14:51:32 2006 for Sh by  doxygen 1.4.6