📄 sc_signal_ports.h
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_signal_ports.h -- The sc_signal<T> port classes. Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 Change log appears at end of file *****************************************************************************/#ifndef SC_SIGNAL_PORTS_H#define SC_SIGNAL_PORTS_H#include "sysc/communication/sc_event_finder.h"#include "sysc/communication/sc_port.h"#include "sysc/communication/sc_signal_ifs.h"#include "sysc/datatypes/bit/sc_logic.h"#include "sysc/tracing/sc_trace.h"namespace sc_core {// ----------------------------------------------------------------------------// STRUCT : sc_trace_params//// Struct for storing the trace file and object name of an sc_trace call.// FOR INTERNAL USE ONLY!// ----------------------------------------------------------------------------extern void sc_deprecated_add_trace();struct sc_trace_params{ sc_trace_file* tf; std::string name; sc_trace_params( sc_trace_file* tf_, const std::string& name_ ) : tf( tf_ ), name( name_ ) {}};typedef std::vector<sc_trace_params*> sc_trace_params_vec;// ----------------------------------------------------------------------------// CLASS : sc_in<T>//// The sc_signal<T> input port class.// ----------------------------------------------------------------------------template <class T>class sc_in: public sc_port<sc_signal_in_if<T>,1,SC_ONE_OR_MORE_BOUND>{public: // typedefs typedef T data_type; typedef sc_signal_in_if<data_type> if_type; typedef sc_port<if_type,1,SC_ONE_OR_MORE_BOUND> base_type; typedef sc_in<data_type> this_type; typedef if_type in_if_type; typedef base_type in_port_type; typedef sc_signal_inout_if<data_type> inout_if_type; typedef sc_port<inout_if_type,1,SC_ONE_OR_MORE_BOUND> inout_port_type;public: // constructors sc_in() : base_type(), m_traces( 0 ), m_change_finder_p(0) {} explicit sc_in( const char* name_ ) : base_type( name_ ), m_traces( 0 ), m_change_finder_p(0) {} explicit sc_in( const in_if_type& interface_ ) : base_type( CCAST<in_if_type&>( interface_ ) ), m_traces( 0 ), m_change_finder_p(0) {} sc_in( const char* name_, const in_if_type& interface_ ) : base_type( name_, CCAST<in_if_type&>( interface_ ) ), m_traces( 0 ), m_change_finder_p(0) {} explicit sc_in( in_port_type& parent_ ) : base_type( parent_ ), m_traces( 0 ), m_change_finder_p(0) {} sc_in( const char* name_, in_port_type& parent_ ) : base_type( name_, parent_ ), m_traces( 0 ), m_change_finder_p(0) {} explicit sc_in( inout_port_type& parent_ ) : base_type(), m_traces( 0 ), m_change_finder_p(0) { sc_port_base::bind( parent_ ); } sc_in( const char* name_, inout_port_type& parent_ ) : base_type( name_ ), m_traces( 0 ), m_change_finder_p(0) { sc_port_base::bind( parent_ ); } sc_in( this_type& parent_ ) : base_type( parent_ ), m_traces( 0 ), m_change_finder_p(0) {} sc_in( const char* name_, this_type& parent_ ) : base_type( name_, parent_ ), m_traces( 0 ), m_change_finder_p(0) {} // destructor virtual ~sc_in() { remove_traces(); if ( m_change_finder_p ) delete m_change_finder_p; } // bind to in interface void bind( const in_if_type& interface_ ) { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); } void operator () ( const in_if_type& interface_ ) { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); } // bind to parent in port void bind( in_port_type& parent_ ) { sc_port_base::bind( parent_ ); } void operator () ( in_port_type& parent_ ) { sc_port_base::bind( parent_ ); } // bind to parent inout port void bind( inout_port_type& parent_ ) { sc_port_base::bind( parent_ ); } void operator () ( inout_port_type& parent_ ) { sc_port_base::bind( parent_ ); } // interface access shortcut methods // get the default event const sc_event& default_event() const { return (*this)->default_event(); } // get the value changed event const sc_event& value_changed_event() const { return (*this)->value_changed_event(); } // read the current value const data_type& read() const { return (*this)->read(); } operator const data_type& () const { return (*this)->read(); } // was there a value changed event? bool event() const { return (*this)->event(); } // (other) event finder method(s) sc_event_finder& value_changed() const { if ( !m_change_finder_p ) { m_change_finder_p = new sc_event_finder_t<in_if_type>( *this, &in_if_type::value_changed_event ); } return *m_change_finder_p; } // called when elaboration is done /* WHEN DEFINING THIS METHOD IN A DERIVED CLASS, */ /* MAKE SURE THAT THIS METHOD IS CALLED AS WELL. */ virtual void end_of_elaboration(); virtual const char* kind() const { return "sc_in"; } void add_trace( sc_trace_file*, const std::string& ) const; // called by sc_trace void add_trace_internal( sc_trace_file*, const std::string& ) const;protected: void remove_traces() const; mutable sc_trace_params_vec* m_traces;protected: // called by pbind (for internal use only) virtual int vbind( sc_interface& ); virtual int vbind( sc_port_base& );private: mutable sc_event_finder* m_change_finder_p;private: // disabled sc_in( const this_type& ); this_type& operator = ( const this_type& );#ifdef __GNUC__ // Needed to circumvent a problem in the g++-2.95.2 compiler: // This unused variable forces the compiler to instantiate // an object of T template so an implicit conversion from // read() to a C++ intrinsic data type will work. static data_type dummy;#endif};template<typename T>::std::ostream& operator << ( ::std::ostream& os, const sc_in<T>& a ){ return os << a->read();}// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII// called when elaboration is donetemplate <class T>inlinevoidsc_in<T>::end_of_elaboration(){ if( m_traces != 0 ) { for( int i = 0; i < (int)m_traces->size(); ++ i ) { sc_trace_params* p = (*m_traces)[i]; in_if_type* iface = DCAST<in_if_type*>( this->get_interface() ); sc_trace( p->tf, iface->read(), p->name ); } remove_traces(); }}// called by sc_tracetemplate <class T>inlinevoidsc_in<T>::add_trace_internal( sc_trace_file* tf_, const std::string& name_ ) const{ if( tf_ != 0 ) { if( m_traces == 0 ) { m_traces = new sc_trace_params_vec; } m_traces->push_back( new sc_trace_params( tf_, name_ ) ); }}template <class T>inlinevoidsc_in<T>::add_trace( sc_trace_file* tf_, const std::string& name_ ) const{ sc_deprecated_add_trace(); add_trace_internal(tf_, name_);}template <class T>inlinevoidsc_in<T>::remove_traces() const{ if( m_traces != 0 ) { for( int i = (int)m_traces->size() - 1; i >= 0; -- i ) { delete (*m_traces)[i]; } delete m_traces; m_traces = 0; }}// called by pbind (for internal use only)template <class T>inlineintsc_in<T>::vbind( sc_interface& interface_ ){ return sc_port_b<if_type>::vbind( interface_ );}template <class T>inlineintsc_in<T>::vbind( sc_port_base& parent_ ){ in_port_type* in_parent = DCAST<in_port_type*>( &parent_ ); if( in_parent != 0 ) { sc_port_base::bind( *in_parent ); return 0; } inout_port_type* inout_parent = DCAST<inout_port_type*>( &parent_ ); if( inout_parent != 0 ) { sc_port_base::bind( *inout_parent ); return 0; } // type mismatch return 2;}// ----------------------------------------------------------------------------// CLASS : sc_in<bool>//// Specialization of sc_in<T> for type bool.// ----------------------------------------------------------------------------template <>class sc_in<bool> : public sc_port<sc_signal_in_if<bool>,1,SC_ONE_OR_MORE_BOUND>{public: // typedefs typedef bool data_type; typedef sc_signal_in_if<data_type> if_type; typedef sc_port<if_type,1,SC_ONE_OR_MORE_BOUND> base_type; typedef sc_in<data_type> this_type; typedef if_type in_if_type; typedef base_type in_port_type; typedef sc_signal_inout_if<data_type> inout_if_type; typedef sc_port<inout_if_type,1,SC_ONE_OR_MORE_BOUND> inout_port_type;public: // constructors sc_in() : base_type(), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} explicit sc_in( const char* name_ ) : base_type( name_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} explicit sc_in( const in_if_type& interface_ ) : base_type( CCAST<in_if_type&>( interface_ ) ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} sc_in( const char* name_, const in_if_type& interface_ ) : base_type( name_, CCAST<in_if_type&>( interface_ ) ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} explicit sc_in( in_port_type& parent_ ) : base_type( parent_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} sc_in( const char* name_, in_port_type& parent_ ) : base_type( name_, parent_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} explicit sc_in( inout_port_type& parent_ ) : base_type(), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) { sc_port_base::bind( parent_ ); } sc_in( const char* name_, inout_port_type& parent_ ) : base_type( name_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) { sc_port_base::bind( parent_ ); } sc_in( this_type& parent_ ) : base_type( parent_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {}#if defined(TESTING) sc_in( const this_type& parent_ ) : base_type( *(in_if_type*)parent_.get_interface() ) , m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {}#endif sc_in( const char* name_, this_type& parent_ ) : base_type( name_, parent_ ), m_traces( 0 ), m_change_finder_p(0), m_neg_finder_p(0), m_pos_finder_p(0) {} // destructor virtual ~sc_in() { remove_traces(); if ( m_change_finder_p ) delete m_change_finder_p; if ( m_neg_finder_p ) delete m_neg_finder_p; if ( m_pos_finder_p ) delete m_pos_finder_p; } // bind to in interface void bind( const in_if_type& interface_ ) { sc_port_base::bind( CCAST<in_if_type&>( interface_ ) ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -