00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 #include <cassert>
00107 #include <math.h>
00108 #include <stdio.h>
00109
00110 #include "sysc/kernel/sc_event.h"
00111 #include "sysc/kernel/sc_kernel_ids.h"
00112 #include "sysc/kernel/sc_macros_int.h"
00113 #include "sysc/kernel/sc_module.h"
00114 #include "sysc/kernel/sc_module_registry.h"
00115 #include "sysc/kernel/sc_name_gen.h"
00116 #include "sysc/kernel/sc_object_manager.h"
00117 #include "sysc/kernel/sc_process.h"
00118 #include "sysc/kernel/sc_process_handle.h"
00119 #include "sysc/kernel/sc_simcontext.h"
00120 #include "sysc/kernel/sc_simcontext_int.h"
00121 #include "sysc/kernel/sc_reset.h"
00122 #include "sysc/communication/sc_communication_ids.h"
00123 #include "sysc/communication/sc_interface.h"
00124 #include "sysc/communication/sc_port.h"
00125 #include "sysc/communication/sc_signal.h"
00126 #include "sysc/communication/sc_signal_ports.h"
00127 #include "sysc/utils/sc_utils_ids.h"
00128 #include "sysc/utils/sc_iostream.h"
00129
00130 namespace sc_core {
00131
00132
00133
00134
00135
00136
00137
00138 class sc_module_dynalloc_list
00139 {
00140 public:
00141
00142 sc_module_dynalloc_list()
00143 {}
00144
00145 ~sc_module_dynalloc_list();
00146
00147 void add( sc_module* p )
00148 { m_list.push_back( p ); }
00149
00150 private:
00151
00152 sc_plist<sc_module*> m_list;
00153 };
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 sc_module_dynalloc_list::~sc_module_dynalloc_list()
00165 {
00166 sc_plist<sc_module*>::iterator it( m_list );
00167 while( ! it.empty() ) {
00168 (*it)->m_parent = 0;
00169 delete *it;
00170 it ++;
00171 }
00172 }
00173
00174
00175
00176
00177 sc_module*
00178 sc_module_dynalloc( sc_module* module_ )
00179 {
00180 static sc_module_dynalloc_list dynalloc_list;
00181 dynalloc_list.add( module_ );
00182 return module_;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 sc_bind_proxy::sc_bind_proxy()
00194 : iface( 0 ),
00195 port( 0 )
00196 {}
00197
00198 sc_bind_proxy::sc_bind_proxy( sc_interface& iface_ )
00199 : iface( &iface_ ),
00200 port( 0 )
00201 {}
00202
00203 sc_bind_proxy::sc_bind_proxy( sc_port_base& port_ )
00204 : iface( 0 ),
00205 port( &port_ )
00206 {}
00207
00208
00209 const sc_bind_proxy SC_BIND_PROXY_NIL;
00210
00211
00212
00213
00214
00215
00216
00217
00218 void
00219 sc_module::sc_module_init()
00220 {
00221 simcontext()->hierarchy_push( this );
00222 m_end_module_called = false;
00223 m_module_name_p = 0;
00224 m_port_vec = new std::vector<sc_port_base*>;
00225 m_port_index = 0;
00226 m_name_gen = new sc_name_gen;
00227 simcontext()->get_module_registry()->insert( *this );
00228 }
00229
00230 sc_module::sc_module( const char* nm )
00231 : sc_object(nm),
00232 sensitive(this),
00233 sensitive_pos(this),
00234 sensitive_neg(this)
00235 {
00236 sc_module_init();
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 sc_module::sc_module()
00260 : sc_object(::sc_core::sc_get_curr_simcontext()
00261 ->get_object_manager()
00262 ->top_of_module_name_stack()
00263 ->operator const char*()),
00264 sensitive(this),
00265 sensitive_pos(this),
00266 sensitive_neg(this)
00267 {
00268
00269
00270 sc_module_name* mod_name =
00271 simcontext()->get_object_manager()->top_of_module_name_stack();
00272 if (0 == mod_name || 0 != mod_name->m_module_p)
00273 SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_REQUIRED_, 0 );
00274 sc_module_init();
00275 mod_name->set_module( this );
00276 m_module_name_p = mod_name;
00277 }
00278
00279 sc_module::sc_module( const sc_module_name& )
00280 : sc_object(::sc_core::sc_get_curr_simcontext()
00281 ->get_object_manager()
00282 ->top_of_module_name_stack()
00283 ->operator const char*()),
00284 sensitive(this),
00285 sensitive_pos(this),
00286 sensitive_neg(this)
00287 {
00288
00289
00290
00291
00292
00293 sc_module_name* mod_name =
00294 simcontext()->get_object_manager()->top_of_module_name_stack();
00295 if (0 == mod_name || 0 != mod_name->m_module_p)
00296 SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_REQUIRED_, 0 );
00297 sc_module_init();
00298 mod_name->set_module( this );
00299 m_module_name_p = mod_name;
00300 }
00301
00302 sc_module::sc_module( const std::string& s )
00303 : sc_object( s.c_str() ),
00304 sensitive(this),
00305 sensitive_pos(this),
00306 sensitive_neg(this)
00307 {
00308 sc_module_init();
00309 }
00310
00311 sc_module::~sc_module()
00312 {
00313 delete m_port_vec;
00314 delete m_name_gen;
00315 if ( m_module_name_p )
00316 {
00317 m_module_name_p->clear_module( this );
00318 end_module();
00319 }
00320 simcontext()->get_module_registry()->remove( *this );
00321 }
00322
00323
00324 const ::std::vector<sc_object*>&
00325 sc_module::get_child_objects() const
00326 {
00327 return m_child_objects;
00328 }
00329
00330 void
00331 sc_module::add_child_object( sc_object* object_ )
00332 {
00333
00334 m_child_objects.push_back( object_ );
00335 }
00336
00337 void
00338 sc_module::remove_child_object( sc_object* object_ )
00339 {
00340 int size = m_child_objects.size();
00341 for( int i = 0; i < size; ++ i ) {
00342 if( object_ == m_child_objects[i] ) {
00343 m_child_objects[i] = m_child_objects[size - 1];
00344 m_child_objects.resize(size-1);
00345 return;
00346 }
00347 }
00348
00349 }
00350
00351
00352 void
00353 sc_module::end_module()
00354 {
00355 if( ! m_end_module_called ) {
00356
00357
00358 (void)sc_get_curr_simcontext()->hierarchy_pop();
00359 sc_get_curr_simcontext()->reset_curr_proc();
00360 sensitive.reset();
00361 sensitive_pos.reset();
00362 sensitive_neg.reset();
00363 m_end_module_called = true;
00364 m_module_name_p = 0;
00365 }
00366 }
00367
00368
00369
00370
00371 void
00372 sc_module::dont_initialize()
00373 {
00374 sc_process_handle last_proc = sc_get_last_created_process_handle();
00375 last_proc.dont_initialize( true );
00376 }
00377
00378
00379
00380 void
00381 sc_module::reset_signal_is( const sc_in<bool>& port, bool level )
00382 {
00383 sc_reset::reset_signal_is(port, level);
00384 }
00385
00386 void
00387 sc_module::reset_signal_is( const sc_signal_in_if<bool>& iface, bool level )
00388 {
00389 sc_reset::reset_signal_is(iface, level);
00390 }
00391
00392
00393
00394 const char*
00395 sc_module::gen_unique_name( const char* basename_, bool preserve_first )
00396 {
00397 return m_name_gen->gen_unique_name( basename_, preserve_first );
00398 }
00399
00400
00401
00402
00403 void
00404 sc_module::before_end_of_elaboration()
00405 {}
00406
00407
00408
00409
00410 void
00411 sc_module::construction_done()
00412 {
00413 simcontext()->hierarchy_push( this );
00414 before_end_of_elaboration();
00415 simcontext()->hierarchy_pop();
00416 }
00417
00418
00419
00420 void
00421 sc_module::end_of_elaboration()
00422 {}
00423
00424
00425
00426
00427
00428 void
00429 sc_module::elaboration_done( bool& error_ )
00430 {
00431 if( ! m_end_module_called ) {
00432 char msg[BUFSIZ];
00433 std::sprintf( msg, "module '%s'", name() );
00434 SC_REPORT_WARNING( SC_ID_END_MODULE_NOT_CALLED_, msg );
00435 if( error_ ) {
00436 SC_REPORT_WARNING( SC_ID_HIER_NAME_INCORRECT_, 0 );
00437 }
00438 error_ = true;
00439 }
00440 simcontext()->hierarchy_push( this );
00441 end_of_elaboration();
00442 simcontext()->hierarchy_pop();
00443 }
00444
00445
00446
00447 void
00448 sc_module::start_of_simulation()
00449 {}
00450
00451 void
00452 sc_module::start_simulation()
00453 {
00454 start_of_simulation();
00455 }
00456
00457
00458
00459 void
00460 sc_module::end_of_simulation()
00461 {}
00462
00463 void
00464 sc_module::simulation_done()
00465 {
00466 end_of_simulation();
00467 }
00468
00469 void
00470 sc_module::set_stack_size( std::size_t size )
00471 {
00472 sc_process_handle proc_h(
00473 sc_is_running() ?
00474 sc_get_current_process_handle() :
00475 sc_get_last_created_process_handle()
00476 );
00477 sc_thread_handle thread_h;
00478
00479
00480 thread_h = (sc_thread_handle)proc_h;
00481 if ( thread_h )
00482 {
00483 thread_h->set_stack_size( size );
00484 }
00485 else
00486 {
00487 SC_REPORT_WARNING( SC_ID_SET_STACK_SIZE_, 0 );
00488 }
00489 }
00490
00491
00492 int
00493 sc_module::append_port( sc_port_base* port_ )
00494 {
00495 int index = m_port_vec->size();
00496 m_port_vec->push_back( port_ );
00497 return index;
00498 }
00499
00500
00501
00502
00503 static void sc_warn_arrow_arrow_bind()
00504 {
00505 static bool warn_arrow_arrow_bind=true;
00506 if ( warn_arrow_arrow_bind )
00507 {
00508 warn_arrow_arrow_bind = false;
00509 SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
00510 "positional binding using << or , is deprecated, use () instead.");
00511 }
00512 }
00513
00514 sc_module&
00515 sc_module::operator << ( sc_interface& interface_ )
00516 {
00517 sc_warn_arrow_arrow_bind();
00518 positional_bind(interface_);
00519 return *this;
00520 }
00521
00522 sc_module&
00523 sc_module::operator << ( sc_port_base& port_ )
00524 {
00525 sc_warn_arrow_arrow_bind();
00526 positional_bind(port_);
00527 return *this;
00528 }
00529
00530
00531 void
00532 sc_module::positional_bind( sc_interface& interface_ )
00533 {
00534 if( m_port_index == (int)m_port_vec->size() ) {
00535 char msg[BUFSIZ];
00536 if( m_port_index == 0 ) {
00537 std::sprintf( msg, "module `%s' has no ports", name() );
00538 } else {
00539 std::sprintf( msg, "all ports of module `%s' are bound", name() );
00540 }
00541 SC_REPORT_ERROR( SC_ID_BIND_IF_TO_PORT_, msg );
00542 }
00543 int status = (*m_port_vec)[m_port_index]->pbind( interface_ );
00544 if( status != 0 ) {
00545 char msg[BUFSIZ];
00546 switch( status ) {
00547 case 1:
00548 std::sprintf( msg, "port %d of module `%s' is already bound",
00549 m_port_index, name() );
00550 break;
00551 case 2:
00552 std::sprintf( msg, "type mismatch on port %d of module `%s'",
00553 m_port_index, name() );
00554 break;
00555 default:
00556 std::sprintf( msg, "unknown error" );
00557 break;
00558 }
00559 SC_REPORT_ERROR( SC_ID_BIND_IF_TO_PORT_, msg );
00560 }
00561 ++ m_port_index;
00562 }
00563
00564 void
00565 sc_module::positional_bind( sc_port_base& port_ )
00566 {
00567 if( m_port_index == (int)m_port_vec->size() ) {
00568 char msg[BUFSIZ];
00569 if( m_port_index == 0 ) {
00570 std::sprintf( msg, "module `%s' has no ports", name() );
00571 } else {
00572 std::sprintf( msg, "all ports of module `%s' are bound", name() );
00573 }
00574 SC_REPORT_ERROR( SC_ID_BIND_PORT_TO_PORT_, msg );
00575 }
00576 int status = (*m_port_vec)[m_port_index]->pbind( port_ );
00577 if( status != 0 ) {
00578 char msg[BUFSIZ];
00579 switch( status ) {
00580 case 1:
00581 std::sprintf( msg, "port %d of module `%s' is already bound",
00582 m_port_index, name() );
00583 break;
00584 case 2:
00585 std::sprintf( msg, "type mismatch on port %d of module `%s'",
00586 m_port_index, name() );
00587 break;
00588 default:
00589 std::sprintf( msg, "unknown error" );
00590 break;
00591 }
00592 SC_REPORT_ERROR( SC_ID_BIND_PORT_TO_PORT_, msg );
00593 }
00594 ++ m_port_index;
00595 }
00596
00597
00598 #define TRY_BIND( p ) \
00599 if( (p).iface != 0 ) { \
00600 positional_bind( *(p).iface ); \
00601 } else if( (p).port != 0 ) { \
00602 positional_bind( *(p).port ); \
00603 } else { \
00604 return; \
00605 }
00606
00607
00608 void
00609 sc_module::operator () ( const sc_bind_proxy& p001,
00610 const sc_bind_proxy& p002,
00611 const sc_bind_proxy& p003,
00612 const sc_bind_proxy& p004,
00613 const sc_bind_proxy& p005,
00614 const sc_bind_proxy& p006,
00615 const sc_bind_proxy& p007,
00616 const sc_bind_proxy& p008,
00617 const sc_bind_proxy& p009,
00618 const sc_bind_proxy& p010,
00619 const sc_bind_proxy& p011,
00620 const sc_bind_proxy& p012,
00621 const sc_bind_proxy& p013,
00622 const sc_bind_proxy& p014,
00623 const sc_bind_proxy& p015,
00624 const sc_bind_proxy& p016,
00625 const sc_bind_proxy& p017,
00626 const sc_bind_proxy& p018,
00627 const sc_bind_proxy& p019,
00628 const sc_bind_proxy& p020,
00629 const sc_bind_proxy& p021,
00630 const sc_bind_proxy& p022,
00631 const sc_bind_proxy& p023,
00632 const sc_bind_proxy& p024,
00633 const sc_bind_proxy& p025,
00634 const sc_bind_proxy& p026,
00635 const sc_bind_proxy& p027,
00636 const sc_bind_proxy& p028,
00637 const sc_bind_proxy& p029,
00638 const sc_bind_proxy& p030,
00639 const sc_bind_proxy& p031,
00640 const sc_bind_proxy& p032,
00641 const sc_bind_proxy& p033,
00642 const sc_bind_proxy& p034,
00643 const sc_bind_proxy& p035,
00644 const sc_bind_proxy& p036,
00645 const sc_bind_proxy& p037,
00646 const sc_bind_proxy& p038,
00647 const sc_bind_proxy& p039,
00648 const sc_bind_proxy& p040,
00649 const sc_bind_proxy& p041,
00650 const sc_bind_proxy& p042,
00651 const sc_bind_proxy& p043,
00652 const sc_bind_proxy& p044,
00653 const sc_bind_proxy& p045,
00654 const sc_bind_proxy& p046,
00655 const sc_bind_proxy& p047,
00656 const sc_bind_proxy& p048,
00657 const sc_bind_proxy& p049,
00658 const sc_bind_proxy& p050,
00659 const sc_bind_proxy& p051,
00660 const sc_bind_proxy& p052,
00661 const sc_bind_proxy& p053,
00662 const sc_bind_proxy& p054,
00663 const sc_bind_proxy& p055,
00664 const sc_bind_proxy& p056,
00665 const sc_bind_proxy& p057,
00666 const sc_bind_proxy& p058,
00667 const sc_bind_proxy& p059,
00668 const sc_bind_proxy& p060,
00669 const sc_bind_proxy& p061,
00670 const sc_bind_proxy& p062,
00671 const sc_bind_proxy& p063,
00672 const sc_bind_proxy& p064 )
00673 {
00674 static bool warn_only_once=true;
00675 if ( m_port_index > 0 && warn_only_once )
00676 {
00677 warn_only_once = false;
00678 SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
00679 "multiple () binding depreacted, use explicit port binding instead." );
00680 }
00681
00682 TRY_BIND( p001 );
00683 TRY_BIND( p002 );
00684 TRY_BIND( p003 );
00685 TRY_BIND( p004 );
00686 TRY_BIND( p005 );
00687 TRY_BIND( p006 );
00688 TRY_BIND( p007 );
00689 TRY_BIND( p008 );
00690 TRY_BIND( p009 );
00691 TRY_BIND( p010 );
00692 TRY_BIND( p011 );
00693 TRY_BIND( p012 );
00694 TRY_BIND( p013 );
00695 TRY_BIND( p014 );
00696 TRY_BIND( p015 );
00697 TRY_BIND( p016 );
00698 TRY_BIND( p017 );
00699 TRY_BIND( p018 );
00700 TRY_BIND( p019 );
00701 TRY_BIND( p020 );
00702 TRY_BIND( p021 );
00703 TRY_BIND( p022 );
00704 TRY_BIND( p023 );
00705 TRY_BIND( p024 );
00706 TRY_BIND( p025 );
00707 TRY_BIND( p026 );
00708 TRY_BIND( p027 );
00709 TRY_BIND( p028 );
00710 TRY_BIND( p029 );
00711 TRY_BIND( p030 );
00712 TRY_BIND( p031 );
00713 TRY_BIND( p032 );
00714 TRY_BIND( p033 );
00715 TRY_BIND( p034 );
00716 TRY_BIND( p035 );
00717 TRY_BIND( p036 );
00718 TRY_BIND( p037 );
00719 TRY_BIND( p038 );
00720 TRY_BIND( p039 );
00721 TRY_BIND( p040 );
00722 TRY_BIND( p041 );
00723 TRY_BIND( p042 );
00724 TRY_BIND( p043 );
00725 TRY_BIND( p044 );
00726 TRY_BIND( p045 );
00727 TRY_BIND( p046 );
00728 TRY_BIND( p047 );
00729 TRY_BIND( p048 );
00730 TRY_BIND( p049 );
00731 TRY_BIND( p050 );
00732 TRY_BIND( p051 );
00733 TRY_BIND( p052 );
00734 TRY_BIND( p053 );
00735 TRY_BIND( p054 );
00736 TRY_BIND( p055 );
00737 TRY_BIND( p056 );
00738 TRY_BIND( p057 );
00739 TRY_BIND( p058 );
00740 TRY_BIND( p059 );
00741 TRY_BIND( p060 );
00742 TRY_BIND( p061 );
00743 TRY_BIND( p062 );
00744 TRY_BIND( p063 );
00745 TRY_BIND( p064 );
00746 }
00747
00748 }
00749
00750