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 SgClassDefinition* get_sc_simcontext()
00135 {
00136 initialize();
00137 return sc_simcontext_;
00138 }
00139
00140 static SgClassDefinition* get_sc_segid()
00141 {
00142 initialize();
00143 return sc_segid_;
00144 }
00145
00146 static SgClassDefinition* get_sc_process_b()
00147 {
00148 initialize();
00149 return sc_process_b_;
00150 }
00151
00152 static SgFunctionDeclaration* get_sc_curr_proc()
00153 {
00154 initialize();
00155 return sc_get_curr_proc_;
00156 }
00157
00158 static SgFunctionDeclaration* get_sc_segid_ctor()
00159 {
00160 initialize();
00161 return sc_segid_ctor_;
00162 }
00163
00164 static SgFunctionDeclaration* get_sc_get_curr_simcontext()
00165 {
00166 initialize();
00167 return sc_get_curr_simcontext_;
00168 }
00169
00170 static SgFunctionDeclaration* get_get_upcoming_segment_ids()
00171 {
00172 initialize();
00173 return get_upcoming_segment_ids_;
00174 }
00175
00176 static SgFunctionDeclaration* get_set_upcoming_segment_ids()
00177 {
00178 initialize();
00179 return set_upcoming_segment_ids_;
00180 }
00181
00182 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_core()
00183 {
00184 initialize();
00185 return sc_core_;
00186 }
00187
00188 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_dt()
00189 {
00190 initialize();
00191 return sc_dt_;
00192 }
00193
00194 static const std::set<SgFunctionDefinition*>& get_sc_wait_funcs()
00195 {
00196 initialize();
00197 return sc_wait_funcs_;
00198 }
00199
00200 static const SgMemberFunctionDeclaration* get_interface()
00201 {
00202 initialize();
00203 return get_interface_;
00204 }
00205
00206 private:
00207 static void initialize()
00208 {
00209 if(is_initialized_ == true) {
00210 return;
00211 }
00212
00213 sc_module_ = NULL;
00214 sc_port_ = NULL;
00215 sc_port_base_ = NULL;
00216 sc_in_ = NULL;
00217 sc_out_ = NULL;
00218 sc_inout_ = NULL;
00219 sc_event_ = NULL;
00220 sc_event_and_list_ = NULL;
00221 sc_event_or_list_ = NULL;
00222 sc_prim_channel_ = NULL;
00223 sc_interface_ = NULL;
00224 sc_channel_ = NULL;
00225 sc_in_clk_ = NULL;
00226 sc_out_clk_ = NULL;
00227 sc_inout_clk_ = NULL;
00228 sc_fifo_ = NULL;
00229 sc_fifo_in_ = NULL;
00230 sc_fifo_out_ = NULL;
00231
00232 sc_simcontext_ = NULL;
00233 sc_segid_ = NULL;
00234 sc_process_b_ = NULL;
00235 sc_get_curr_simcontext_ = NULL;
00236 sc_get_curr_proc_ = NULL;
00237 sc_segid_ctor_ = NULL;
00238 get_upcoming_segment_ids_ = NULL;
00239 set_upcoming_segment_ids_ = NULL;
00240
00241 sc_main_ = NULL;
00242
00243 const std::vector<SgNode*> &class_defs = RoseNodes::get_class_defs();
00244 for(std::vector<SgNode*>::const_iterator
00245 iter = class_defs.begin();
00246 iter != class_defs.end();
00247 iter++) {
00248
00249 SgClassDefinition* class_def = isSgClassDefinition(*iter);
00250 std::string qualified_name = class_def->get_qualified_name();
00251
00252 #define COMPARE_NAME(QualifiedName, Variable) \
00253 if(qualified_name == #QualifiedName) { \
00254 sc_##Variable = class_def; \
00255 continue; \
00256 }
00257 COMPARE_NAME(::sc_core::sc_module, module_);
00258 COMPARE_NAME(::sc_core::sc_port, port_);
00259 COMPARE_NAME(::sc_core::sc_port_base, port_base_);
00260 COMPARE_NAME(::sc_core::sc_in, in_);
00261 COMPARE_NAME(::sc_core::sc_inout, inout_);
00262 COMPARE_NAME(::sc_core::sc_out, out_);
00263 COMPARE_NAME(::sc_core::sc_event, event_);
00264 COMPARE_NAME(::sc_core::sc_event_and_list, event_and_list_);
00265 COMPARE_NAME(::sc_core::sc_event_or_list, event_or_list_);
00266 COMPARE_NAME(::sc_core::sc_prim_channel, prim_channel_);
00267 COMPARE_NAME(::sc_core::sc_interface, interface_);
00268 COMPARE_NAME(::sc_core::sc_channel, channel_);
00269 COMPARE_NAME(::sc_core::sc_fifo, fifo_);
00270 COMPARE_NAME(::sc_core::sc_fifo_in, fifo_in_);
00271 COMPARE_NAME(::sc_core::sc_fifo_out, fifo_out_);
00272 COMPARE_NAME(::sc_core::sc_simcontext, simcontext_);
00273 COMPARE_NAME(::sc_core::sc_segid, segid_);
00274 COMPARE_NAME(::sc_core::sc_process_b, process_b_);
00275
00276
00277
00278
00279
00280 COMPARE_NAME(::sc_core::sc_in_clk, in_clk_);
00281 COMPARE_NAME(::sc_core::sc_out_clk, out_clk_);
00282 COMPARE_NAME(::sc_core::sc_inout_clk, inout_clk_);
00283 #undef COMPARE_NAME
00284 }
00285
00286
00287 const std::vector<SgNode*> &temp_namespaces
00288 = risc::tools::RoseNodes::get_namespace_defs();
00289 for(std::vector<SgNode*>::const_iterator
00290 iter = temp_namespaces.begin();
00291 iter != temp_namespaces.end();
00292 iter++) {
00293
00294 SgNamespaceDefinitionStatement *namespace_def
00295 = isSgNamespaceDefinitionStatement(*iter);
00296 std::string qualified_name = namespace_def->get_qualified_name();
00297
00298 #define COMPARE_NAME(QualifiedName, Variable) \
00299 if(qualified_name == #QualifiedName) { \
00300 sc_##Variable.push_back(namespace_def); \
00301 continue; \
00302 }
00303 COMPARE_NAME(::sc_core, core_);
00304 COMPARE_NAME(::sc_dt, dt_);
00305 #undef COMPARE_NAME
00306 }
00307
00308
00309 const std::vector<SgNode*> &temp_wait_func_def
00310 = risc::tools::RoseNodes::get_func_defs();
00311
00312 for(std::vector<SgNode*>::const_iterator
00313 iter = temp_wait_func_def.begin();
00314 iter != temp_wait_func_def.end();
00315 iter++) {
00316
00317 SgFunctionDefinition *func_def = isSgFunctionDefinition(*iter);
00318 std::string qualified_name
00319 = func_def->get_declaration()->get_qualified_name();
00320
00321 #define COMPARE_NAME(QualifiedName, Variable) \
00322 if(qualified_name == #QualifiedName) { \
00323 sc_##Variable = func_def; \
00324 continue; \
00325 }
00326 COMPARE_NAME(::sc_main, main_);
00327 #undef COMPARE_NAME
00328
00329 SgClassDefinition *enclosing_class_def
00330 = SageInterface::getEnclosingClassDefinition(func_def);
00331
00332
00333 if(enclosing_class_def == sc_module_) {
00334 if(SageInterface::get_name(func_def) == "wait") {
00335 sc_wait_funcs_.insert(func_def);
00336 }
00337 }
00338
00339 if(enclosing_class_def == sc_prim_channel_) {
00340 if(SageInterface::get_name(func_def) == "wait") {
00341 sc_wait_funcs_.insert(func_def);
00342 }
00343 }
00344 }
00345
00346 std::vector<SgNode*> func_defs
00347 = NodeQuery::querySubTree(sc_process_b_, V_SgFunctionDeclaration);
00348 for(std::vector<SgNode*>::iterator
00349 iter = func_defs.begin();
00350 iter != func_defs.end();
00351 iter++) {
00352 if(SageInterface::get_name(*iter) == "get_upcoming_segment_ids") {
00353 get_upcoming_segment_ids_ = isSgMemberFunctionDeclaration(*iter);
00354 get_upcoming_segment_ids_
00355 = isSgMemberFunctionDeclaration(
00356 get_upcoming_segment_ids_
00357 ->get_declaration_associated_with_symbol());
00358 }
00359 if(SageInterface::get_name(*iter) == "set_upcoming_segment_ids") {
00360 set_upcoming_segment_ids_ = isSgMemberFunctionDeclaration(*iter);
00361 set_upcoming_segment_ids_
00362 = isSgMemberFunctionDeclaration(
00363 set_upcoming_segment_ids_
00364 ->get_declaration_associated_with_symbol());
00365 }
00366 }
00367
00368 func_defs
00369 = NodeQuery::querySubTree(sc_simcontext_, V_SgMemberFunctionDeclaration);
00370 for(std::vector<SgNode*>::iterator
00371 iter = func_defs.begin();
00372 iter != func_defs.end();
00373 iter++) {
00374 if(SageInterface::get_name(*iter) == "get_curr_proc") {
00375 sc_get_curr_proc_ = isSgMemberFunctionDeclaration(*iter);
00376 sc_get_curr_proc_
00377 = isSgMemberFunctionDeclaration(
00378 sc_get_curr_proc_->get_declaration_associated_with_symbol());
00379 }
00380 }
00381
00382 func_defs
00383 = NodeQuery::querySubTree(sc_segid_, V_SgMemberFunctionDeclaration);
00384 for(std::vector<SgNode*>::iterator
00385 iter = func_defs.begin();
00386 iter != func_defs.end();
00387 iter++) {
00388
00389 if(SageInterface::get_name(*iter) == "sc_segid") {
00390 sc_segid_ctor_ = isSgMemberFunctionDeclaration(*iter);
00391 sc_segid_ctor_
00392 = isSgMemberFunctionDeclaration(
00393 sc_segid_ctor_->get_declaration_associated_with_symbol());
00394 }
00395 }
00396
00397 func_defs
00398 = NodeQuery::querySubTree(sc_port_base_, V_SgMemberFunctionDeclaration);
00399 for(std::vector<SgNode*>::iterator
00400 iter = func_defs.begin();
00401 iter != func_defs.end();
00402 iter++) {
00403 if(SageInterface::get_name(*iter) == "get_interface") {
00404 get_interface_ = isSgMemberFunctionDeclaration(*iter);
00405 get_interface_
00406 = isSgMemberFunctionDeclaration(
00407 get_interface_->get_declaration_associated_with_symbol());
00408 }
00409 }
00410
00411 for(std::vector<SgNamespaceDefinitionStatement*>::iterator
00412 namespace_iter = sc_core_.begin();
00413 namespace_iter != sc_core_.end();
00414 namespace_iter++) {
00415
00416 func_defs = NodeQuery::querySubTree(
00417 *namespace_iter, V_SgFunctionDeclaration);
00418
00419 bool found = false;
00420 for(std::vector<SgNode*>::iterator
00421 iter = func_defs.begin();
00422 iter != func_defs.end();
00423 iter++) {
00424
00425 if(SageInterface::get_name(*iter) == "sc_get_curr_simcontext") {
00426 sc_get_curr_simcontext_ = isSgFunctionDeclaration(*iter);
00427 sc_get_curr_simcontext_
00428 = isSgFunctionDeclaration(
00429 sc_get_curr_simcontext_
00430 ->get_declaration_associated_with_symbol());
00431 found = true;
00432 }
00433 }
00434
00435 if(found) {
00436 break;
00437 }
00438 }
00439
00440 SystemCDefinitions::is_initialized_ = true;
00441
00442 #if 0
00443 std::cout << "sc_process_b_ " << sc_process_b_ << std::endl;
00444 std::cout << "sc_simcontext_ " << sc_simcontext_ << std::endl;
00445 std::cout << "sc_module_ " << sc_module_ << std::endl;
00446 std::cout << "sc_port_ " << sc_port_ << std::endl;
00447 std::cout << "sc_port_base_ " << sc_port_base_ << std::endl;
00448 std::cout << "sc_in_ " << sc_in_ << std::endl;
00449 std::cout << "sc_inout_ " << sc_inout_ << std::endl;
00450 std::cout << "sc_out_ " << sc_out_ << std::endl;
00451 std::cout << "sc_event_ " << sc_event_ << std::endl;
00452 std::cout << "sc_event_and_list_ " << sc_event_and_list_ << std::endl;
00453 std::cout << "sc_event_or_list_ " << sc_event_or_list_ << std::endl;
00454 std::cout << "sc_prim_channel_ " << sc_prim_channel_ << std::endl;
00455 std::cout << "sc_channel_ " << sc_channel_ << std::endl;
00456 std::cout << "sc_in_clk_ " << sc_in_clk_ << std::endl;
00457 std::cout << "sc_out_clk_ " << sc_out_clk_ << std::endl;
00458 std::cout << "sc_inout_clk_ " << sc_inout_clk_ << std::endl;
00459 std::cout << "sc_fifo_ " << sc_fifo_ << std::endl;
00460 std::cout << "sc_fifo_in_ " << sc_fifo_in_ << std::endl;
00461 std::cout << "sc_fifo_out_ " << sc_fifo_out_ << std::endl;
00462 std::cout << "sc_main_ " << sc_main_ << std::endl;
00463 std::cout << "sc_core_ " << sc_core_.size() << std::endl;
00464 std::cout << "sc_dt_ " << sc_dt_.size() << std::endl;
00465 std::cout << "sc_wait_funcs_ " << sc_wait_funcs_.size() << std::endl;
00466 std::cout << "get_curr_proc_ " << sc_get_curr_proc_ << std::endl;
00467 std::cout << "get_curr_simcontext_ " << sc_get_curr_simcontext_ << std::endl;
00468 std::cout << "get_upcoming_segment_ids_ " << get_upcoming_segment_ids_ << std::endl;
00469 std::cout << "set_upcoming_segment_ids_ " << set_upcoming_segment_ids_ << std::endl;
00470 #endif
00471 }
00472
00473
00474
00475
00476 static SgClassDefinition *sc_module_;
00477 static SgClassDefinition *sc_port_;
00478 static SgClassDefinition *sc_port_base_;
00479 static SgClassDefinition *sc_in_;
00480 static SgClassDefinition *sc_out_;
00481 static SgClassDefinition *sc_inout_;
00482 static SgClassDefinition *sc_event_;
00483 static SgClassDefinition *sc_event_and_list_;
00484 static SgClassDefinition *sc_event_or_list_;
00485 static SgClassDefinition *sc_prim_channel_;
00486 static SgClassDefinition *sc_interface_;
00487 static SgClassDefinition *sc_fifo_;
00488 static SgClassDefinition *sc_fifo_in_;
00489 static SgClassDefinition *sc_fifo_out_;
00490 static SgClassDefinition *sc_simcontext_;
00491 static SgClassDefinition *sc_segid_;
00492 static SgClassDefinition *sc_process_b_;
00493
00494
00495 static SgClassDefinition *sc_channel_;
00496 static SgClassDefinition *sc_in_clk_;
00497 static SgClassDefinition *sc_out_clk_;
00498 static SgClassDefinition *sc_inout_clk_;
00499
00500 static SgFunctionDefinition *sc_main_;
00501 static SgFunctionDeclaration *sc_get_curr_simcontext_;
00502 static SgMemberFunctionDeclaration *sc_get_curr_proc_;
00503 static SgMemberFunctionDeclaration *sc_segid_ctor_;
00504 static SgMemberFunctionDeclaration *get_upcoming_segment_ids_;
00505 static SgMemberFunctionDeclaration *set_upcoming_segment_ids_;
00506 static SgMemberFunctionDeclaration *get_interface_;
00507
00508
00509 static std::vector<SgNamespaceDefinitionStatement*> sc_core_;
00510 static std::vector<SgNamespaceDefinitionStatement*> sc_dt_;
00511
00512
00513 static std::set<SgFunctionDefinition*> sc_wait_funcs_;
00514
00515 static bool is_initialized_;
00516 };
00517
00518 };
00519
00520 };
00521
00522 #endif
00523
00524