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