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 #ifndef SC_PORT_H
00079 #define SC_PORT_H
00080
00081
00082 #include "sysc/communication/sc_communication_ids.h"
00083 #include "sysc/communication/sc_interface.h"
00084 #include "sysc/kernel/sc_event.h"
00085 #include "sysc/kernel/sc_object.h"
00086 #include "sysc/kernel/sc_process.h"
00087 #include <typeinfo>
00088
00089 namespace sc_core {
00090
00091 class sc_event_finder;
00092
00093 struct sc_bind_info;
00094
00095 enum sc_port_policy
00096 {
00097 SC_ONE_OR_MORE_BOUND,
00098 SC_ZERO_OR_MORE_BOUND,
00099 SC_ALL_BOUND
00100 };
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 class sc_port_base
00115 : public sc_object
00116 {
00117 friend class sc_module;
00118 friend class sc_port_registry;
00119 friend class sc_sensitive;
00120 friend class sc_sensitive_pos;
00121 friend class sc_sensitive_neg;
00122
00123 public:
00124
00125
00126
00127 typedef sc_port_base this_type;
00128
00129 public:
00130
00131
00132 virtual sc_interface* get_interface() = 0;
00133
00134 virtual const sc_interface* get_interface() const = 0;
00135
00136 virtual const char* kind() const
00137 { return "sc_port_base"; }
00138
00139 protected:
00140
00141
00142 explicit sc_port_base( int max_size_,
00143 sc_port_policy policy=SC_ONE_OR_MORE_BOUND );
00144 sc_port_base( const char* name_, int max_size_,
00145 sc_port_policy policy=SC_ONE_OR_MORE_BOUND );
00146
00147
00148 virtual ~sc_port_base();
00149
00150
00151 void bind( sc_interface& interface_ );
00152
00153
00154 void bind( this_type& parent_ );
00155
00156
00157 virtual int vbind( sc_interface& ) = 0;
00158 virtual int vbind( sc_port_base& ) = 0;
00159
00160
00161 virtual void add_interface( sc_interface* ) = 0;
00162 virtual int interface_count() = 0;
00163 virtual const char* if_typename() const = 0;
00164
00165
00166 virtual void before_end_of_elaboration();
00167
00168
00169 virtual void end_of_elaboration();
00170
00171
00172 virtual void start_of_simulation();
00173
00174
00175 virtual void end_of_simulation();
00176
00177
00178 void report_error( const char* id, const char* add_msg = 0) const;
00179
00180 protected:
00181
00182 virtual void make_sensitive( sc_thread_handle, sc_event_finder* = 0 ) const;
00183 virtual void make_sensitive( sc_method_handle, sc_event_finder* = 0 ) const;
00184 void add_static_event(
00185 sc_method_handle process_p, const sc_event& event) const;
00186 void add_static_event(
00187 sc_thread_handle process_p, const sc_event& event) const;
00188
00189 private:
00190
00191
00192 int pbind( sc_interface& );
00193 int pbind( sc_port_base& );
00194
00195
00196
00197 int first_parent();
00198 void insert_parent( int );
00199
00200
00201 void construction_done();
00202
00203
00204 void complete_binding();
00205 void elaboration_done();
00206
00207
00208 void start_simulation();
00209
00210
00211 void simulation_done();
00212
00213 protected:
00214
00215 sc_bind_info* m_bind_info;
00216
00217 private:
00218
00219
00220 sc_port_base();
00221 sc_port_base( const this_type& );
00222 this_type& operator = ( const this_type& );
00223 };
00224
00225
00226
00227
00228
00229
00230
00231
00232 class sc_port_registry
00233 {
00234 friend class sc_simcontext;
00235
00236 public:
00237
00238 void insert( sc_port_base* );
00239 void remove( sc_port_base* );
00240
00241 int size() const
00242 { return m_port_vec.size(); }
00243
00244 private:
00245
00246
00247 explicit sc_port_registry( sc_simcontext& simc_ );
00248
00249
00250 ~sc_port_registry();
00251
00252
00253 void complete_binding();
00254
00255
00256 void construction_done();
00257
00258
00259 void elaboration_done();
00260
00261
00262 void start_simulation();
00263
00264
00265 void simulation_done();
00266
00267 static void replace_port( sc_port_registry* );
00268
00269 private:
00270
00271 sc_simcontext* m_simc;
00272 std::vector<sc_port_base*> m_port_vec;
00273
00274 private:
00275
00276
00277 sc_port_registry();
00278 sc_port_registry( const sc_port_registry& );
00279 sc_port_registry& operator = ( const sc_port_registry& );
00280 };
00281
00282
00283
00284
00285
00286
00287
00288
00289 template <class IF>
00290 class sc_port_b
00291 : public sc_port_base
00292 {
00293 public:
00294
00295 friend class sc_sensitive;
00296 friend class sc_sensitive_neg;
00297 friend class sc_sensitive_pos;
00298
00299
00300
00301 typedef sc_port_base base_type;
00302 typedef sc_port_b<IF> this_type;
00303
00304 public:
00305
00306
00307
00308 void bind( IF& interface_ )
00309 { base_type::bind( interface_ ); }
00310
00311
00312 void operator () ( IF& interface_ )
00313 { base_type::bind( interface_ ); }
00314
00315
00316
00317
00318 void bind( this_type& parent_ )
00319 { base_type::bind( parent_ ); }
00320
00321
00322 void operator () ( this_type& parent_ )
00323 { base_type::bind( parent_ ); }
00324
00325
00326
00327
00328 int size() const
00329 { return m_interface_vec.size(); }
00330
00331
00332
00333 IF* operator -> ();
00334 const IF* operator -> () const;
00335
00336
00337
00338 inline const IF* get_interface( int iface_i ) const;
00339
00340 inline IF* get_interface( int iface_i );
00341 IF* operator [] ( int index_ )
00342 { return get_interface( index_ ); }
00343
00344 const IF* operator [] ( int index_ ) const
00345 { return get_interface( index_ ); }
00346
00347
00348
00349
00350 virtual sc_interface* get_interface()
00351 { return m_interface; }
00352
00353
00354 virtual const sc_interface* get_interface() const
00355 { return m_interface; }
00356
00357 protected:
00358
00359
00360
00361 explicit sc_port_b( int max_size_,
00362 sc_port_policy policy=SC_ONE_OR_MORE_BOUND )
00363 : base_type( max_size_, policy ), m_interface( 0 )
00364 {}
00365
00366 sc_port_b( const char* name_, int max_size_,
00367 sc_port_policy policy=SC_ONE_OR_MORE_BOUND )
00368 : base_type( name_, max_size_, policy ), m_interface( 0 )
00369 {}
00370
00371
00372
00373
00374 virtual ~sc_port_b()
00375 {}
00376
00377
00378
00379 virtual int vbind( sc_interface& );
00380 virtual int vbind( sc_port_base& );
00381
00382 protected:
00383
00384
00385 virtual void make_sensitive( sc_thread_handle, sc_event_finder* = 0 ) const;
00386 virtual void make_sensitive( sc_method_handle, sc_event_finder* = 0 ) const;
00387
00388 private:
00389
00390
00391 virtual void add_interface( sc_interface* );
00392 virtual const char* if_typename() const;
00393 virtual int interface_count();
00394
00395
00396 sc_port_b();
00397 sc_port_b( const this_type& );
00398 this_type& operator = ( const this_type& );
00399
00400 private:
00401
00402 IF* m_interface;
00403 std::vector<IF*> m_interface_vec;
00404 };
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 extern void sc_warn_port_constructor();
00416
00417 template <class IF, int N = 1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
00418 class sc_port
00419 : public sc_port_b<IF>
00420 {
00421
00422
00423 typedef sc_port_b<IF> base_type;
00424 typedef sc_port<IF,N,P> this_type;
00425
00426 public:
00427
00428
00429
00430 sc_port()
00431 : base_type( N, P )
00432 {}
00433
00434 explicit sc_port( const char* name_ )
00435 : base_type( name_, N, P )
00436 {}
00437
00438 explicit sc_port( IF& interface_ )
00439 : base_type( N, P )
00440 { sc_warn_port_constructor(); base_type::bind( interface_ ); }
00441
00442 sc_port( const char* name_, IF& interface_ )
00443 : base_type( name_, N, P )
00444 { sc_warn_port_constructor(); base_type::bind( interface_ ); }
00445
00446 explicit sc_port( base_type& parent_ )
00447 : base_type( N, P )
00448 { sc_warn_port_constructor(); base_type::bind( parent_ ); }
00449
00450 sc_port( const char* name_, base_type& parent_ )
00451 : base_type( name_, N, P )
00452 { sc_warn_port_constructor(); base_type::bind( parent_ ); }
00453
00454 sc_port( this_type& parent_ )
00455 : base_type( N, P )
00456 { sc_warn_port_constructor(); base_type::bind( parent_ ); }
00457
00458 sc_port( const char* name_, this_type& parent_ )
00459 : base_type( name_, N, P )
00460 { sc_warn_port_constructor(); base_type::bind( parent_ ); }
00461
00462
00463
00464
00465 virtual ~sc_port()
00466 {}
00467
00468 virtual const char* kind() const
00469 { return "sc_port"; }
00470
00471 private:
00472
00473
00474 sc_port( const this_type& );
00475 this_type& operator = ( const this_type& );
00476 };
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 template <class IF>
00490 inline
00491 IF*
00492 sc_port_b<IF>::operator -> ()
00493 {
00494 if( m_interface == 0 ) {
00495 report_error( SC_ID_GET_IF_, "port is not bound" );
00496 }
00497 return m_interface;
00498 }
00499
00500
00501 template <class IF>
00502 inline
00503 const IF*
00504 sc_port_b<IF>::operator -> () const
00505 {
00506 if( m_interface == 0 ) {
00507 report_error( SC_ID_GET_IF_, "port is not bound" );
00508 }
00509 return m_interface;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519 template <class IF>
00520 inline
00521 IF*
00522 sc_port_b<IF>::get_interface( int index_ )
00523 {
00524 if ( index_ == 0 ) {
00525 return m_interface;
00526 }
00527 else if( index_ < 0 || index_ >= size() ) {
00528 report_error( SC_ID_GET_IF_, "index out of range" );
00529 }
00530 return m_interface_vec[index_];
00531 }
00532
00533 template <class IF>
00534 inline
00535 const IF*
00536 sc_port_b<IF>::get_interface( int index_ ) const
00537 {
00538 if ( index_ == 0 ) {
00539 return m_interface;
00540 }
00541 else if( index_ < 0 || index_ >= size() ) {
00542 report_error( SC_ID_GET_IF_, "index out of range" );
00543 }
00544 return m_interface_vec[index_];
00545 }
00546
00547
00548
00549
00550 template <class IF>
00551 inline
00552 int
00553 sc_port_b<IF>::vbind( sc_interface& interface_ )
00554 {
00555 IF* iface = DCAST<IF*>( &interface_ );
00556 if( iface == 0 ) {
00557
00558 return 2;
00559 }
00560 base_type::bind( *iface );
00561 return 0;
00562 }
00563
00564 template <class IF>
00565 inline
00566 int
00567 sc_port_b<IF>::vbind( sc_port_base& parent_ )
00568 {
00569 this_type* parent = DCAST<this_type*>( &parent_ );
00570 if( parent == 0 ) {
00571
00572 return 2;
00573 }
00574 base_type::bind( *parent );
00575 return 0;
00576 }
00577
00578
00579
00580
00581 template <class IF>
00582 inline
00583 void
00584 sc_port_b<IF>::add_interface( sc_interface* interface_ )
00585 {
00586 IF* iface = DCAST<IF*>( interface_ );
00587 assert( iface != 0 );
00588
00589
00590
00591 int size = m_interface_vec.size();
00592 for ( int i = 0; i < size; i++ )
00593 {
00594 if ( iface == m_interface_vec[i] )
00595 {
00596 report_error( SC_ID_BIND_IF_TO_PORT_,
00597 "interface already bound to port" );
00598 }
00599 }
00600
00601
00602
00603 m_interface_vec.push_back( iface );
00604 m_interface = m_interface_vec[0];
00605 }
00606
00607 template <class IF>
00608 inline
00609 const char*
00610 sc_port_b<IF>::if_typename() const
00611 {
00612 return typeid( IF ).name();
00613 }
00614
00615 template <class IF>
00616 inline
00617 int
00618 sc_port_b<IF>::interface_count()
00619 {
00620 return m_interface_vec.size();
00621 }
00622
00623 template <class IF>
00624 void
00625 sc_port_b<IF>::make_sensitive( sc_thread_handle handle_p,
00626 sc_event_finder* event_finder_ ) const
00627 {
00628 if ( m_bind_info == 0 )
00629 {
00630 int if_n = m_interface_vec.size();
00631 for ( int if_i = 0; if_i < if_n; if_i++ )
00632 {
00633 IF* iface_p = m_interface_vec[if_i];
00634 assert( iface_p != 0 );
00635 add_static_event( handle_p, iface_p->default_event() );
00636 }
00637 }
00638 else
00639 {
00640 sc_port_base::make_sensitive( handle_p, event_finder_ );
00641 }
00642 }
00643
00644 template <class IF>
00645 void
00646 sc_port_b<IF>::make_sensitive( sc_method_handle handle_p,
00647 sc_event_finder* event_finder_ ) const
00648 {
00649 if ( m_bind_info == 0 )
00650 {
00651 int if_n = m_interface_vec.size();
00652 for ( int if_i = 0; if_i < if_n; if_i++ )
00653 {
00654 IF* iface_p = m_interface_vec[if_i];
00655 assert( iface_p != 0 );
00656 add_static_event( handle_p, iface_p->default_event() );
00657 }
00658 }
00659 else
00660 {
00661 sc_port_base::make_sensitive( handle_p, event_finder_ );
00662 }
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 }
00674
00675 #endif
00676
00677