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