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

Gcc.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 SHGCC_HPP 00028 #define SHGCC_HPP 00029 00030 #include <map> 00031 #include <string> 00032 #include <sstream> 00033 00034 #include "ShBackend.hpp" 00035 00036 typedef void (*GccFunc)(float** inputs, 00037 float** params, 00038 float** streams, 00039 void** textures, 00040 float** outputs); 00041 00042 namespace ShGcc { 00043 00044 class GccVariable 00045 { 00046 public: 00047 GccVariable(void); 00048 GccVariable(int num, const std::string& name); 00049 GccVariable(int num, const std::string& name, int size); 00050 00051 public: 00052 int m_num; 00053 std::string m_name; 00054 int m_size; 00055 }; 00056 00057 class GccBackendCode: public SH::ShBackendCode 00058 { 00059 public: 00060 GccBackendCode(const SH::ShProgramNodeCPtr& program); 00061 ~GccBackendCode(void); 00062 00063 bool allocateRegister(const SH::ShVariableNodePtr& var); 00064 void freeRegister(const SH::ShVariableNodePtr& var); 00065 00066 void upload(void); 00067 void bind(void); 00068 00069 void updateUniform(const SH::ShVariableNodePtr& uniform); 00070 00071 std::ostream& print(std::ostream& out); 00072 00073 std::ostream& printInputOutputFormat(std::ostream& out); 00074 00075 protected: 00076 friend class GccBackend; 00077 bool generate(void); 00078 bool execute(SH::ShStream& dest); 00079 00080 private: 00081 void allocate_consts(void); 00082 void allocate_inputs(void); 00083 void allocate_outputs(void); 00084 void allocate_streams(void); 00085 void allocate_textures(void); 00086 void allocate_uniforms(void); 00087 00088 std::string resolve(const SH::ShVariable& v); 00089 std::string resolve(const SH::ShVariable& v, int idx); 00090 00091 class LabelFunctor 00092 { 00093 public: 00094 LabelFunctor(std::map<SH::ShCtrlGraphNodePtr, int>& label_map); 00095 00096 void operator()(SH::ShCtrlGraphNode* node); 00097 00098 public: 00099 int m_cur_label; 00100 std::map<SH::ShCtrlGraphNodePtr, int>& m_label_map; 00101 }; 00102 00103 class EmitFunctor 00104 { 00105 public: 00106 EmitFunctor(GccBackendCode* bec); 00107 00108 void operator()(SH::ShCtrlGraphNode* node); 00109 00110 public: 00111 GccBackendCode* m_bec; 00112 }; 00113 00114 void emit(const SH::ShStatement& stmt); 00115 void emit(SH::ShBasicBlockPtr block); 00116 void emit(SH::ShCtrlGraphNodePtr node); 00117 00118 private: 00119 const SH::ShProgramNodeCPtr& m_program; 00120 00121 std::map<SH::ShCtrlGraphNodePtr, int> m_label_map; 00122 std::map<SH::ShVariableNodePtr, GccVariable> m_varmap; 00123 00124 std::stringstream m_code; 00125 00126 void* m_handle; 00127 GccFunc m_func; 00128 00129 int m_cur_temp; 00130 00131 float** m_params; 00132 std::vector<SH::ShChannelNodePtr> m_streams; 00133 std::vector<GccVariable> m_temps; 00134 std::vector<SH::ShTextureNodePtr> m_textures; 00135 }; 00136 00137 class GccBackend: public SH::ShBackend 00138 { 00139 public: 00140 GccBackend(void); 00141 ~GccBackend(void); 00142 00143 std::string name(void) const; 00144 00145 SH::ShBackendCodePtr generateCode(const std::string& target, 00146 const SH::ShProgramNodeCPtr& program); 00147 00148 void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest); 00149 }; 00150 00151 00152 typedef SH::ShPointer<GccBackendCode> GccBackendCodePtr; 00153 typedef SH::ShPointer<GccBackend> GccBackendPtr; 00154 } 00155 00156 #endif

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