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

ShFixedManipulator.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 00028 #include <sstream> 00029 #include "ShDebug.hpp" 00030 #include "ShVariableNode.hpp" 00031 #include "ShError.hpp" 00032 #include "ShAlgebra.hpp" 00033 #include "ShFixedManipulator.hpp" 00034 #include "ShEnvironment.hpp" 00035 00036 namespace SH { 00037 00038 ShFixedManipulatorNode::ShFixedManipulatorNode() { 00039 } 00040 00041 ShFixedManipulatorNode::~ShFixedManipulatorNode() { 00042 } 00043 00044 ShVariable makeVariable(const ShVariableNodePtr &v, ShBindingType binding) { 00045 ShVariable result(new ShVariableNode(binding, v->size(), v->specialType())); 00046 result.name(v->name()); 00047 return result; 00048 } 00049 00050 ShKeepNode::ShKeepNode(int numChannels) 00051 : m_numChannels(numChannels) { 00052 } 00053 00054 ShProgram ShKeepNode::applyToInputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00055 ShProgram result = SH_BEGIN_PROGRAM() { 00056 for(int i = 0; i < m_numChannels; ++i, ++finger) { 00057 if(finger == end) { 00058 shError(ShAlgebraException("Not enough ShProgram channels for shKeep manipulator")); 00059 } 00060 ShVariable inout = makeVariable((*finger), SH_INOUT); 00061 } 00062 } SH_END; 00063 return result; 00064 } 00065 00066 ShProgram ShKeepNode::applyToOutputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00067 return applyToInputs(finger, end); 00068 } 00069 00070 ShFixedManipulator shKeep(int numChannels) { 00071 return new ShKeepNode(numChannels); 00072 } 00073 00074 00075 ShLoseNode::ShLoseNode(int numChannels) 00076 : m_numChannels(numChannels) { 00077 } 00078 00079 ShProgram ShLoseNode::applyToInputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00080 SH_DEBUG_PRINT( "Applying lose " << m_numChannels ); 00081 ShProgram result = SH_BEGIN_PROGRAM() { 00082 for(int i = 0; i < m_numChannels; ++i, ++finger) { 00083 if(finger == end) { 00084 shError(ShAlgebraException("Not enough ShProgram input channels for shLose manipulator")); 00085 } 00086 ShVariable output = makeVariable((*finger), SH_OUTPUT); 00087 } 00088 } SH_END; 00089 return result; 00090 } 00091 00092 ShProgram ShLoseNode::applyToOutputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00093 ShProgram result = SH_BEGIN_PROGRAM() { 00094 for(int i = 0; i < m_numChannels; ++i, ++finger) { 00095 if(finger == end) { 00096 shError(ShAlgebraException("Not enough ShProgram output channels for shLose manipulator")); 00097 } 00098 ShVariable input = makeVariable((*finger), SH_INPUT); 00099 } 00100 } SH_END; 00101 return result; 00102 } 00103 00104 ShFixedManipulator shLose(int numChannels) { 00105 return new ShLoseNode(numChannels); 00106 } 00107 00108 ShDupNode::ShDupNode(int numDups) 00109 : m_numDups(numDups) { 00110 } 00111 00112 ShProgram ShDupNode::applyToInputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00113 ShProgram result = SH_BEGIN_PROGRAM() { 00114 ShVariable input; 00115 for(int i = 0; i < m_numDups; ++i, ++finger) { 00116 if(finger == end) { 00117 shError(ShAlgebraException("Not enough ShProgram input channels for shDup manipulator")); 00118 } 00119 if(i == 0) { 00120 input = makeVariable((*finger), SH_INPUT); 00121 } 00122 if((*finger)->size() != input.size()) { 00123 shError(ShAlgebraException("Duplicating type " + input.node()->nameOfType() 00124 + " to incompatible type " + (*finger)->nameOfType())); 00125 } 00126 ShVariable output = makeVariable((*finger), SH_OUTPUT); 00127 shASN(output, input); 00128 } 00129 } SH_END; 00130 return result; 00131 } 00132 00133 ShProgram ShDupNode::applyToOutputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00134 ShProgram result = SH_BEGIN_PROGRAM() { 00135 if(finger == end) { 00136 shError(ShAlgebraException("Not enough ShProgram output channels for shDup manipulator")); 00137 } 00138 ShVariable input = makeVariable((*finger), SH_INPUT); 00139 00140 for(int i = 0; i < m_numDups; ++i) { 00141 ShVariable output = makeVariable((*finger), SH_OUTPUT); 00142 shASN(output, input); 00143 } 00144 ++finger; 00145 } SH_END; 00146 return result; 00147 } 00148 00149 ShFixedManipulator shDup(int numDups) { 00150 return new ShDupNode(numDups); 00151 } 00152 00153 ShProgramManipNode::ShProgramManipNode(const ShProgram &p) 00154 : p(p) { 00155 } 00156 00157 ShProgram ShProgramManipNode::applyToInputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00158 std::size_t i; 00159 for(i = 0; i < p.node()->outputs.size() && finger != end; ++i, ++finger); 00160 // allow extra outputs from p 00161 return p; 00162 } 00163 00164 ShProgram ShProgramManipNode::applyToOutputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00165 std::size_t i; 00166 for(i = 0; i < p.node()->inputs.size() && finger != end; ++i, ++finger); 00167 // allow extra inputs from p 00168 return p; 00169 } 00170 00171 ShTreeManipNode::ShTreeManipNode(const ShFixedManipulator &a, const ShFixedManipulator &b) 00172 : a(a), b(b) { 00173 SH_DEBUG_ASSERT(a); 00174 SH_DEBUG_ASSERT(b); 00175 } 00176 00177 ShProgram ShTreeManipNode::applyToInputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00178 ShProgram aProgram = a->applyToInputs(finger, end); 00179 ShProgram bProgram = b->applyToInputs(finger, end); 00180 return aProgram & bProgram; 00181 } 00182 00183 ShProgram ShTreeManipNode::applyToOutputs(ShManipVarIterator &finger, ShManipVarIterator end) const { 00184 ShProgram aProgram = a->applyToOutputs(finger, end); 00185 ShProgram bProgram = b->applyToOutputs(finger, end); 00186 return aProgram & bProgram; 00187 } 00188 00189 ShProgram operator<<(const ShProgram &p, const ShFixedManipulator &m) { 00190 ShManipVarIterator finger = p.node()->inputs.begin(); 00191 ShProgram manipulator = m->applyToInputs(finger, p.node()->inputs.end()); 00192 return p << manipulator; 00193 } 00194 00195 ShProgram operator<<(const ShFixedManipulator &m, const ShProgram &p) { 00196 ShManipVarIterator finger = p.node()->outputs.begin(); 00197 ShProgram manipulator = m->applyToOutputs(finger, p.node()->outputs.end()); 00198 return manipulator << p; 00199 } 00200 00201 ShFixedManipulator operator&(const ShFixedManipulator &m, const ShFixedManipulator &n) { 00202 return new ShTreeManipNode(m, n); 00203 } 00204 00205 ShFixedManipulator operator&(const ShFixedManipulator &m, const ShProgram &p) { 00206 return m & new ShProgramManipNode(p); 00207 } 00208 ShFixedManipulator operator&(const ShProgram &p, const ShFixedManipulator &m) { 00209 return new ShProgramManipNode(p) & m; 00210 } 00211 00212 } 00213

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