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 #ifndef SC_SIGNAL_PORTS_H
00043 #define SC_SIGNAL_PORTS_H
00044
00045
00046 #include "sysc/communication/sc_event_finder.h"
00047 #include "sysc/communication/sc_port.h"
00048 #include "sysc/communication/sc_signal_ifs.h"
00049 #include "sysc/datatypes/bit/sc_logic.h"
00050 #include "sysc/tracing/sc_trace.h"
00051
00052 namespace sc_core {
00053
00054
00055
00056
00057
00058
00059
00060
00061 struct sc_trace_params
00062 {
00063 sc_trace_file* tf;
00064 std::string name;
00065
00066 sc_trace_params( sc_trace_file* tf_, const std::string& name_ )
00067 : tf( tf_ ), name( name_ )
00068 {}
00069 };
00070
00071
00072 typedef sc_pvector<sc_trace_params*> sc_trace_params_vec;
00073
00074
00075
00076
00077
00078
00079
00080
00081 template <class T>
00082 class sc_in
00083 : public sc_port<sc_signal_in_if<T>,1>
00084 {
00085 public:
00086
00087
00088
00089 typedef T data_type;
00090
00091 typedef sc_signal_in_if<data_type> if_type;
00092 typedef sc_port<if_type,1> base_type;
00093 typedef sc_in<data_type> this_type;
00094
00095 typedef if_type in_if_type;
00096 typedef base_type in_port_type;
00097 typedef sc_signal_inout_if<data_type> inout_if_type;
00098 typedef sc_port<inout_if_type,1> inout_port_type;
00099
00100 public:
00101
00102
00103
00104 sc_in()
00105 : base_type(), m_traces( 0 )
00106 {}
00107
00108 explicit sc_in( const char* name_ )
00109 : base_type( name_ ), m_traces( 0 )
00110 {}
00111
00112 explicit sc_in( const in_if_type& interface_ )
00113 : base_type( CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00114 {}
00115
00116 sc_in( const char* name_, const in_if_type& interface_ )
00117 : base_type( name_, CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00118 {}
00119
00120 explicit sc_in( in_port_type& parent_ )
00121 : base_type( parent_ ), m_traces( 0 )
00122 {}
00123
00124 sc_in( const char* name_, in_port_type& parent_ )
00125 : base_type( name_, parent_ ), m_traces( 0 )
00126 {}
00127
00128 explicit sc_in( inout_port_type& parent_ )
00129 : base_type(), m_traces( 0 )
00130 { sc_port_base::bind( parent_ ); }
00131
00132 sc_in( const char* name_, inout_port_type& parent_ )
00133 : base_type( name_ ), m_traces( 0 )
00134 { sc_port_base::bind( parent_ ); }
00135
00136 sc_in( this_type& parent_ )
00137 : base_type( parent_ ), m_traces( 0 )
00138 {}
00139
00140 sc_in( const char* name_, this_type& parent_ )
00141 : base_type( name_, parent_ ), m_traces( 0 )
00142 {}
00143
00144
00145
00146
00147 virtual ~sc_in()
00148 { remove_traces(); }
00149
00150
00151
00152
00153 void bind( const in_if_type& interface_ )
00154 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00155
00156 void operator () ( const in_if_type& interface_ )
00157 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00158
00159
00160
00161
00162 void bind( in_port_type& parent_ )
00163 { sc_port_base::bind( parent_ ); }
00164
00165 void operator () ( in_port_type& parent_ )
00166 { sc_port_base::bind( parent_ ); }
00167
00168
00169
00170
00171 void bind( inout_port_type& parent_ )
00172 { sc_port_base::bind( parent_ ); }
00173
00174 void operator () ( inout_port_type& parent_ )
00175 { sc_port_base::bind( parent_ ); }
00176
00177
00178
00179
00180
00181
00182 const sc_event& default_event() const
00183 { return (*this)->default_event(); }
00184
00185
00186
00187
00188 const sc_event& value_changed_event() const
00189 { return (*this)->value_changed_event(); }
00190
00191
00192
00193
00194 const data_type& read() const
00195 { return (*this)->read(); }
00196
00197 operator const data_type& () const
00198 { return (*this)->read(); }
00199
00200
00201
00202
00203 bool event() const
00204 { return (*this)->event(); }
00205
00206
00207
00208
00209 sc_event_finder& value_changed() const
00210 {
00211 return *new sc_event_finder_t<in_if_type>(
00212 *this, &in_if_type::value_changed_event );
00213 }
00214
00215
00216
00217
00218
00219
00220 virtual void end_of_elaboration();
00221
00222 virtual const char* kind() const
00223 { return "sc_in"; }
00224
00225
00226
00227 void add_trace( sc_trace_file*, const std::string& ) const;
00228
00229 protected:
00230
00231 void remove_traces() const;
00232
00233 mutable sc_trace_params_vec* m_traces;
00234
00235 protected:
00236
00237
00238 virtual int vbind( sc_interface& );
00239 virtual int vbind( sc_port_base& );
00240
00241 private:
00242
00243
00244 sc_in( const this_type& );
00245 this_type& operator = ( const this_type& );
00246
00247 #ifdef __GNUC__
00248
00249
00250
00251
00252 static data_type dummy;
00253 #endif
00254 };
00255
00256 template<typename T>
00257 ::std::ostream& operator << ( ::std::ostream& os, const sc_in<T>& a )
00258 {
00259 return os << a->read();
00260 }
00261
00262
00263
00264
00265
00266
00267 template <class T>
00268 inline
00269 void
00270 sc_in<T>::end_of_elaboration()
00271 {
00272 if( m_traces != 0 ) {
00273 for( int i = 0; i < m_traces->size(); ++ i ) {
00274 sc_trace_params* p = (*m_traces)[i];
00275 in_if_type* iface = DCAST<in_if_type*>( this->get_interface() );
00276 sc_trace( p->tf, iface->get_data_ref(), p->name );
00277 }
00278 remove_traces();
00279 }
00280 }
00281
00282
00283
00284
00285 template <class T>
00286 inline
00287 void
00288 sc_in<T>::add_trace( sc_trace_file* tf_, const std::string& name_ ) const
00289 {
00290 if( tf_ != 0 ) {
00291 if( m_traces == 0 ) {
00292 m_traces = new sc_trace_params_vec;
00293 }
00294 m_traces->push_back( new sc_trace_params( tf_, name_ ) );
00295 }
00296 }
00297
00298 template <class T>
00299 inline
00300 void
00301 sc_in<T>::remove_traces() const
00302 {
00303 if( m_traces != 0 ) {
00304 for( int i = m_traces->size() - 1; i >= 0; -- i ) {
00305 delete (*m_traces)[i];
00306 }
00307 delete m_traces;
00308 m_traces = 0;
00309 }
00310 }
00311
00312
00313
00314
00315 template <class T>
00316 inline
00317 int
00318 sc_in<T>::vbind( sc_interface& interface_ )
00319 {
00320 return sc_port_b<if_type>::vbind( interface_ );
00321 }
00322
00323 template <class T>
00324 inline
00325 int
00326 sc_in<T>::vbind( sc_port_base& parent_ )
00327 {
00328 in_port_type* in_parent = DCAST<in_port_type*>( &parent_ );
00329 if( in_parent != 0 ) {
00330 sc_port_base::bind( *in_parent );
00331 return 0;
00332 }
00333 inout_port_type* inout_parent = DCAST<inout_port_type*>( &parent_ );
00334 if( inout_parent != 0 ) {
00335 sc_port_base::bind( *inout_parent );
00336 return 0;
00337 }
00338
00339 return 2;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349 template <>
00350 class sc_in<bool>
00351 : public sc_port<sc_signal_in_if<bool>,1>
00352 {
00353 public:
00354
00355
00356
00357 typedef bool data_type;
00358
00359 typedef sc_signal_in_if<data_type> if_type;
00360 typedef sc_port<if_type,1> base_type;
00361 typedef sc_in<data_type> this_type;
00362
00363 typedef if_type in_if_type;
00364 typedef base_type in_port_type;
00365 typedef sc_signal_inout_if<data_type> inout_if_type;
00366 typedef sc_port<inout_if_type,1> inout_port_type;
00367
00368 public:
00369
00370
00371
00372 sc_in()
00373 : base_type(), m_traces( 0 )
00374 {}
00375
00376 explicit sc_in( const char* name_ )
00377 : base_type( name_ ), m_traces( 0 )
00378 {}
00379
00380 explicit sc_in( const in_if_type& interface_ )
00381 : base_type( CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00382 {}
00383
00384 sc_in( const char* name_, const in_if_type& interface_ )
00385 : base_type( name_, CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00386 {}
00387
00388 explicit sc_in( in_port_type& parent_ )
00389 : base_type( parent_ ), m_traces( 0 )
00390 {}
00391
00392 sc_in( const char* name_, in_port_type& parent_ )
00393 : base_type( name_, parent_ ), m_traces( 0 )
00394 {}
00395
00396 explicit sc_in( inout_port_type& parent_ )
00397 : base_type(), m_traces( 0 )
00398 { sc_port_base::bind( parent_ ); }
00399
00400 sc_in( const char* name_, inout_port_type& parent_ )
00401 : base_type( name_ ), m_traces( 0 )
00402 { sc_port_base::bind( parent_ ); }
00403
00404 sc_in( this_type& parent_ )
00405 : base_type( parent_ ), m_traces( 0 )
00406 {}
00407
00408 #if defined(TESTING)
00409 sc_in( const this_type& parent_ )
00410 : base_type( *(in_if_type*)parent_.get_interface() ) , m_traces( 0 )
00411 {}
00412 #endif
00413
00414 sc_in( const char* name_, this_type& parent_ )
00415 : base_type( name_, parent_ ), m_traces( 0 )
00416 {}
00417
00418
00419
00420
00421 virtual ~sc_in()
00422 { remove_traces(); }
00423
00424
00425
00426
00427 void bind( const in_if_type& interface_ )
00428 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00429
00430 void operator () ( const in_if_type& interface_ )
00431 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00432
00433
00434
00435
00436 void bind( in_port_type& parent_ )
00437 { sc_port_base::bind( parent_ ); }
00438
00439 void operator () ( in_port_type& parent_ )
00440 { sc_port_base::bind( parent_ ); }
00441
00442
00443
00444
00445 void bind( inout_port_type& parent_ )
00446 { sc_port_base::bind( parent_ ); }
00447
00448 void operator () ( inout_port_type& parent_ )
00449 { sc_port_base::bind( parent_ ); }
00450
00451
00452
00453
00454
00455
00456 const sc_event& default_event() const
00457 { return (*this)->default_event(); }
00458
00459
00460
00461
00462 const sc_event& value_changed_event() const
00463 { return (*this)->value_changed_event(); }
00464
00465
00466
00467 const sc_event& posedge_event() const
00468 { return (*this)->posedge_event(); }
00469
00470
00471
00472 const sc_event& negedge_event() const
00473 { return (*this)->negedge_event(); }
00474
00475
00476
00477
00478 const data_type& read() const
00479 { return (*this)->read(); }
00480
00481 operator const data_type& () const
00482 { return (*this)->read(); }
00483
00484
00485
00486
00487 sc_event_finder& pos() const
00488 {
00489 return *new sc_event_finder_t<in_if_type>(
00490 *this, &in_if_type::posedge_event );
00491 }
00492
00493
00494
00495 sc_event_finder& neg() const
00496 {
00497 return *new sc_event_finder_t<in_if_type>(
00498 *this, &in_if_type::negedge_event );
00499 }
00500
00501
00502
00503
00504 bool event() const
00505 { return (*this)->event(); }
00506
00507
00508
00509 bool posedge() const
00510 { return (*this)->posedge(); }
00511
00512
00513
00514 bool negedge() const
00515 { return (*this)->negedge(); }
00516
00517
00518
00519 const sc_signal_bool_deval& delayed() const;
00520
00521
00522
00523 sc_event_finder& value_changed() const
00524 {
00525 return *new sc_event_finder_t<in_if_type>(
00526 *this, &in_if_type::value_changed_event );
00527 }
00528
00529
00530
00531
00532
00533
00534 virtual void end_of_elaboration();
00535
00536 virtual const char* kind() const
00537 { return "sc_in"; }
00538
00539
00540
00541 void add_trace( sc_trace_file*, const std::string& ) const;
00542
00543 protected:
00544
00545 void remove_traces() const;
00546
00547 mutable sc_trace_params_vec* m_traces;
00548
00549 protected:
00550
00551
00552 virtual int vbind( sc_interface& );
00553 virtual int vbind( sc_port_base& );
00554
00555 private:
00556
00557
00558 #if defined(TESTING)
00559 #else
00560 sc_in( const this_type& );
00561 #endif
00562 this_type& operator = ( const this_type& );
00563
00564 #ifdef __GNUC__
00565
00566
00567
00568
00569 static data_type dummy;
00570 #endif
00571 };
00572
00573
00574
00575
00576
00577
00578 inline
00579 const sc_signal_bool_deval&
00580 sc_in<bool>::delayed() const
00581 {
00582 const in_if_type* iface = DCAST<const in_if_type*>( get_interface() );
00583 if( iface != 0 ) {
00584 return RCAST<const sc_signal_bool_deval&>( *iface );
00585 } else {
00586
00587 const sc_port_base* pb = this;
00588 return RCAST<const sc_signal_bool_deval&>( *pb );
00589 }
00590 }
00591
00592
00593
00594
00595
00596
00597
00598
00599 template <>
00600 class sc_in<sc_dt::sc_logic>
00601 : public sc_port<sc_signal_in_if<sc_dt::sc_logic>,1>
00602 {
00603 public:
00604
00605
00606
00607 typedef sc_dt::sc_logic data_type;
00608
00609 typedef sc_signal_in_if<data_type> if_type;
00610 typedef sc_port<if_type,1> base_type;
00611 typedef sc_in<data_type> this_type;
00612
00613 typedef if_type in_if_type;
00614 typedef base_type in_port_type;
00615 typedef sc_signal_inout_if<data_type> inout_if_type;
00616 typedef sc_port<inout_if_type,1> inout_port_type;
00617
00618 public:
00619
00620
00621
00622 sc_in()
00623 : base_type(), m_traces( 0 )
00624 {}
00625
00626 explicit sc_in( const char* name_ )
00627 : base_type( name_ ), m_traces( 0 )
00628 {}
00629
00630 explicit sc_in( const in_if_type& interface_ )
00631 : base_type( CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00632 {}
00633
00634 sc_in( const char* name_, const in_if_type& interface_ )
00635 : base_type( name_, CCAST<in_if_type&>( interface_ ) ), m_traces( 0 )
00636 {}
00637
00638 explicit sc_in( in_port_type& parent_ )
00639 : base_type( parent_ ), m_traces( 0 )
00640 {}
00641
00642 sc_in( const char* name_, in_port_type& parent_ )
00643 : base_type( name_, parent_ ), m_traces( 0 )
00644 {}
00645
00646 explicit sc_in( inout_port_type& parent_ )
00647 : base_type(), m_traces( 0 )
00648 { sc_port_base::bind( parent_ ); }
00649
00650 sc_in( const char* name_, inout_port_type& parent_ )
00651 : base_type( name_ ), m_traces( 0 )
00652 { sc_port_base::bind( parent_ ); }
00653
00654 sc_in( this_type& parent_ )
00655 : base_type( parent_ ), m_traces( 0 )
00656 {}
00657
00658 sc_in( const char* name_, this_type& parent_ )
00659 : base_type( name_, parent_ ), m_traces( 0 )
00660 {}
00661
00662
00663
00664
00665 virtual ~sc_in()
00666 { remove_traces(); }
00667
00668
00669
00670
00671 void bind( const in_if_type& interface_ )
00672 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00673
00674 void operator () ( const in_if_type& interface_ )
00675 { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
00676
00677
00678
00679
00680 void bind( in_port_type& parent_ )
00681 { sc_port_base::bind( parent_ ); }
00682
00683 void operator () ( in_port_type& parent_ )
00684 { sc_port_base::bind( parent_ ); }
00685
00686
00687
00688
00689 void bind( inout_port_type& parent_ )
00690 { sc_port_base::bind( parent_ ); }
00691
00692 void operator () ( inout_port_type& parent_ )
00693 { sc_port_base::bind( parent_ ); }
00694
00695
00696
00697
00698
00699
00700 const sc_event& default_event() const
00701 { return (*this)->default_event(); }
00702
00703
00704
00705
00706 const sc_event& value_changed_event() const
00707 { return (*this)->value_changed_event(); }
00708
00709
00710
00711 const sc_event& posedge_event() const
00712 { return (*this)->posedge_event(); }
00713
00714
00715
00716 const sc_event& negedge_event() const
00717 { return (*this)->negedge_event(); }
00718
00719
00720
00721
00722 const data_type& read() const
00723 { return (*this)->read(); }
00724
00725 operator const data_type& () const
00726 { return (*this)->read(); }
00727
00728
00729
00730
00731 sc_event_finder& pos() const
00732 {
00733 return *new sc_event_finder_t<in_if_type>(
00734 *this, &in_if_type::posedge_event );
00735 }
00736
00737
00738
00739 sc_event_finder& neg() const
00740 {
00741 return *new sc_event_finder_t<in_if_type>(
00742 *this, &in_if_type::negedge_event );
00743 }
00744
00745
00746
00747
00748 bool event() const
00749 { return (*this)->event(); }
00750
00751
00752
00753 bool posedge() const
00754 { return (*this)->posedge(); }
00755
00756
00757
00758 bool negedge() const
00759 { return (*this)->negedge(); }
00760
00761
00762
00763 const sc_signal_logic_deval& delayed() const;
00764
00765
00766
00767
00768 sc_event_finder& value_changed() const
00769 {
00770 return *new sc_event_finder_t<in_if_type>(
00771 *this, &in_if_type::value_changed_event );
00772 }
00773
00774
00775
00776
00777
00778
00779 virtual void end_of_elaboration();
00780
00781 virtual const char* kind() const
00782 { return "sc_in"; }
00783
00784
00785
00786 void add_trace( sc_trace_file*, const std::string& ) const;
00787
00788 protected:
00789
00790 void remove_traces() const;
00791
00792 mutable sc_trace_params_vec* m_traces;
00793
00794 protected:
00795
00796
00797 virtual int vbind( sc_interface& );
00798 virtual int vbind( sc_port_base& );
00799
00800 private:
00801
00802
00803 sc_in( const this_type& );
00804 this_type& operator = ( const this_type& );
00805
00806 #ifdef __GNUC__
00807
00808
00809
00810
00811 static data_type dummy;
00812 #endif
00813 };
00814
00815
00816
00817
00818
00819
00820 inline
00821 const sc_signal_logic_deval&
00822 sc_in<sc_dt::sc_logic>::delayed() const
00823 {
00824 const in_if_type* iface = DCAST<const in_if_type*>( get_interface() );
00825 if( iface != 0 ) {
00826 return RCAST<const sc_signal_logic_deval&>( *iface );
00827 } else {
00828
00829 const sc_port_base* pb = this;
00830 return RCAST<const sc_signal_logic_deval&>( *pb );
00831 }
00832 }
00833
00834
00835
00836
00837
00838
00839
00840
00841 template <class T>
00842 class sc_inout
00843 : public sc_port<sc_signal_inout_if<T>,1>
00844 {
00845 public:
00846
00847
00848
00849 typedef T data_type;
00850
00851 typedef sc_signal_inout_if<data_type> if_type;
00852 typedef sc_port<if_type,1> base_type;
00853 typedef sc_inout<data_type> this_type;
00854
00855 typedef sc_signal_in_if<data_type> in_if_type;
00856 typedef sc_port<in_if_type,1> in_port_type;
00857 typedef if_type inout_if_type;
00858 typedef base_type inout_port_type;
00859
00860 public:
00861
00862
00863
00864 sc_inout()
00865 : base_type(), m_init_val( 0 ), m_traces( 0 )
00866 {}
00867
00868 explicit sc_inout( const char* name_ )
00869 : base_type( name_ ), m_init_val( 0 ), m_traces( 0 )
00870 {}
00871
00872 explicit sc_inout( inout_if_type& interface_ )
00873 : base_type( interface_ ), m_init_val( 0 ), m_traces( 0 )
00874 {}
00875
00876 sc_inout( const char* name_, inout_if_type& interface_ )
00877 : base_type( name_, interface_ ), m_init_val( 0 ), m_traces( 0 )
00878 {}
00879
00880 explicit sc_inout( inout_port_type& parent_ )
00881 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
00882 {}
00883
00884 sc_inout( const char* name_, inout_port_type& parent_ )
00885 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
00886 {}
00887
00888 sc_inout( this_type& parent_ )
00889 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
00890 {}
00891
00892 sc_inout( const char* name_, this_type& parent_ )
00893 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
00894 {}
00895
00896
00897
00898
00899 virtual ~sc_inout();
00900
00901
00902
00903
00904
00905
00906 const sc_event& default_event() const
00907 { return (*this)->default_event(); }
00908
00909
00910
00911
00912 const sc_event& value_changed_event() const
00913 { return (*this)->value_changed_event(); }
00914
00915
00916
00917
00918 const data_type& read() const
00919 { return (*this)->read(); }
00920
00921 operator const data_type& () const
00922 { return (*this)->read(); }
00923
00924
00925
00926
00927 bool event() const
00928 { return (*this)->event(); }
00929
00930
00931
00932
00933 void write( const data_type& value_ )
00934 { (*this)->write( value_ ); }
00935
00936 this_type& operator = ( const data_type& value_ )
00937 { (*this)->write( value_ ); return *this; }
00938
00939 this_type& operator = ( const in_if_type& interface_ )
00940 { (*this)->write( interface_.read() ); return *this; }
00941
00942 this_type& operator = ( const in_port_type& port_ )
00943 { (*this)->write( port_->read() ); return *this; }
00944
00945 this_type& operator = ( const inout_port_type& port_ )
00946 { (*this)->write( port_->read() ); return *this; }
00947
00948 this_type& operator = ( const this_type& port_ )
00949 { (*this)->write( port_->read() ); return *this; }
00950
00951
00952
00953
00954 void initialize( const data_type& value_ );
00955
00956 void initialize( const in_if_type& interface_ )
00957 { initialize( interface_.read() ); }
00958
00959
00960
00961
00962
00963
00964 virtual void end_of_elaboration();
00965
00966
00967
00968
00969 sc_event_finder& value_changed() const
00970 {
00971 return *new sc_event_finder_t<in_if_type>(
00972 *this, &in_if_type::value_changed_event );
00973 }
00974
00975 virtual const char* kind() const
00976 { return "sc_inout"; }
00977
00978 protected:
00979
00980 data_type* m_init_val;
00981
00982 public:
00983
00984
00985 void add_trace( sc_trace_file*, const std::string& ) const;
00986
00987 protected:
00988
00989 void remove_traces() const;
00990
00991 mutable sc_trace_params_vec* m_traces;
00992
00993 private:
00994
00995
00996 sc_inout( const this_type& );
00997
00998 #ifdef __GNUC__
00999
01000
01001
01002
01003 static data_type dummy;
01004 #endif
01005 };
01006
01007 template<typename T>
01008 ::std::ostream& operator << ( ::std::ostream& os, const sc_inout<T>& a )
01009 {
01010 return os << a->read();
01011 }
01012
01013
01014
01015
01016
01017
01018 template <class T>
01019 inline
01020 sc_inout<T>::~sc_inout()
01021 {
01022 if( m_init_val != 0 ) {
01023 delete m_init_val;
01024 }
01025 remove_traces();
01026 }
01027
01028
01029
01030
01031 template <class T>
01032 inline
01033 void
01034 sc_inout<T>::initialize( const data_type& value_ )
01035 {
01036 inout_if_type* iface = DCAST<inout_if_type*>( this->get_interface() );
01037 if( iface != 0 ) {
01038 iface->write( value_ );
01039 } else {
01040 if( m_init_val == 0 ) {
01041 m_init_val = new data_type;
01042 }
01043 *m_init_val = value_;
01044 }
01045 }
01046
01047
01048
01049
01050 template <class T>
01051 inline
01052 void
01053 sc_inout<T>::end_of_elaboration()
01054 {
01055 if( m_init_val != 0 ) {
01056 write( *m_init_val );
01057 delete m_init_val;
01058 m_init_val = 0;
01059 }
01060 if( m_traces != 0 ) {
01061 for( int i = 0; i < m_traces->size(); ++ i ) {
01062 sc_trace_params* p = (*m_traces)[i];
01063 in_if_type* iface = DCAST<in_if_type*>( this->get_interface() );
01064 sc_trace( p->tf, iface->get_data_ref(), p->name );
01065 }
01066 remove_traces();
01067 }
01068 }
01069
01070
01071
01072
01073 template <class T>
01074 inline
01075 void
01076 sc_inout<T>::add_trace( sc_trace_file* tf_, const std::string& name_) const
01077 {
01078 if( tf_ != 0 ) {
01079 if( m_traces == 0 ) {
01080 m_traces = new sc_trace_params_vec;
01081 }
01082 m_traces->push_back( new sc_trace_params( tf_, name_ ) );
01083 }
01084 }
01085
01086 template <class T>
01087 inline
01088 void
01089 sc_inout<T>::remove_traces() const
01090 {
01091 if( m_traces != 0 ) {
01092 for( int i = m_traces->size() - 1; i >= 0; -- i ) {
01093 delete (*m_traces)[i];
01094 }
01095 delete m_traces;
01096 m_traces = 0;
01097 }
01098 }
01099
01100
01101
01102
01103
01104
01105
01106
01107 template <>
01108 class sc_inout<bool>
01109 : public sc_port<sc_signal_inout_if<bool>,1>
01110 {
01111 public:
01112
01113
01114
01115 typedef bool data_type;
01116
01117 typedef sc_signal_inout_if<data_type> if_type;
01118 typedef sc_port<if_type,1> base_type;
01119 typedef sc_inout<data_type> this_type;
01120
01121 typedef sc_signal_in_if<data_type> in_if_type;
01122 typedef sc_port<in_if_type,1> in_port_type;
01123 typedef if_type inout_if_type;
01124 typedef base_type inout_port_type;
01125
01126 public:
01127
01128
01129
01130 sc_inout()
01131 : base_type(), m_init_val( 0 ), m_traces( 0 )
01132 {}
01133
01134 explicit sc_inout( const char* name_ )
01135 : base_type( name_ ), m_init_val( 0 ), m_traces( 0 )
01136 {}
01137
01138 explicit sc_inout( inout_if_type& interface_ )
01139 : base_type( interface_ ), m_init_val( 0 ), m_traces( 0 )
01140 {}
01141
01142 sc_inout( const char* name_, inout_if_type& interface_ )
01143 : base_type( name_, interface_ ), m_init_val( 0 ), m_traces( 0 )
01144 {}
01145
01146 explicit sc_inout( inout_port_type& parent_ )
01147 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
01148 {}
01149
01150 sc_inout( const char* name_, inout_port_type& parent_ )
01151 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
01152 {}
01153
01154 sc_inout( this_type& parent_ )
01155 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
01156 {}
01157
01158 sc_inout( const char* name_, this_type& parent_ )
01159 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
01160 {}
01161
01162
01163
01164
01165 virtual ~sc_inout();
01166
01167
01168
01169
01170
01171
01172 const sc_event& default_event() const
01173 { return (*this)->default_event(); }
01174
01175
01176
01177
01178 const sc_event& value_changed_event() const
01179 { return (*this)->value_changed_event(); }
01180
01181
01182
01183 const sc_event& posedge_event() const
01184 { return (*this)->posedge_event(); }
01185
01186
01187
01188 const sc_event& negedge_event() const
01189 { return (*this)->negedge_event(); }
01190
01191
01192
01193
01194 const data_type& read() const
01195 { return (*this)->read(); }
01196
01197 operator const data_type& () const
01198 { return (*this)->read(); }
01199
01200
01201
01202
01203 sc_event_finder& pos() const
01204 {
01205 return *new sc_event_finder_t<in_if_type>(
01206 *this, &in_if_type::posedge_event );
01207 }
01208
01209
01210
01211 sc_event_finder& neg() const
01212 {
01213 return *new sc_event_finder_t<in_if_type>(
01214 *this, &in_if_type::negedge_event );
01215 }
01216
01217
01218
01219
01220 bool event() const
01221 { return (*this)->event(); }
01222
01223
01224
01225 bool posedge() const
01226 { return (*this)->posedge(); }
01227
01228
01229
01230 bool negedge() const
01231 { return (*this)->negedge(); }
01232
01233
01234
01235 const sc_signal_bool_deval& delayed() const;
01236
01237
01238
01239 void write( const data_type& value_ )
01240 { (*this)->write( value_ ); }
01241
01242 this_type& operator = ( const data_type& value_ )
01243 { (*this)->write( value_ ); return *this; }
01244
01245 this_type& operator = ( const in_if_type& interface_ )
01246 { (*this)->write( interface_.read() ); return *this; }
01247
01248 this_type& operator = ( const in_port_type& port_ )
01249 { (*this)->write( port_->read() ); return *this; }
01250
01251 this_type& operator = ( const inout_port_type& port_ )
01252 { (*this)->write( port_->read() ); return *this; }
01253
01254 this_type& operator = ( const this_type& port_ )
01255 { (*this)->write( port_->read() ); return *this; }
01256
01257
01258
01259
01260 void initialize( const data_type& value_ );
01261
01262 void initialize( const in_if_type& interface_ )
01263 { initialize( interface_.read() ); }
01264
01265
01266
01267
01268
01269
01270 virtual void end_of_elaboration();
01271
01272
01273
01274
01275 sc_event_finder& value_changed() const
01276 {
01277 return *new sc_event_finder_t<in_if_type>(
01278 *this, &in_if_type::value_changed_event );
01279 }
01280
01281 virtual const char* kind() const
01282 { return "sc_inout"; }
01283
01284 protected:
01285
01286 data_type* m_init_val;
01287
01288 public:
01289
01290
01291 void add_trace( sc_trace_file*, const std::string& ) const;
01292
01293 protected:
01294
01295 void remove_traces() const;
01296
01297 mutable sc_trace_params_vec* m_traces;
01298
01299 private:
01300
01301
01302 sc_inout( const this_type& );
01303
01304 #ifdef __GNUC__
01305
01306
01307
01308
01309 static data_type dummy;
01310 #endif
01311 };
01312
01313
01314
01315
01316
01317
01318 inline
01319 const sc_signal_bool_deval&
01320 sc_inout<bool>::delayed() const
01321 {
01322 const in_if_type* iface = DCAST<const in_if_type*>( get_interface() );
01323 if( iface != 0 ) {
01324 return RCAST<const sc_signal_bool_deval&>( *iface );
01325 } else {
01326
01327 const sc_port_base* pb = this;
01328 return RCAST<const sc_signal_bool_deval&>( *pb );
01329 }
01330 }
01331
01332
01333
01334
01335
01336
01337
01338
01339 template <>
01340 class sc_inout<sc_dt::sc_logic>
01341 : public sc_port<sc_signal_inout_if<sc_dt::sc_logic>,1>
01342 {
01343 public:
01344
01345
01346
01347 typedef sc_dt::sc_logic data_type;
01348
01349 typedef sc_signal_inout_if<data_type> if_type;
01350 typedef sc_port<if_type,1> base_type;
01351 typedef sc_inout<data_type> this_type;
01352
01353 typedef sc_signal_in_if<data_type> in_if_type;
01354 typedef sc_port<in_if_type,1> in_port_type;
01355 typedef if_type inout_if_type;
01356 typedef base_type inout_port_type;
01357
01358 public:
01359
01360
01361
01362 sc_inout()
01363 : base_type(), m_init_val( 0 ), m_traces( 0 )
01364 {}
01365
01366 explicit sc_inout( const char* name_ )
01367 : base_type( name_ ), m_init_val( 0 ), m_traces( 0 )
01368 {}
01369
01370 explicit sc_inout( inout_if_type& interface_ )
01371 : base_type( interface_ ), m_init_val( 0 ), m_traces( 0 )
01372 {}
01373
01374 sc_inout( const char* name_, inout_if_type& interface_ )
01375 : base_type( name_, interface_ ), m_init_val( 0 ), m_traces( 0 )
01376 {}
01377
01378 explicit sc_inout( inout_port_type& parent_ )
01379 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
01380 {}
01381
01382 sc_inout( const char* name_, inout_port_type& parent_ )
01383 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
01384 {}
01385
01386 sc_inout( this_type& parent_ )
01387 : base_type( parent_ ), m_init_val( 0 ), m_traces( 0 )
01388 {}
01389
01390 sc_inout( const char* name_, this_type& parent_ )
01391 : base_type( name_, parent_ ), m_init_val( 0 ), m_traces( 0 )
01392 {}
01393
01394
01395
01396
01397 virtual ~sc_inout();
01398
01399
01400
01401
01402
01403
01404 const sc_event& default_event() const
01405 { return (*this)->default_event(); }
01406
01407
01408
01409
01410 const sc_event& value_changed_event() const
01411 { return (*this)->value_changed_event(); }
01412
01413
01414
01415 const sc_event& posedge_event() const
01416 { return (*this)->posedge_event(); }
01417
01418
01419
01420 const sc_event& negedge_event() const
01421 { return (*this)->negedge_event(); }
01422
01423
01424
01425
01426 const data_type& read() const
01427 { return (*this)->read(); }
01428
01429 operator const data_type& () const
01430 { return (*this)->read(); }
01431
01432
01433
01434
01435 sc_event_finder& pos() const
01436 {
01437 return *new sc_event_finder_t<in_if_type>(
01438 *this, &in_if_type::posedge_event );
01439 }
01440
01441
01442
01443 sc_event_finder& neg() const
01444 {
01445 return *new sc_event_finder_t<in_if_type>(
01446 *this, &in_if_type::negedge_event );
01447 }
01448
01449
01450
01451
01452 bool event() const
01453 { return (*this)->event(); }
01454
01455
01456
01457 bool posedge() const
01458 { return (*this)->posedge(); }
01459
01460
01461
01462 bool negedge() const
01463 { return (*this)->negedge(); }
01464
01465
01466
01467 const sc_signal_logic_deval& delayed() const;
01468
01469
01470
01471
01472 void write( const data_type& value_ )
01473 { (*this)->write( value_ ); }
01474
01475 this_type& operator = ( const data_type& value_ )
01476 { (*this)->write( value_ ); return *this; }
01477
01478 this_type& operator = ( const in_if_type& interface_ )
01479 { (*this)->write( interface_.read() ); return *this; }
01480
01481 this_type& operator = ( const in_port_type& port_ )
01482 { (*this)->write( port_->read() ); return *this; }
01483
01484 this_type& operator = ( const inout_port_type& port_ )
01485 { (*this)->write( port_->read() ); return *this; }
01486
01487 this_type& operator = ( const this_type& port_ )
01488 { (*this)->write( port_->read() ); return *this; }
01489
01490
01491
01492
01493 void initialize( const data_type& value_ );
01494
01495 void initialize( const in_if_type& interface_ )
01496 { initialize( interface_.read() ); }
01497
01498
01499
01500
01501
01502
01503 virtual void end_of_elaboration();
01504
01505
01506
01507
01508 sc_event_finder& value_changed() const
01509 {
01510 return *new sc_event_finder_t<in_if_type>(
01511 *this, &in_if_type::value_changed_event );
01512 }
01513
01514 virtual const char* kind() const
01515 { return "sc_inout"; }
01516
01517 protected:
01518
01519 data_type* m_init_val;
01520
01521 public:
01522
01523
01524 void add_trace( sc_trace_file*, const std::string& ) const;
01525
01526 protected:
01527
01528 void remove_traces() const;
01529
01530 mutable sc_trace_params_vec* m_traces;
01531
01532 private:
01533
01534
01535 sc_inout( const this_type& );
01536
01537 #ifdef __GNUC__
01538
01539
01540
01541
01542 static data_type dummy;
01543 #endif
01544 };
01545
01546
01547
01548
01549
01550
01551 inline
01552 const sc_signal_logic_deval&
01553 sc_inout<sc_dt::sc_logic>::delayed() const
01554 {
01555 const in_if_type* iface = DCAST<const in_if_type*>( get_interface() );
01556 if( iface != 0 ) {
01557 return RCAST<const sc_signal_logic_deval&>( *iface );
01558 } else {
01559
01560 const sc_port_base* pb = this;
01561 return RCAST<const sc_signal_logic_deval&>( *pb );
01562 }
01563 }
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575 template <class T>
01576 class sc_out
01577 : public sc_inout<T>
01578 {
01579 public:
01580
01581
01582
01583 typedef T data_type;
01584
01585 typedef sc_out<data_type> this_type;
01586 typedef sc_inout<data_type> base_type;
01587
01588 typedef typename base_type::in_if_type in_if_type;
01589 typedef typename base_type::in_port_type in_port_type;
01590 typedef typename base_type::inout_if_type inout_if_type;
01591 typedef typename base_type::inout_port_type inout_port_type;
01592
01593 public:
01594
01595
01596
01597 sc_out()
01598 : base_type()
01599 {}
01600
01601 explicit sc_out( const char* name_ )
01602 : base_type( name_ )
01603 {}
01604
01605 explicit sc_out( inout_if_type& interface_ )
01606 : base_type( interface_ )
01607 {}
01608
01609 sc_out( const char* name_, inout_if_type& interface_ )
01610 : base_type( name_, interface_ )
01611 {}
01612
01613 explicit sc_out( inout_port_type& parent_ )
01614 : base_type( parent_ )
01615 {}
01616
01617 sc_out( const char* name_, inout_port_type& parent_ )
01618 : base_type( name_, parent_ )
01619 {}
01620
01621 sc_out( this_type& parent_ )
01622 : base_type( parent_ )
01623 {}
01624
01625 sc_out( const char* name_, this_type& parent_ )
01626 : base_type( name_, parent_ )
01627 {}
01628
01629
01630
01631
01632 virtual ~sc_out()
01633 {}
01634
01635
01636
01637
01638 this_type& operator = ( const data_type& value_ )
01639 { (*this)->write( value_ ); return *this; }
01640
01641 this_type& operator = ( const in_if_type& interface_ )
01642 { (*this)->write( interface_.read() ); return *this; }
01643
01644 this_type& operator = ( const in_port_type& port_ )
01645 { (*this)->write( port_->read() ); return *this; }
01646
01647 this_type& operator = ( const inout_port_type& port_ )
01648 { (*this)->write( port_->read() ); return *this; }
01649
01650 this_type& operator = ( const this_type& port_ )
01651 { (*this)->write( port_->read() ); return *this; }
01652
01653 virtual const char* kind() const
01654 { return "sc_out"; }
01655
01656 private:
01657
01658
01659 sc_out( const this_type& );
01660 };
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670 template <class T>
01671 inline
01672 void
01673 sc_trace(sc_trace_file* tf, const sc_in<T>& port, const std::string& name)
01674 {
01675 const sc_signal_in_if<T>* iface = 0;
01676 if (sc_get_curr_simcontext()->elaboration_done() )
01677 {
01678 iface = DCAST<const sc_signal_in_if<T>*>( port.get_interface() );
01679 }
01680
01681 if ( iface )
01682 sc_trace( tf, iface->get_data_ref(), name );
01683 else
01684 port.add_trace( tf, name );
01685 }
01686
01687 template <class T>
01688 inline
01689 void
01690 sc_trace( sc_trace_file* tf, const sc_inout<T>& port,
01691 const std::string& name )
01692 {
01693 const sc_signal_in_if<T>* iface = 0;
01694 if (sc_get_curr_simcontext()->elaboration_done() )
01695 {
01696 iface =DCAST<const sc_signal_in_if<T>*>( port.get_interface() );
01697 }
01698
01699 if ( iface )
01700 sc_trace( tf, iface->get_data_ref(), name );
01701 else
01702 port.add_trace( tf, name );
01703 }
01704
01705 }
01706
01707 #endif
01708
01709