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

ShProgramNode.hpp

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 SHPROGRAMNODE_HPP
00021 #define SHPROGRAMNODE_HPP
00022 
00023 #include <list>
00024 #include <map>
00025 #include <utility>
00026 #include <string>
00027 #include "ShDllExport.hpp"
00028 #include "ShRefCount.hpp"
00029 #include "ShTokenizer.hpp"
00030 #include "ShVariableNode.hpp"
00031 #include "ShCtrlGraph.hpp"
00032 #include "ShTextureNode.hpp"
00033 #include "ShChannelNode.hpp"
00034 #include "ShPaletteNode.hpp"
00035 #include "ShMeta.hpp"
00036 
00037 namespace SH {
00038 
00039 class ShBackendCode;
00040 class ShBackend;
00041 
00044 class
00045 SH_DLLEXPORT ShProgramNode : public virtual ShRefCountable, public virtual ShMeta, public virtual ShInfoHolder {
00046 public:
00047   ShProgramNode(const std::string& target);
00048 
00049   ~ShProgramNode();
00050   
00055   void compile(const ShPointer<ShBackend>& backend);
00059   void compile(const std::string& target, const ShPointer<ShBackend>& backend);
00060 
00064   bool is_compiled() const;
00067   bool is_compiled(const std::string& target) const;
00070   bool is_compiled(const std::string& target, const ShPointer<ShBackend>& backend) const;
00071 
00073   std::string describe_interface() const;
00075   std::string describe_vars() const;
00077   std::string describe_decls() const;
00078 
00081   void dump(std::string filename) const;
00082   
00085   ShPointer<ShBackendCode> code(); 
00089   ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend);
00092   ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend);
00093 
00095   void updateUniform(const ShVariableNodePtr& uniform);
00096 
00099   ShTokenizer tokenizer;
00100 
00104   ShPointer<ShCtrlGraph> ctrlGraph;
00105 
00107   void collectDecls();
00108 
00110   void collectVariables();
00111 
00113   bool hasDecl(ShVariableNodePtr node) const;
00114 
00124   void addDecl(ShVariableNodePtr node, ShCtrlGraphNodePtr);
00125   void addDecl(ShVariableNodePtr node);
00127 
00128   typedef std::set<ShVariableNodePtr> VarSet;
00129   typedef std::list<ShVariableNodePtr> VarList;
00130   typedef std::list<ShTextureNodePtr> TexList;
00131   typedef std::list<ShChannelNodePtr> ChannelList;
00132   typedef std::list<ShPaletteNodePtr> PaletteList;
00133 
00134   VarList::const_iterator inputs_begin() const;
00135   VarList::const_iterator inputs_end() const;
00136   VarList::const_iterator outputs_begin() const;
00137   VarList::const_iterator outputs_end() const;
00138   VarList::const_iterator temps_begin() const;
00139   VarList::const_iterator temps_end() const;
00140   VarList::const_iterator constants_begin() const;
00141   VarList::const_iterator constants_end() const;
00142   VarList::const_iterator uniforms_begin() const;
00143   VarList::const_iterator uniforms_end() const;
00144 
00145   TexList::const_iterator textures_begin() const;
00146   TexList::const_iterator textures_end() const;
00147 
00148   ChannelList::const_iterator channels_begin() const;
00149   ChannelList::const_iterator channels_end() const;
00150 
00151   PaletteList::const_iterator palettes_begin() const;
00152   PaletteList::const_iterator palettes_end() const;
00153   
00154   
00155   VarList inputs; 
00156   VarList outputs; 
00157   VarList temps; 
00158   VarSet tempDecls; 
00159   VarList constants; 
00160   VarList uniforms; 
00161   TexList textures; 
00162   ChannelList channels; 
00163   PaletteList palettes; 
00164 
00166   std::string target() const { return m_target; }
00167 
00169   std::string& target() { return m_target; }
00170 
00172   ShPointer<ShProgramNode> clone() const;
00173 
00175   static std::ostream& print(std::ostream& out, const VarList& list);
00176 
00178   bool finished() const;
00179 
00181   void finish();
00182 
00186   void assign(const ShVariableNodePtr& var) const;
00187   
00188 private:
00189   static std::string describe(const VarList &varlist); 
00190   static std::string describe(const ChannelList &chanlist); 
00191 
00192   std::string m_target; 
00193 
00194   void collectNodeDecls(const ShPointer<ShCtrlGraphNode>& node);
00195 
00196   void collectNodeVars(const ShPointer<ShCtrlGraphNode>& node);
00197   void collectVar(const ShVariableNodePtr& node);
00198 
00199   typedef std::map< std::pair< std::string, ShPointer<ShBackend> >,
00200                     ShPointer<ShBackendCode> > CodeMap;
00201   CodeMap m_code; 
00202 
00203   bool m_finished; 
00204 
00205 
00206   mutable ShVariableNodePtr m_assigned_var;
00207 };
00208 
00209 typedef ShPointer<ShProgramNode> ShProgramNodePtr;
00210 typedef ShPointer<const ShProgramNode> ShProgramNodeCPtr;
00211 
00212 }
00213 
00214 #endif
00215 

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