Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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 00030 namespace SH { 00031 00032 ShContext* ShContext::m_instance = 0; 00033 00034 ShContext* ShContext::current() 00035 { 00036 if (!m_instance) { 00037 m_instance = new ShContext(); 00038 } 00039 return m_instance; 00040 } 00041 00042 ShContext::ShContext() 00043 : m_optimization(2), 00044 m_throw_errors(true) 00045 { 00046 } 00047 00048 int ShContext::optimization() const 00049 { 00050 return m_optimization; 00051 } 00052 00053 void ShContext::optimization(int level) 00054 { 00055 m_optimization = level; 00056 } 00057 00058 bool ShContext::throw_errors() const 00059 { 00060 return m_throw_errors; 00061 } 00062 00063 void ShContext::throw_errors(bool on) 00064 { 00065 m_throw_errors = on; 00066 } 00067 00068 void ShContext::disable_optimization(const std::string& name) 00069 { 00070 m_disabled_optimizations.insert(name); 00071 } 00072 00073 void ShContext::enable_optimization(const std::string& name) 00074 { 00075 m_disabled_optimizations.erase(name); 00076 } 00077 00078 bool ShContext::optimization_disabled(const std::string& name) const 00079 { 00080 return m_disabled_optimizations.find(name) != m_disabled_optimizations.end(); 00081 } 00082 00083 ShContext::BoundProgramMap::iterator ShContext::begin_bound() 00084 { 00085 return m_bound.begin(); 00086 } 00087 00088 ShContext::BoundProgramMap::iterator ShContext::end_bound() 00089 { 00090 return m_bound.end(); 00091 } 00092 00093 void ShContext::set_binding(const std::string& unit, const ShProgram program) 00094 { 00095 if (!program.node()) { 00096 m_bound.erase(unit); 00097 } else { 00098 m_bound[unit] = program; 00099 } 00100 } 00101 00102 ShProgramNodePtr ShContext::parsing() 00103 { 00104 if (m_parsing.empty()) return 0; 00105 return m_parsing.top(); 00106 } 00107 00108 void ShContext::enter(const ShProgramNodePtr& program) 00109 { 00110 m_parsing.push(program); 00111 } 00112 00113 void ShContext::exit() 00114 { 00115 SH_DEBUG_ASSERT(!m_parsing.empty()); 00116 m_parsing.pop(); 00117 } 00118 00119 ShBoundIterator shBeginBound() 00120 { 00121 return ShContext::current()->begin_bound(); 00122 } 00123 00124 ShBoundIterator shEndBound() 00125 { 00126 return ShContext::current()->end_bound(); 00127 } 00128 00129 }

Generated on Mon Oct 18 14:17:39 2004 for Sh by doxygen 1.3.7