00001 #ifndef SYSTEMC_DEFINITION_H_INCLUDED_
00002 #define SYSTEMC_DEFINITION_H_INCLUDED_
00003
00004 #include "rose.h"
00005
00006 #include "rose_nodes.h"
00007
00008 namespace risc {
00009
00010 namespace tools {
00011
00016 class SystemCDefinitions {
00017
00018 public:
00019
00020 static SgClassDefinition* get_sc_module()
00021 {
00022 initialize();
00023 return sc_module_;
00024 }
00025
00026 static SgClassDefinition* get_sc_port()
00027 {
00028 initialize();
00029 return sc_port_;
00030 }
00031
00032 static SgClassDefinition* get_sc_port_base()
00033 {
00034 initialize();
00035 return sc_port_base_;
00036 }
00037
00038 static SgClassDefinition* get_sc_in()
00039 {
00040 initialize();
00041 return sc_in_;
00042 }
00043
00044 static SgClassDefinition* get_sc_out()
00045 {
00046 initialize();
00047 return sc_out_;
00048 }
00049
00050 static SgClassDefinition* get_sc_inout()
00051 {
00052 initialize();
00053 return sc_inout_;
00054 }
00055
00056 static SgClassDefinition* get_sc_event()
00057 {
00058 initialize();
00059 return sc_event_;
00060 }
00061
00062 static SgClassDefinition* get_sc_event_and_list()
00063 {
00064 initialize();
00065 return sc_event_and_list_;
00066 }
00067
00068 static SgClassDefinition* get_sc_event_or_list()
00069 {
00070 initialize();
00071 return sc_event_or_list_;
00072 }
00073
00074 static SgClassDefinition* get_sc_prim_channel()
00075 {
00076 initialize();
00077 return sc_prim_channel_;
00078 }
00079
00080 static SgClassDefinition* get_sc_interface()
00081 {
00082 initialize();
00083 return sc_interface_;
00084 }
00085
00086 static SgClassDefinition* get_sc_channel()
00087 {
00088 initialize();
00089 return sc_channel_;
00090 }
00091
00092 static SgClassDefinition* get_sc_in_clk()
00093 {
00094 initialize();
00095 return sc_in_clk_;
00096 }
00097
00098 static SgClassDefinition* get_sc_out_clk()
00099 {
00100 initialize();
00101 return sc_out_clk_;
00102 }
00103
00104 static SgClassDefinition* get_sc_inout_clk()
00105 {
00106 initialize();
00107 return sc_inout_clk_;
00108 }
00109
00110 static SgClassDefinition* get_sc_fifo()
00111 {
00112 initialize();
00113 return sc_fifo_;
00114 }
00115
00116 static SgClassDefinition* get_sc_fifo_in()
00117 {
00118 initialize();
00119 return sc_fifo_in_;
00120 }
00121
00122 static SgClassDefinition* get_sc_fifo_out()
00123 {
00124 initialize();
00125 return sc_fifo_out_;
00126 }
00127
00128 static SgFunctionDefinition* get_sc_main()
00129 {
00130 initialize();
00131 return sc_main_;
00132 }
00133
00134 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_core()
00135 {
00136 initialize();
00137 return sc_core_;
00138 }
00139
00140 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_dt()
00141 {
00142 initialize();
00143 return sc_dt_;
00144 }
00145
00146 static const std::set<SgFunctionDefinition*>& get_sc_wait_funcs()
00147 {
00148 initialize();
00149 return sc_wait_funcs_;
00150 }
00151
00152 private:
00153 static void initialize()
00154 {
00155 if(is_initialized_ == true) {
00156 return;
00157 }
00158
00159 sc_module_ = NULL;
00160 sc_port_ = NULL;
00161 sc_port_base_ = NULL;
00162 sc_in_ = NULL;
00163 sc_out_ = NULL;
00164 sc_inout_ = NULL;
00165 sc_event_ = NULL;
00166 sc_event_and_list_ = NULL;
00167 sc_event_or_list_ = NULL;
00168 sc_prim_channel_ = NULL;
00169 sc_interface_ = NULL;
00170 sc_channel_ = NULL;
00171 sc_in_clk_ = NULL;
00172 sc_out_clk_ = NULL;
00173 sc_inout_clk_ = NULL;
00174 sc_fifo_ = NULL;
00175 sc_fifo_in_ = NULL;
00176 sc_fifo_out_ = NULL;
00177
00178 sc_main_ = NULL;
00179
00180 const std::vector<SgNode*> &class_defs = RoseNodes::get_class_defs();
00181 for(std::vector<SgNode*>::const_iterator
00182 iter = class_defs.begin();
00183 iter != class_defs.end();
00184 iter++) {
00185
00186 SgClassDefinition* class_def = isSgClassDefinition(*iter);
00187 std::string qualified_name = class_def->get_qualified_name();
00188
00189 #define COMPARE_NAME(QualifiedName, Variable) \
00190 if(qualified_name == #QualifiedName) { \
00191 sc_##Variable = class_def; \
00192 continue; \
00193 }
00194 COMPARE_NAME(::sc_core::sc_module, module_);
00195 COMPARE_NAME(::sc_core::sc_port, port_);
00196 COMPARE_NAME(::sc_core::sc_port_base, port_base_);
00197 COMPARE_NAME(::sc_core::sc_in, in_);
00198 COMPARE_NAME(::sc_core::sc_inout, inout_);
00199 COMPARE_NAME(::sc_core::sc_out, out_);
00200 COMPARE_NAME(::sc_core::sc_event, event_);
00201 COMPARE_NAME(::sc_core::sc_event_and_list, event_and_list_);
00202 COMPARE_NAME(::sc_core::sc_event_or_list, event_or_list_);
00203 COMPARE_NAME(::sc_core::sc_prim_channel, prim_channel_);
00204 COMPARE_NAME(::sc_core::sc_interface, interface_);
00205 COMPARE_NAME(::sc_core::sc_channel, channel_);
00206 COMPARE_NAME(::sc_core::sc_fifo, fifo_);
00207 COMPARE_NAME(::sc_core::sc_fifo_in, fifo_in_);
00208 COMPARE_NAME(::sc_core::sc_fifo_out, fifo_out_);
00209
00210
00211
00212
00213
00214 COMPARE_NAME(::sc_core::sc_in_clk, in_clk_);
00215 COMPARE_NAME(::sc_core::sc_out_clk, out_clk_);
00216 COMPARE_NAME(::sc_core::sc_inout_clk, inout_clk_);
00217 #undef COMPARE_NAME
00218 }
00219
00220
00221 const std::vector<SgNode*> &temp_namespaces
00222 = risc::tools::RoseNodes::get_namespace_defs();
00223 for(std::vector<SgNode*>::const_iterator
00224 iter = temp_namespaces.begin();
00225 iter != temp_namespaces.end();
00226 iter++) {
00227
00228 SgNamespaceDefinitionStatement *namespace_def
00229 = isSgNamespaceDefinitionStatement(*iter);
00230 std::string qualified_name = namespace_def->get_qualified_name();
00231
00232 #define COMPARE_NAME(QualifiedName, Variable) \
00233 if(qualified_name == #QualifiedName) { \
00234 sc_##Variable.push_back(namespace_def); \
00235 continue; \
00236 }
00237 COMPARE_NAME(::sc_core, core_);
00238 COMPARE_NAME(::sc_dt, dt_);
00239 #undef COMPARE_NAME
00240 }
00241
00242
00243 const std::vector<SgNode*> &temp_wait_func_def
00244 = risc::tools::RoseNodes::get_func_defs();
00245
00246 for(std::vector<SgNode*>::const_iterator
00247 iter = temp_wait_func_def.begin();
00248 iter != temp_wait_func_def.end();
00249 iter++) {
00250
00251 SgFunctionDefinition *func_def = isSgFunctionDefinition(*iter);
00252 std::string qualified_name
00253 = func_def->get_declaration()->get_qualified_name();
00254
00255 #define COMPARE_NAME(QualifiedName, Variable) \
00256 if(qualified_name == #QualifiedName) { \
00257 sc_##Variable = func_def; \
00258 continue; \
00259 }
00260 COMPARE_NAME(::sc_main, main_);
00261 #undef COMPARE_NAME
00262
00263 SgClassDefinition *enclosing_class_def
00264 = SageInterface::getEnclosingClassDefinition(func_def);
00265
00266
00267 if(enclosing_class_def == sc_module_) {
00268 if(SageInterface::get_name(func_def) == "wait") {
00269 sc_wait_funcs_.insert(func_def);
00270 }
00271 }
00272
00273 if(enclosing_class_def == sc_prim_channel_) {
00274 if(SageInterface::get_name(func_def) == "wait") {
00275 sc_wait_funcs_.insert(func_def);
00276 }
00277 }
00278 }
00279
00280 SystemCDefinitions::is_initialized_ = true;
00281
00282 #if 0
00283 std::cout << "sc_module_ " << sc_module_ << std::endl;
00284 std::cout << "sc_port_ " << sc_port_ << std::endl;
00285 std::cout << "sc_port_base_ " << sc_port_base_ << std::endl;
00286 std::cout << "sc_in_ " << sc_in_ << std::endl;
00287 std::cout << "sc_inout_ " << sc_inout_ << std::endl;
00288 std::cout << "sc_out_ " << sc_out_ << std::endl;
00289 std::cout << "sc_event_ " << sc_event_ << std::endl;
00290 std::cout << "sc_event_and_list_ " << sc_event_and_list_ << std::endl;
00291 std::cout << "sc_event_or_list_ " << sc_event_or_list_ << std::endl;
00292 std::cout << "sc_prim_channel_ " << sc_prim_channel_ << std::endl;
00293 std::cout << "sc_channel_ " << sc_channel_ << std::endl;
00294 std::cout << "sc_in_clk_ " << sc_in_clk_ << std::endl;
00295 std::cout << "sc_out_clk_ " << sc_out_clk_ << std::endl;
00296 std::cout << "sc_inout_clk_ " << sc_inout_clk_ << std::endl;
00297 std::cout << "sc_fifo_ " << sc_fifo_ << std::endl;
00298 std::cout << "sc_fifo_in_ " << sc_fifo_in_ << std::endl;
00299 std::cout << "sc_fifo_out_ " << sc_fifo_out_ << std::endl;
00300 std::cout << "sc_main_: " << sc_main_ << std::endl;
00301 std::cout << "sc_core_ " << sc_core_.size() << std::endl;
00302 std::cout << "sc_dt_ " << sc_dt_.size() << std::endl;
00303 std::cout << "sc_wait_funcs_: " << sc_wait_funcs_.size() << std::endl;
00304 #endif
00305 }
00306
00307
00308
00309
00310 static SgClassDefinition *sc_module_;
00311 static SgClassDefinition *sc_port_;
00312 static SgClassDefinition *sc_port_base_;
00313 static SgClassDefinition *sc_in_;
00314 static SgClassDefinition *sc_out_;
00315 static SgClassDefinition *sc_inout_;
00316 static SgClassDefinition *sc_event_;
00317 static SgClassDefinition *sc_event_and_list_;
00318 static SgClassDefinition *sc_event_or_list_;
00319 static SgClassDefinition *sc_prim_channel_;
00320 static SgClassDefinition *sc_interface_;
00321 static SgClassDefinition *sc_fifo_;
00322 static SgClassDefinition *sc_fifo_in_;
00323 static SgClassDefinition *sc_fifo_out_;
00324
00325
00326 static SgClassDefinition *sc_channel_;
00327 static SgClassDefinition *sc_in_clk_;
00328 static SgClassDefinition *sc_out_clk_;
00329 static SgClassDefinition *sc_inout_clk_;
00330
00331 static SgFunctionDefinition *sc_main_;
00332
00333
00334 static std::vector<SgNamespaceDefinitionStatement*> sc_core_;
00335 static std::vector<SgNamespaceDefinitionStatement*> sc_dt_;
00336
00337
00338 static std::set<SgFunctionDefinition*> sc_wait_funcs_;
00339
00340 static bool is_initialized_;
00341 };
00342
00343 };
00344
00345 };
00346
00347 #endif
00348
00349