sc_port.cpp
来自「基于4个mips核的noc设计」· C++ 代码 · 共 701 行 · 第 1/2 页
CPP
701 行
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2002 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.3 (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_port.cpp -- Base classes of all port classes. Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: *****************************************************************************/#include "systemc/kernel/sc_lambda.h"#include "systemc/kernel/sc_process_int.h"#include "systemc/kernel/sc_simcontext.h"#include "systemc/communication/sc_communication_ids.h"#include "systemc/communication/sc_event_finder.h"#include "systemc/communication/sc_port.h"#include "systemc/communication/sc_signal_ifs.h"// ----------------------------------------------------------------------------// STRUCT : sc_bind_elem// ----------------------------------------------------------------------------struct sc_bind_elem{ // constructors sc_bind_elem(); explicit sc_bind_elem( sc_interface* interface_ ); explicit sc_bind_elem( sc_port_base* parent_ ); sc_interface* iface; sc_port_base* parent;};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII// constructorssc_bind_elem::sc_bind_elem(): iface( 0 ), parent( 0 ){}sc_bind_elem::sc_bind_elem( sc_interface* interface_ ): iface( interface_ ), parent( 0 ){}sc_bind_elem::sc_bind_elem( sc_port_base* parent_ ): iface( 0 ), parent( parent_ ){}// ----------------------------------------------------------------------------// STRUCT : sc_bind_ef// ----------------------------------------------------------------------------struct sc_bind_ef{ // constructor sc_bind_ef( sc_process_b* , sc_event_finder* ); // destructor ~sc_bind_ef(); sc_process_b* handle; sc_event_finder* event_finder;};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII// constructorsc_bind_ef::sc_bind_ef( sc_process_b* handle_, sc_event_finder* event_finder_ ): handle( handle_ ), event_finder( event_finder_ ){}// destructorsc_bind_ef::~sc_bind_ef(){ if( event_finder != 0 ) { delete event_finder; }}// ----------------------------------------------------------------------------// STRUCT : sc_bind_info// ----------------------------------------------------------------------------struct sc_bind_info{ // constructor explicit sc_bind_info( int max_size_ ); // destructor ~sc_bind_info(); int size() const; int max_size; sc_pvector<sc_bind_elem*> vec; bool has_parent; int last_add; bool is_leaf; bool complete; sc_pvector<sc_bind_ef*> thread_vec; sc_pvector<sc_bind_ef*> method_vec;};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII// constructorsc_bind_info::sc_bind_info( int max_size_ ): max_size( max_size_ ), has_parent( false ), last_add( -1 ), is_leaf( true ), complete( false ){}// destructorsc_bind_info::~sc_bind_info(){ for( int i = size() - 1; i >= 0; -- i ) { delete vec[i]; }}intsc_bind_info::size() const{ return vec.size();}// ----------------------------------------------------------------------------// CLASS : sc_port_base//// Abstract base class for class sc_port_b.// ----------------------------------------------------------------------------const char* const sc_port_base::kind_string = "sc_port_base";// error reportingvoidsc_port_base::report_error( int id, const char* add_msg ) const{ char msg[BUFSIZ]; if( add_msg != 0 ) { sprintf( msg, "%s: port '%s' (%s)", add_msg, name(), kind() ); } else { sprintf( msg, "port '%s' (%s)", name(), kind() ); } SC_REPORT_ERROR( id, msg );}// constructorssc_port_base::sc_port_base( int max_size_ ): sc_object( sc_gen_unique_name( "port" ) ), m_bind_info( new sc_bind_info( max_size_ ) ){ simcontext()->get_port_registry()->insert( this );}sc_port_base::sc_port_base( const char* name_, int max_size_ ): sc_object( name_ ), m_bind_info( new sc_bind_info( max_size_ ) ){ simcontext()->get_port_registry()->insert( this );}// destructorsc_port_base::~sc_port_base(){ simcontext()->get_port_registry()->remove( this ); if( m_bind_info != 0 ) { delete m_bind_info; }}// bind interface to this portvoidsc_port_base::bind( sc_interface& interface_ ){ if( m_bind_info == 0 ) { // cannot bind an interface after elaboration report_error( SC_ID_BIND_IF_TO_PORT_, "simulation running" ); } if( m_bind_info->size() == m_bind_info->max_size && m_bind_info->max_size > 0 ) { report_error( SC_ID_BIND_IF_TO_PORT_, "maximum reached" ); } // check if interface is already bound to this port for( int i = m_bind_info->size() - 1; i >= 0; -- i ) { if( &interface_ == m_bind_info->vec[i]->iface ) { report_error( SC_ID_BIND_IF_TO_PORT_, "already bound" ); } } m_bind_info->vec.push_back( new sc_bind_elem( &interface_ ) ); if( ! m_bind_info->has_parent ) { // add (cache) the interface add_interface( &interface_ ); m_bind_info->last_add ++; }}// bind parent port to this portvoidsc_port_base::bind( this_type& 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() == m_bind_info->max_size && m_bind_info->max_size > 0 ) { report_error( SC_ID_BIND_PORT_TO_PORT_, "maximum reached" ); } if( &parent_ == this ) { report_error( SC_ID_BIND_PORT_TO_PORT_, "same port" ); } // check if parent port is already bound to this port for( int i = m_bind_info->size() - 1; i >= 0; -- i ) { if( &parent_ == m_bind_info->vec[i]->parent ) { report_error( SC_ID_BIND_PORT_TO_PORT_, "already bound" ); } } m_bind_info->vec.push_back( new sc_bind_elem( &parent_ ) ); m_bind_info->has_parent = true; parent_.m_bind_info->is_leaf = false;}// called by elaboration_done (does nothing)voidsc_port_base::end_of_elaboration(){}// called by class sc_module for positional bindingintsc_port_base::pbind( sc_interface& interface_ ){ if( m_bind_info == 0 ) { // cannot bind an interface after elaboration report_error( SC_ID_BIND_IF_TO_PORT_, "simulation running" ); } 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( 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( handle_, event_finder_ ) );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?