ShContext.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 SHCONTEXT_HPP
00021 #define SHCONTEXT_HPP
00022 
00023 #include <string>
00024 #include <map>
00025 #include "ShDllExport.hpp"
00026 #include "ShProgram.hpp"
00027 
00028 namespace SH {
00029 
00030 class
00031 SH_DLLEXPORT ShContext {
00032 public:
00033   static ShContext* current();
00034 
00036   int optimization() const;
00037   void optimization(int level);
00038 
00041   bool throw_errors() const;
00042   void throw_errors(bool on);
00043 
00047   void disable_optimization(const std::string& name);
00049   void enable_optimization(const std::string& name);
00051   bool optimization_disabled(const std::string& name) const;
00052 
00053   bool is_bound(const std::string& target);
00054   ShProgramNodePtr bound_program(const std::string& target);
00055 
00056   
00057   typedef std::map<std::string, ShProgram> BoundProgramMap;
00058 
00059   BoundProgramMap::iterator begin_bound()
00060   {
00061     return m_bound.begin();
00062   }
00063 
00064   BoundProgramMap::iterator end_bound()
00065   {
00066     return m_bound.end();
00067   }
00068 
00070   void set_binding(const std::string& unit, const ShProgram& program);
00072   void unset_binding(const std::string& unit);
00073 
00075   ShProgramNodePtr parsing();
00076 
00078   void enter(const ShProgramNodePtr& program);
00079 
00081   void exit();
00082   
00083 private:
00084   ShContext();
00085 
00086   int m_optimization;
00087   bool m_throw_errors;
00088   
00089   BoundProgramMap m_bound;
00090   std::stack<ShProgramNodePtr> m_parsing;
00091 
00092   std::set<std::string> m_disabled_optimizations;
00093   
00094   static ShContext* m_instance;
00095 
00096   // NOT IMPLEMENTED
00097   ShContext(const ShContext& other);
00098   ShContext& operator=(const ShContext& other);
00099 };
00100 
00101 typedef ShContext::BoundProgramMap::iterator ShBoundIterator;
00102 
00104 SH_DLLEXPORT
00105 bool shIsBound(const std::string& target);
00106 
00108 SH_DLLEXPORT
00109 ShProgramNodePtr shBound(const std::string& target);
00110 
00112 inline ShBoundIterator shBeginBound()
00113 {
00114   return ShContext::current()->begin_bound();
00115 }
00116 
00118 inline ShBoundIterator shEndBound()
00119 {
00120   return ShContext::current()->end_bound();
00121 }
00122 
00123 }
00124 
00125 #endif

Generated on Wed Nov 9 15:29:30 2005 for Sh by  doxygen 1.4.5