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

ShStatement.hpp

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 #ifndef SHSTATEMENT_HPP
00028 #define SHSTATEMENT_HPP
00029 
00030 #include <iosfwd>
00031 #include <set>
00032 #include <list>
00033 #include "ShOperation.hpp"
00034 #include "ShDllExport.hpp"
00035 #include "ShVariable.hpp"
00036 
00037 namespace SH {
00038 
00042 class 
00043 SH_DLLEXPORT
00044 ShStatementInfo {
00045 public:
00046   virtual ~ShStatementInfo();
00047 
00048   virtual ShStatementInfo* clone() const = 0;
00049   
00050 protected:
00051   ShStatementInfo();
00052 
00053 };
00054 
00063 class
00064 SH_DLLEXPORT ShStatement {
00065 public:
00066   ShStatement(ShVariable dest, ShOperation op);
00067   ShStatement(ShVariable dest, ShOperation op, ShVariable src);
00068   ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1);
00069   ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2);
00070   ShStatement(const ShStatement& other);
00071   
00072   ~ShStatement();
00073 
00074   ShStatement& operator=(const ShStatement& other);
00075   
00076   
00077   ShVariable dest;
00078   ShVariable src[3];
00079   
00080   ShOperation op;
00081 
00082   // Used by the optimizer and anything else that needs to store extra
00083   // information in statements.
00084   // Anything in here will be deleted when this statement is deleted.
00085   std::list<ShStatementInfo*> info;
00086 
00087   // Return the first entry in info whose type matches T, or 0 if no
00088   // such entry exists.
00089   template<typename T>
00090   T* get_info();
00091 
00092   // Delete and remove all info entries matching the given type.
00093   template<typename T>
00094   void destroy_info();
00095 
00096   // Add the given statement information to the end of the info list.
00097   void add_info(ShStatementInfo* new_info);
00098 
00099   // Remove the given statement information from the list.
00100   // Does not delete it, so be careful!
00101   void remove_info(ShStatementInfo* old_info);
00102   
00103   bool marked;
00104 
00105   friend SH_DLLEXPORT std::ostream& operator<<(std::ostream& out, const SH::ShStatement& stmt);
00106 };
00107 
00108 
00109 template<typename T>
00110 T* ShStatement::get_info()
00111 {
00112   for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) {
00113     T* item = dynamic_cast<T*>(*I);
00114     if (item) {
00115       return item;
00116     }
00117   }
00118   return 0;
00119 }
00120 
00121 template<typename T>
00122 void ShStatement::destroy_info()
00123 {
00124   for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end();) {
00125     T* item = dynamic_cast<T*>(*I);
00126     if (item) {
00127       I = info.erase(I);
00128       delete item;
00129     } else {
00130       ++I;
00131     }
00132   }
00133 }
00134 
00135 } // namespace SH
00136 
00137 #endif

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