📄 sc_port.cpp
字号:
if( m_bind_info->size() != 0 ) { // first interface already bound return 1; } return vbind( interface_ );}intsc_port_base::pbind( sc_port_base& parent_ ){ if( m_bind_info == 0 ) { // cannot bind a parent port after elaboration report_error( SC_ID_BIND_PORT_TO_PORT_, "simulation running" ); } if( m_bind_info->size() != 0 ) { // first interface already bound return 1; } return vbind( parent_ );}// called by the sc_sensitive* classesvoidsc_port_base::make_sensitive( sc_thread_handle handle_, sc_event_finder* event_finder_ ) const{ assert( m_bind_info != 0 ); m_bind_info->thread_vec.push_back( new sc_bind_ef( (sc_process_b*)handle_, event_finder_ ) );}voidsc_port_base::make_sensitive( sc_method_handle handle_, sc_event_finder* event_finder_ ) const{ assert( m_bind_info != 0 ); m_bind_info->method_vec.push_back( new sc_bind_ef( (sc_process_b*)handle_, event_finder_ ) );}// support methodsintsc_port_base::first_parent(){ for( int i = 0; i < m_bind_info->size(); ++ i ) { if( m_bind_info->vec[i]->parent != 0 ) { return i; } } return -1;}voidsc_port_base::insert_parent( int i ){ std::vector<sc_bind_elem*>& vec = m_bind_info->vec; this_type* parent = vec[i]->parent; // IF OUR PARENT HAS NO BINDING THEN IGNORE IT: // // Note that the zeroing of the parent pointer must occur before this // test vec[i]->parent = 0; if ( parent->m_bind_info->vec.size() == 0 ) return; vec[i]->iface = parent->m_bind_info->vec[0]->iface; int n = parent->m_bind_info->size() - 1; if( n > 0 ) { // resize the bind vector (by adding new elements) for( int k = 0; k < n; ++ k ) { vec.push_back( new sc_bind_elem() ); } // move elements in the bind vector for( int k = m_bind_info->size() - n - 1; k > i; -- k ) { vec[k + n]->iface = vec[k]->iface; vec[k + n]->parent = vec[k]->parent; } // insert parent interfaces into the bind vector for( int k = i + 1; k <= i + n; ++ k ) { vec[k]->iface = parent->m_bind_info->vec[k - i]->iface; vec[k]->parent = 0; } }}// called when elaboration is donevoidsc_port_base::complete_binding(){ char msg_buffer[128]; // For error message construction. // IF BINDING HAS ALREADY BEEN COMPLETED IGNORE THIS CALL: assert( m_bind_info != 0 ); if( m_bind_info->complete ) { return; } // COMPLETE BINDING OF OUR PARENT PORTS SO THAT WE CAN USE THAT INFORMATION: int i = first_parent(); while( i >= 0 ) { m_bind_info->vec[i]->parent->complete_binding(); insert_parent( i ); i = first_parent(); } // LOOP OVER BINDING INFORMATION TO COMPLETE THE BINDING PROCESS: int size; for( int j = 0; j < m_bind_info->size(); ++ j ) { sc_interface* iface = m_bind_info->vec[j]->iface; // if the interface is zero this was for an unbound port. if ( iface == 0 ) continue; // add (cache) the interface if( j > m_bind_info->last_add ) { add_interface( iface ); } // only register "leaf" ports (ports without children) if( m_bind_info->is_leaf ) { iface->register_port( *this, if_typename() ); } // complete static sensitivity for methods size = m_bind_info->method_vec.size(); for( int k = 0; k < size; ++ k ) { sc_bind_ef* p = m_bind_info->method_vec[k]; const sc_event& event = ( p->event_finder != 0 ) ? p->event_finder->find_event(iface) : iface->default_event(); p->handle->add_static_event( event ); } // complete static sensitivity for threads size = m_bind_info->thread_vec.size(); for( int k = 0; k < size; ++ k ) { sc_bind_ef* p = m_bind_info->thread_vec[k]; const sc_event& event = ( p->event_finder != 0 ) ? p->event_finder->find_event(iface) : iface->default_event(); p->handle->add_static_event( event ); } } // MAKE SURE THE PROPER NUMBER OF BINDINGS OCCURRED: // // Make sure there are enough bindings, and not too many. int actual_binds = interface_count(); if ( actual_binds > m_bind_info->max_size() ) { sprintf(msg_buffer, "%d binds exceeds maximum of %d allowed", actual_binds, m_bind_info->max_size() ); report_error( SC_ID_COMPLETE_BINDING_, msg_buffer ); } switch ( m_bind_info->policy() ) { case SC_ONE_OR_MORE_BOUND: if ( actual_binds < 1 ) { report_error( SC_ID_COMPLETE_BINDING_, "port not bound" ); } break; case SC_ALL_BOUND: if ( actual_binds < m_bind_info->max_size() || actual_binds < 1 ) { sprintf(msg_buffer, "%d actual binds is less than required %d", actual_binds, m_bind_info->max_size() ); report_error( SC_ID_COMPLETE_BINDING_, msg_buffer ); } break; default: // SC_ZERO_OR_MORE_BOUND: break; } // CLEAN UP: FREE BINDING STORAGE: size = m_bind_info->method_vec.size(); for( int k = 0; k < size; ++ k ) { delete m_bind_info->method_vec[k]; } m_bind_info->method_vec.resize(0); size = m_bind_info->thread_vec.size(); for( int k = 0; k < size; ++ k ) { delete m_bind_info->thread_vec[k]; } m_bind_info->thread_vec.resize(0); m_bind_info->complete = true;}voidsc_port_base::construction_done(){ before_end_of_elaboration();}voidsc_port_base::elaboration_done(){ assert( m_bind_info != 0 && m_bind_info->complete ); delete m_bind_info; m_bind_info = 0; end_of_elaboration();}voidsc_port_base::start_simulation(){ start_of_simulation();}voidsc_port_base::simulation_done(){ end_of_simulation();}// ----------------------------------------------------------------------------// CLASS : sc_port_registry//// Registry for all ports.// FOR INTERNAL USE ONLY!// ----------------------------------------------------------------------------voidsc_port_registry::insert( sc_port_base* port_ ){ if( sc_is_running() ) { port_->report_error( SC_ID_INSERT_PORT_, "simulation running" ); }#if defined(DEBUG_SYSTEMC) // check if port_ is already inserted for( int i = size() - 1; i >= 0; -- i ) { if( port_ == m_port_vec[i] ) { port_->report_error( SC_ID_INSERT_PORT_, "port already inserted" ); } }#endif // append the port to the current module's vector of ports sc_module* curr_module = m_simc->hierarchy_curr(); if( curr_module == 0 ) { port_->report_error( SC_ID_PORT_OUTSIDE_MODULE_ ); } curr_module->append_port( port_ ); // insert m_port_vec.push_back( port_ );}voidsc_port_registry::remove( sc_port_base* port_ ){ int i; for( i = size() - 1; i >= 0; -- i ) { if( port_ == m_port_vec[i] ) { break; } } if( i == -1 ) { port_->report_error( SC_ID_REMOVE_PORT_, "port not registered" ); } // remove m_port_vec[i] = m_port_vec[size() - 1]; m_port_vec.resize(size()-1);}// constructorsc_port_registry::sc_port_registry( sc_simcontext& simc_ ): m_simc( &simc_ ){}// destructorsc_port_registry::~sc_port_registry(){}// called when construction is donevoidsc_port_registry::construction_done(){ for( int i = size() - 1; i >= 0; -- i ) { m_port_vec[i]->construction_done(); }}// called when when elaboration is donevoidsc_port_registry::complete_binding(){ for( int i = size() - 1; i >= 0; -- i ) { m_port_vec[i]->complete_binding(); }}// called when elaboration is donevoidsc_port_registry::elaboration_done(){ complete_binding(); for( int i = size() - 1; i >= 0; -- i ) { m_port_vec[i]->elaboration_done(); }}// called before simulation beginsvoidsc_port_registry::start_simulation(){ for( int i = size() - 1; i >= 0; -- i ) { m_port_vec[i]->start_simulation(); }}// called after simulation endsvoidsc_port_registry::simulation_done(){ for( int i = size() - 1; i >= 0; -- i ) { m_port_vec[i]->simulation_done(); }}// This is a static member function.voidsc_port_registry::replace_port( sc_port_registry* registry ){}void sc_warn_port_constructor(){ static bool warn_port_constructor=true; if ( warn_port_constructor ) { warn_port_constructor = false; SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_, "interface and/or port binding in port constructors is deprecated" ); }}} // namespace sc_core// Taf!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -