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

ShContext.cpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #include "ShContext.hpp"
00028 #include "ShDebug.hpp"
00029 #include "ShTypeInfo.hpp"
00030 
00031 namespace SH {
00032 
00033 ShContext* ShContext::m_instance = 0;
00034 
00035 ShContext* ShContext::current()
00036 {
00037   if (!m_instance) {
00038     m_instance = new ShContext();
00039 
00040     // must be done this way since
00041     // init_types requires a ShContext object, 
00042     ShTypeInfo::init();
00043   }
00044   return m_instance;
00045 }
00046 
00047 ShContext::ShContext()
00048   : m_optimization(2),
00049     m_throw_errors(true)
00050 {
00051 }
00052 
00053 
00054 int ShContext::optimization() const
00055 {
00056   return m_optimization;
00057 }
00058 
00059 void ShContext::optimization(int level)
00060 {
00061   m_optimization = level;
00062 }
00063 
00064 bool ShContext::throw_errors() const
00065 {
00066   return m_throw_errors;
00067 }
00068 
00069 void ShContext::throw_errors(bool on)
00070 {
00071   m_throw_errors = on;
00072 }
00073 
00074 void ShContext::disable_optimization(const std::string& name)
00075 {
00076   m_disabled_optimizations.insert(name);
00077 }
00078 
00079 void ShContext::enable_optimization(const std::string& name)
00080 {
00081   m_disabled_optimizations.erase(name);
00082 }
00083 
00084 bool ShContext::optimization_disabled(const std::string& name) const
00085 {
00086   return m_disabled_optimizations.find(name) != m_disabled_optimizations.end();
00087 }
00088 
00089 ShContext::BoundProgramMap::iterator ShContext::begin_bound()
00090 {
00091   return m_bound.begin();
00092 }
00093 
00094 ShContext::BoundProgramMap::iterator ShContext::end_bound()
00095 {
00096   return m_bound.end();
00097 }
00098 
00099 void ShContext::set_binding(const std::string& unit, const ShProgram program)
00100 {
00101   if (!program.node()) {
00102     m_bound.erase(unit);
00103   } else {
00104     m_bound[unit] = program;
00105   }
00106 }
00107 
00108 ShProgramNodePtr ShContext::parsing()
00109 {
00110   if (m_parsing.empty()) return 0;
00111   return m_parsing.top();
00112 }
00113 
00114 void ShContext::enter(const ShProgramNodePtr& program)
00115 {
00116   m_parsing.push(program);
00117 }
00118 
00119 void ShContext::exit()
00120 {
00121   SH_DEBUG_ASSERT(!m_parsing.empty());
00122   m_parsing.pop();
00123 }
00124 
00125 ShBoundIterator shBeginBound()
00126 {
00127   return ShContext::current()->begin_bound();
00128 }
00129 
00130 ShBoundIterator shEndBound()
00131 {
00132   return ShContext::current()->end_bound();
00133 }
00134 
00135 }

Generated on Mon Jan 24 18:36:31 2005 for Sh by  doxygen 1.4.1