ShProgram.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 SHPROGRAM_HPP
00021 #define SHPROGRAM_HPP
00022 
00023 #include "ShDllExport.hpp"
00024 #include "ShProgramNode.hpp"
00025 #include "ShBackend.hpp"
00026 
00027 namespace SH {
00028 
00029 class ShStream;
00030 template<typename T> class ShChannel;
00031 class ShRecord;
00032 
00035 class
00036 SH_DLLEXPORT ShProgram : public ShMetaForwarder {
00037 public:
00038   ShProgram();
00039   ShProgram(const ShProgram& other);
00040   ShProgram(const std::string& target);
00041   ShProgram(const ShProgramNodePtr& node);
00042 
00043   ShProgram& operator=(const ShProgram& other);
00044   
00046   ShProgramNodeCPtr node() const { return m_node; }
00047 
00049   ShProgramNodePtr node() { return m_node; }
00050   
00055   void compile(const ShPointer<ShBackend>& backend) { m_node->compile(backend); }
00056 
00060   void compile(const std::string& target, const ShPointer<ShBackend>& backend)
00061   {
00062     m_node->compile(target, backend);
00063   }
00064 
00068   bool is_compiled() const { return m_node->is_compiled(); }
00069 
00072   bool is_compiled(const std::string& target) const
00073   { 
00074     return m_node->is_compiled(target);
00075   }
00076 
00079   std::string describe_interface() const
00080   {
00081     return m_node->describe_interface();
00082   }
00083 
00086   std::string describe_bindings() const
00087   {
00088     return m_node->describe_bindings();
00089   }
00090   
00093   std::string describe_bindings(const std::string& target) const
00094   {
00095     return m_node->describe_bindings(target);
00096   }
00097   
00101   ShPointer<ShBackendCode> code() { return m_node->code(); }
00102   
00106   ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend) {
00107     return m_node->code(backend);
00108   }
00109 
00111   ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend)
00112   {
00113     return m_node->code(target, backend);
00114   }
00115 
00117   void updateUniform(const ShVariableNodePtr& uniform)
00118   {
00119     m_node->updateUniform(uniform);
00120   }
00121 
00125   std::string backend_name() const { return m_node->backend_name(); }
00126 
00127   std::string target() const { return m_node->target(); }
00128 
00130   std::string& target() { return m_node->target(); }
00131 
00132   ShProgramNode::VarList::const_iterator begin_inputs() const         { return m_node->begin_inputs(); }
00133   ShProgramNode::VarList::const_iterator end_inputs() const           { return m_node->end_inputs(); }
00134   ShProgramNode::VarList::const_iterator begin_outputs() const        { return m_node->begin_outputs(); }
00135   ShProgramNode::VarList::const_iterator end_outputs() const          { return m_node->end_outputs(); }
00136   ShProgramNode::VarList::const_iterator begin_temps() const          { return m_node->begin_temps(); }
00137   ShProgramNode::VarList::const_iterator end_temps() const            { return m_node->end_temps(); }
00138   ShProgramNode::VarList::const_iterator begin_constants() const      { return m_node->begin_constants(); }
00139   ShProgramNode::VarList::const_iterator end_constants() const        { return m_node->end_constants(); }
00140   ShProgramNode::VarList::const_iterator begin_parameters() const     { return m_node->begin_parameters(); }
00141   ShProgramNode::VarList::const_iterator end_parameters() const       { return m_node->end_parameters(); }
00142   ShProgramNode::VarList::const_iterator begin_all_parameters() const { return m_node->begin_all_parameters(); }
00143   ShProgramNode::VarList::const_iterator end_all_parameters() const   { return m_node->end_all_parameters(); }
00144   ShProgramNode::TexList::const_iterator begin_textures() const       { return m_node->begin_textures(); }
00145   ShProgramNode::TexList::const_iterator end_textures() const         { return m_node->end_textures(); }
00146   ShProgramNode::ChannelList::const_iterator begin_channels() const   { return m_node->begin_channels(); }
00147   ShProgramNode::ChannelList::const_iterator end_channels() const     { return m_node->end_channels(); }
00148   ShProgramNode::PaletteList::const_iterator begin_palettes() const   { return m_node->begin_palettes(); }
00149   ShProgramNode::PaletteList::const_iterator end_palettes() const     { return m_node->end_palettes(); }
00150 
00151   // Call operators for channels and streams.
00152   // Equivalent to operator<< invocations.
00153   // Note that the template functions are implemented in
00154   // ShChannelImpl.hpp
00155   template<typename T0>
00156   ShProgram operator()(const ShChannel<T0>& t0) const;
00157   ShProgram operator()(const ShStream& s0) const;
00158   template<typename T0, typename T1>
00159   ShProgram operator()(const ShChannel<T0>& t0,
00160                         const ShChannel<T1>& t1) const;
00161   ShProgram operator()(const ShStream& s0,
00162                         const ShStream& s1) const;
00163   template<typename T0, typename T1, typename T2>
00164   ShProgram operator()(const ShChannel<T0>& t0,
00165                         const ShChannel<T1>& t1,
00166                         const ShChannel<T2>& t2) const;
00167   ShProgram operator()(const ShStream& s0,
00168                         const ShStream& s1,
00169                         const ShStream& s2) const;
00170   template<typename T0, typename T1, typename T2, typename T3>
00171   ShProgram operator()(const ShChannel<T0>& t0,
00172                         const ShChannel<T1>& t1,
00173                         const ShChannel<T2>& t2,
00174                         const ShChannel<T3>& t3) const;
00175   ShProgram operator()(const ShStream& s0,
00176                         const ShStream& s1,
00177                         const ShStream& s2,
00178                         const ShStream& s3) const;
00179   template<typename T0, typename T1, typename T2, typename T3,
00180            typename T4>
00181   ShProgram operator()(const ShChannel<T0>& t0,
00182                         const ShChannel<T1>& t1,
00183                         const ShChannel<T2>& t2,
00184                         const ShChannel<T3>& t3,
00185                         const ShChannel<T4>& t4) const;
00186   ShProgram operator()(const ShStream& s0,
00187                         const ShStream& s1,
00188                         const ShStream& s2,
00189                         const ShStream& s3,
00190                         const ShStream& s4) const;
00191   
00192   // Call operators for records
00193   // May want to merge these with above in the long term. 
00194   ShProgram operator()(const ShRecord &rec) const;
00195   ShProgram operator()(const ShVariable &v0) const;
00196   ShProgram operator()(const ShVariable &v0, 
00197                        const ShVariable &v1) const;
00198   ShProgram operator()(const ShVariable &v0, 
00199                        const ShVariable &v1, 
00200                        const ShVariable &v2) const;
00201   ShProgram operator()(const ShVariable &v0, 
00202                        const ShVariable &v1, 
00203                        const ShVariable &v2, 
00204                        const ShVariable &v3) const;
00205   
00206 private:
00207 
00208   ShProgramNodePtr m_node;
00209 };
00210 
00211 }
00212 
00213 #endif
00214 

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