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

ShSyntax.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHSYNTAX_HPP
00025 #define SHSYNTAX_HPP
00026 
00027 #include "ShDllExport.hpp"
00028 #include "ShProgram.hpp"
00029 #include "ShUtility.hpp"
00030 
00035 
00036 
00037 #define SH_PUSH_ARG_QUEUE ::SH::shPushArgQueue()
00038 #define SH_PUSH_ARG ::SH::shPushArg()
00039 #define SH_PROCESS_ARG(arg, internal_cond) ::SH::shProcessArg(arg, internal_cond)
00040 
00041 
00043 
00044 
00050 #define SH_BEGIN_PROGRAM(target) ::SH::shBeginShader(target);
00051 
00059 #define SH_END_PROGRAM         ::SH::shEndShader();
00060 
00061 
00062 #define SH_END                 SH_END_PROGRAM
00063 
00064 #define SH_BEGIN_VERTEX_PROGRAM ::SH::shBeginShader("gpu:vertex");
00065 #define SH_BEGIN_FRAGMENT_PROGRAM ::SH::shBeginShader("gpu:fragment");
00066 
00068 
00069 
00074 #define SH_IF(cond) { \
00075   bool sh__internal_cond; \
00076   ::SH::shIf(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, &sh__internal_cond)); \
00077   if (ShContext::current()->parsing() || sh__internal_cond) {{
00078 
00083 #define SH_ELSE  \
00084   }} \
00085   ::SH::shElse(); \
00086   if (ShContext::current()->parsing() || !sh__internal_cond) {{
00087 
00092 #define SH_ENDIF \
00093   }} \
00094   ::SH::shEndIf(); \
00095 }
00096 
00097 
00099 
00100 
00104 #define SH_WHILE(cond) { \
00105   bool sh__internal_cond; \
00106   ::SH::shWhile(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, &sh__internal_cond)); \
00107   bool sh__internal_firsttime = true; \
00108   while ((sh__internal_firsttime && (ShContext::current()->parsing() || sh__internal_cond)) \
00109          || (!ShContext::current()->parsing() && ::SH::shEvaluateCondition(cond))) {{{
00110 
00114 #define SH_ENDWHILE \
00115     sh__internal_firsttime = false; \
00116   }}} \
00117   ::SH::shEndWhile(); \
00118 }
00119 
00120 
00122 
00123 
00127 #define SH_DO       { \
00128   ::SH::shDo(); \
00129   do {{{{
00130 
00134 #define SH_UNTIL(cond) \
00135   }}}} while (!ShContext::current()->parsing() && ::SH::shEvaluateCondition(cond)); \
00136   if (ShContext::current()->parsing()) ::SH::shUntil(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, 0)); }
00137 
00138 
00140 
00141 
00147 // TODO: It is possible to make declaring variables in init work. do so.
00148 #define SH_FOR(init,cond,update) { \
00149   if (ShContext::current()->parsing()) \
00150     ::SH::shFor(SH_PUSH_ARG_QUEUE \
00151              && SH_PUSH_ARG && SH_PROCESS_ARG(init, 0) \
00152              && SH_PUSH_ARG && SH_PROCESS_ARG(cond, 0) \
00153              && SH_PUSH_ARG && SH_PROCESS_ARG(update, 0)); \
00154   if (!ShContext::current()->parsing()) init; \
00155   bool sh__internal_first_time = true; \
00156   while (1) {{{{{ \
00157     if (!ShContext::current()->parsing()) { \
00158       if (!sh__internal_first_time) { update; } \
00159       else { sh__internal_first_time = false; } \
00160       if (!shEvaluateCondition(cond)) break; \
00161     }                                                                                  
00162 
00166 #define SH_ENDFOR \
00167     if (ShContext::current()->parsing()) break; \
00168   }}}}} \
00169   ::SH::shEndFor(); \
00170 }
00171 
00172 
00174 
00175 
00182 #define SH_BREAK    if (!ShContext::current()->parsing()) { break; } else { ::SH::shBreak(); }
00183 
00190 #define SH_CONTINUE if (!ShContext::current()->parsing()) { continue; } else { ::SH::shBreak(); }
00191 
00192 
00201 #define SH_BEGIN_SECTION(name) \
00202   {{{{{{ \
00203     if(ShContext::current()->parsing()) { \
00204       ::SH::shBeginSection(); \
00205       ::SH::shComment(name); \
00206     }
00207 
00208 #define SH_END_SECTION \
00209     if(ShContext::current()->parsing()) { ::SH::shEndSection(); } \
00210   }}}}}} 
00211 
00212 
00214 
00215 
00221 #define SH_NAME(var) do { var.name( # var); } while (0)
00222 
00232 #define SH_DECL(var) var; var.name( # var ); ::SH::ShIgnore() & var
00233 
00242 #define SH_NAMEDECL(var, varName) var; var.name( varName ); ::SH::ShIgnore() & var
00243 
00244 
00245 namespace SH {
00246 
00248 SH_DLLEXPORT
00249 bool shProcessArg(const ShVariable& arg, bool* internal_cond);
00250 
00252 SH_DLLEXPORT
00253 bool shPushArg();
00254 
00256 SH_DLLEXPORT
00257 bool shPushArgQueue();
00258 
00260 SH_DLLEXPORT
00261 bool shEvaluateCondition(const ShVariable& arg);
00262 
00264 SH_DLLEXPORT
00265 ShProgram shBeginShader(const std::string& kind = "");
00267 SH_DLLEXPORT
00268 void shEndShader();
00269 
00271 SH_DLLEXPORT
00272 void shCompile(ShProgram& prg);
00274 SH_DLLEXPORT
00275 void shCompile(ShProgram& prg, const std::string& target);
00276 
00278 SH_DLLEXPORT
00279 void shCompileShader(ShProgram& prg);
00281 SH_DLLEXPORT
00282 void shCompileShader(ShProgram& prg, const std::string& target);
00283 
00285 SH_DLLEXPORT
00286 void shBind(ShProgram& prg);
00288 SH_DLLEXPORT
00289 void shBind(const std::string& target, ShProgram& shader);
00290 
00292 SH_DLLEXPORT
00293 void shBindShader(ShProgram& shader);
00295 SH_DLLEXPORT
00296 void shBindShader(const std::string& target, ShProgram& shader);
00297 
00299 SH_DLLEXPORT
00300 void shBind(const ShProgramSet& s);
00301 
00303 SH_DLLEXPORT
00304 void shUnbind();
00305 
00307 SH_DLLEXPORT
00308 void shUnbind(ShProgram& prg);
00310 SH_DLLEXPORT
00311 void shUnbind(const std::string& target, ShProgram& shader);
00312 
00314 SH_DLLEXPORT
00315 void shUnbind(const ShProgramSet& s);
00316 
00318 SH_DLLEXPORT
00319 void shLink(const ShProgramSet& s);
00320 
00324 SH_DLLEXPORT
00325 void shUpdate();
00326 
00328 SH_DLLEXPORT
00329 bool shSetBackend(const std::string& name);
00330 
00336 SH_DLLEXPORT
00337 void shInit();
00338 
00340 SH_DLLEXPORT
00341 void shIf(bool);
00343 SH_DLLEXPORT
00344 void shElse();
00346 SH_DLLEXPORT
00347 void shEndIf();
00348 
00350 SH_DLLEXPORT
00351 void shWhile(bool);
00353 SH_DLLEXPORT
00354 void shEndWhile();
00355 
00357 SH_DLLEXPORT
00358 void shDo();
00360 SH_DLLEXPORT
00361 void shUntil(bool);
00362 
00364 SH_DLLEXPORT
00365 void shFor(bool);
00367 SH_DLLEXPORT
00368 void shEndFor();
00369 
00371 SH_DLLEXPORT
00372 void shBreak();
00374 SH_DLLEXPORT
00375 void shContinue();
00376 
00378 SH_DLLEXPORT
00379 void shBeginSection();
00381 SH_DLLEXPORT
00382 void shEndSection();
00383 
00386 SH_DLLEXPORT
00387 void shComment(const std::string& comment);
00388 
00389 }
00390 
00391 #endif

Generated on Thu Apr 21 17:32:49 2005 for Sh by  doxygen 1.4.2