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

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