sc_signal_ports.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_signal_ports.cpp -- The sc_signal<T> port classes.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-08-20
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033     
00034  *****************************************************************************/
00035 
00036 
00037 // $Log: sc_signal_ports.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:35  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.7  2006/04/18 18:01:26  acg
00042 //  Andy Goodrich: added an add_trace_internal() method to the various port
00043 //  classes so that sc_trace has something to call that won't emit an
00044 //  IEEE 1666 deprecation message.
00045 //
00046 // Revision 1.6  2006/02/02 23:42:37  acg
00047 //  Andy Goodrich: implemented a much better fix to the sc_event_finder
00048 //  proliferation problem. This new version allocates only a single event
00049 //  finder for each port for each type of event, e.g., pos(), neg(), and
00050 //  value_change(). The event finder persists as long as the port does,
00051 //  which is what the LRM dictates. Because only a single instance is
00052 //  allocated for each event type per port there is not a potential
00053 //  explosion of storage as was true in the 2.0.1/2.1 versions.
00054 //
00055 // Revision 1.5  2006/01/25 00:31:11  acg
00056 //  Andy Goodrich: Changed over to use a standard message id of
00057 //  SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
00058 //
00059 // Revision 1.4  2006/01/24 20:46:32  acg
00060 // Andy Goodrich: changes to eliminate use of deprecated features. For instance,
00061 // using notify(SC_ZERO_TIME) in place of notify_delayed().
00062 //
00063 // Revision 1.3  2006/01/13 18:47:42  acg
00064 // Added $Log command so that CVS comments are reproduced in the source.
00065 //
00066 
00067 #include "sysc/communication/sc_signal_ports.h"
00068 #include "sysc/datatypes/int/sc_signed.h"
00069 #include "sysc/datatypes/int/sc_unsigned.h"
00070 #include "sysc/datatypes/bit/sc_lv_base.h"
00071 #include "sysc/utils/sc_utils_ids.h"
00072 
00073 namespace sc_core {
00074 
00075 // ----------------------------------------------------------------------------
00076 //  CLASS : sc_in<bool>
00077 //
00078 //  Specialization of sc_in<T> for type bool.
00079 // ----------------------------------------------------------------------------
00080 
00081 // called when elaboration is done
00082 
00083 void
00084 sc_in<bool>::end_of_elaboration()
00085 {
00086     if( m_traces != 0 ) {
00087     for( int i = 0; i < (int)m_traces->size(); ++ i ) {
00088         sc_trace_params* p = (*m_traces)[i];
00089         in_if_type* iface = DCAST<in_if_type*>( get_interface() );
00090         sc_trace( p->tf, iface->read(), p->name );
00091     }
00092     remove_traces();
00093     }
00094 }
00095 
00096 // called by sc_trace
00097 
00098 void
00099 sc_in<bool>::add_trace_internal(sc_trace_file* tf_, 
00100     const std::string& name_) const
00101 {
00102     if( tf_ != 0 ) {
00103     if( m_traces == 0 ) {
00104         m_traces = new sc_trace_params_vec;
00105     }
00106     m_traces->push_back( new sc_trace_params( tf_, name_ ) );
00107     }
00108 }
00109 
00110 void
00111 sc_in<bool>::add_trace(sc_trace_file* tf_, 
00112     const std::string& name_) const
00113 {
00114     sc_deprecated_add_trace();
00115     add_trace_internal(tf_, name_);
00116 }
00117 
00118 void
00119 sc_in<bool>::remove_traces() const
00120 {
00121     if( m_traces != 0 ) {
00122     for( int i = m_traces->size() - 1; i >= 0; -- i ) {
00123         delete (*m_traces)[i];
00124     }
00125     delete m_traces;
00126     m_traces = 0;
00127     }
00128 }
00129 
00130 
00131 // called by pbind (for internal use only)
00132 
00133 int
00134 sc_in<bool>::vbind( sc_interface& interface_ )
00135 {
00136     return sc_port_b<if_type>::vbind( interface_ );
00137 }
00138 
00139 int
00140 sc_in<bool>::vbind( sc_port_base& parent_ )
00141 {
00142     in_port_type* in_parent = DCAST<in_port_type*>( &parent_ );
00143     if( in_parent != 0 ) {
00144     sc_port_base::bind( *in_parent );
00145     return 0;
00146     }
00147     inout_port_type* inout_parent = DCAST<inout_port_type*>( &parent_ );
00148     if( inout_parent != 0 ) {
00149     sc_port_base::bind( *inout_parent );
00150     return 0;
00151     }
00152     // type mismatch
00153     return 2;
00154 }
00155 
00156 
00157 // ----------------------------------------------------------------------------
00158 //  CLASS : sc_in<sc_logic>
00159 //
00160 //  Specialization of sc_in<T> for type sc_logic.
00161 // ----------------------------------------------------------------------------
00162 
00163 // called when elaboration is done
00164 
00165 void
00166 sc_in<sc_dt::sc_logic>::end_of_elaboration()
00167 {
00168     if( m_traces != 0 ) {
00169     for( int i = 0; i < (int)m_traces->size(); ++ i ) {
00170         sc_trace_params* p = (*m_traces)[i];
00171         in_if_type* iface = DCAST<in_if_type*>( get_interface() );
00172         sc_trace( p->tf, iface->read(), p->name );
00173     }
00174     remove_traces();
00175     }
00176 }
00177 
00178 
00179 // called by sc_trace
00180 
00181 void
00182 sc_in<sc_dt::sc_logic>::add_trace_internal( sc_trace_file* tf_, 
00183     const std::string& name_ ) const
00184 {
00185     if( tf_ != 0 ) {
00186     if( m_traces == 0 ) {
00187         m_traces = new sc_trace_params_vec;
00188     }
00189     m_traces->push_back( new sc_trace_params( tf_, name_ ) );
00190     }
00191 }
00192 
00193 void
00194 sc_in<sc_dt::sc_logic>::add_trace( sc_trace_file* tf_, 
00195     const std::string& name_ ) const
00196 {
00197     sc_deprecated_add_trace();
00198     add_trace_internal(tf_, name_);
00199 }
00200 
00201 void
00202 sc_in<sc_dt::sc_logic>::remove_traces() const
00203 {
00204     if( m_traces != 0 ) {
00205     for( int i = m_traces->size() - 1; i >= 0; -- i ) {
00206         delete (*m_traces)[i];
00207     }
00208     delete m_traces;
00209     m_traces = 0;
00210     }
00211 }
00212 
00213 
00214 // called by pbind (for internal use only)
00215 
00216 int
00217 sc_in<sc_dt::sc_logic>::vbind( sc_interface& interface_ )
00218 {
00219     return sc_port_b<if_type>::vbind( interface_ );
00220 }
00221 
00222 int
00223 sc_in<sc_dt::sc_logic>::vbind( sc_port_base& parent_ )
00224 {
00225     in_port_type* in_parent = DCAST<in_port_type*>( &parent_ );
00226     if( in_parent != 0 ) {
00227     sc_port_base::bind( *in_parent );
00228     return 0;
00229     }
00230     inout_port_type* inout_parent = DCAST<inout_port_type*>( &parent_ );
00231     if( inout_parent != 0 ) {
00232     sc_port_base::bind( *inout_parent );
00233     return 0;
00234     }
00235     // type mismatch
00236     return 2;
00237 }
00238 
00239 
00240 // ----------------------------------------------------------------------------
00241 //  CLASS : sc_inout<bool>
00242 //
00243 //  Specialization of sc_inout<T> for type bool.
00244 // ----------------------------------------------------------------------------
00245 
00246 // destructor
00247 
00248 sc_inout<bool>::~sc_inout()
00249 {
00250     if ( m_change_finder_p ) delete m_change_finder_p;
00251     if ( m_neg_finder_p ) delete m_neg_finder_p;
00252     if ( m_pos_finder_p ) delete m_pos_finder_p;
00253     if( m_init_val != 0 ) {
00254     delete m_init_val;
00255     }
00256     remove_traces();
00257 }
00258 
00259 
00260 // set initial value (can also be called when port is not bound yet)
00261 
00262 void
00263 sc_inout<bool>::initialize( const data_type& value_ )
00264 {
00265     inout_if_type* iface = DCAST<inout_if_type*>( get_interface() );
00266     if( iface != 0 ) {
00267     iface->write( value_ );
00268     } else {
00269     if( m_init_val == 0 ) {
00270         m_init_val = new data_type;
00271     }
00272     *m_init_val = value_;
00273     }
00274 }
00275 
00276 
00277 // called when elaboration is done
00278 
00279 void
00280 sc_inout<bool>::end_of_elaboration()
00281 {
00282     if( m_init_val != 0 ) {
00283     write( *m_init_val );
00284     delete m_init_val;
00285     m_init_val = 0;
00286     }
00287     if( m_traces != 0 ) {
00288     for( int i = 0; i < (int)m_traces->size(); ++ i ) {
00289         sc_trace_params* p = (*m_traces)[i];
00290         in_if_type* iface = DCAST<in_if_type*>( get_interface() );
00291         sc_trace( p->tf, iface->read(), p->name );
00292     }
00293     remove_traces();
00294     }
00295 }
00296 
00297 
00298 // called by sc_trace
00299 
00300 void
00301 sc_inout<bool>::add_trace_internal( sc_trace_file* tf_, 
00302     const std::string& name_ ) const
00303 {
00304     if( tf_ != 0 ) {
00305     if( m_traces == 0 ) {
00306         m_traces = new sc_trace_params_vec;
00307     }
00308     m_traces->push_back( new sc_trace_params( tf_, name_ ) );
00309     }
00310 }
00311 
00312 void
00313 sc_inout<bool>::add_trace( sc_trace_file* tf_, 
00314     const std::string& name_ ) const
00315 {
00316     sc_deprecated_add_trace();
00317     add_trace_internal(tf_, name_);
00318 }
00319 
00320 void
00321 sc_inout<bool>::remove_traces() const
00322 {
00323     if( m_traces != 0 ) {
00324     for( int i = m_traces->size() - 1; i >= 0; -- i ) {
00325         delete (*m_traces)[i];
00326     }
00327     delete m_traces;
00328     m_traces = 0;
00329     }
00330 }
00331 
00332 
00333 // ----------------------------------------------------------------------------
00334 //  CLASS : sc_inout<sc_dt::sc_logic>
00335 //
00336 //  Specialization of sc_inout<T> for type sc_dt::sc_logic.
00337 // ----------------------------------------------------------------------------
00338 
00339 // destructor
00340 
00341 sc_inout<sc_dt::sc_logic>::~sc_inout()
00342 {
00343     if ( m_change_finder_p ) delete m_change_finder_p;
00344     if ( m_neg_finder_p ) delete m_neg_finder_p;
00345     if ( m_pos_finder_p ) delete m_pos_finder_p;
00346     if( m_init_val != 0 ) {
00347     delete m_init_val;
00348     }
00349     remove_traces();
00350 }
00351 
00352 
00353 // set initial value (can also be called when port is not bound yet)
00354 
00355 void
00356 sc_inout<sc_dt::sc_logic>::initialize( const data_type& value_ )
00357 {
00358     inout_if_type* iface = DCAST<inout_if_type*>( get_interface() );
00359     if( iface != 0 ) {
00360     iface->write( value_ );
00361     } else {
00362     if( m_init_val == 0 ) {
00363         m_init_val = new data_type;
00364     }
00365     *m_init_val = value_;
00366     }
00367 }
00368 
00369 
00370 // called when elaboration is done
00371 
00372 void
00373 sc_inout<sc_dt::sc_logic>::end_of_elaboration()
00374 {
00375     if( m_init_val != 0 ) {
00376     write( *m_init_val );
00377     delete m_init_val;
00378     m_init_val = 0;
00379     }
00380     if( m_traces != 0 ) {
00381     for( int i = 0; i < (int)m_traces->size(); ++ i ) {
00382         sc_trace_params* p = (*m_traces)[i];
00383         in_if_type* iface = DCAST<in_if_type*>( get_interface() );
00384         sc_trace( p->tf, iface->read(), p->name );
00385     }
00386     remove_traces();
00387     }
00388 }
00389 
00390 
00391 // called by sc_trace
00392 
00393 void
00394 sc_inout<sc_dt::sc_logic>::add_trace_internal( sc_trace_file* tf_,
00395                    const std::string& name_ ) const
00396 {
00397     if( tf_ != 0 ) {
00398     if( m_traces == 0 ) {
00399         m_traces = new sc_trace_params_vec;
00400     }
00401     m_traces->push_back( new sc_trace_params( tf_, name_ ) );
00402     }
00403 }
00404 
00405 
00406 void
00407 sc_inout<sc_dt::sc_logic>::add_trace( sc_trace_file* tf_,
00408                    const std::string& name_ ) const
00409 {
00410     sc_deprecated_add_trace();
00411     add_trace_internal(tf_, name_);
00412 }
00413 
00414 void
00415 sc_inout<sc_dt::sc_logic>::remove_traces() const
00416 {
00417     if( m_traces != 0 ) {
00418     for( int i = m_traces->size() - 1; i >= 0; -- i ) {
00419         delete (*m_traces)[i];
00420     }
00421     delete m_traces;
00422     m_traces = 0;
00423     }
00424 }
00425 
00426 void sc_deprecated_add_trace()
00427 {
00428     static bool warn_add_trace_deprecated=true;
00429     if ( warn_add_trace_deprecated )
00430     {
00431         warn_add_trace_deprecated=false;
00432     SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
00433         "sc_signal<T>::addtrace() is deprecated");
00434     }
00435 }
00436 } // namespace sc_core
00437 
00438 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5