sc_module.cpp

来自「基于4个mips核的noc设计」· C++ 代码 · 共 584 行 · 第 1/2 页

CPP
584
字号
/*****************************************************************************  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_module.cpp -- Base class of all sequential and combinational processes.  Original Author: Stan Y. Liao, Synopsys, Inc. *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.  Description of Modification: - Implementation of operator() and operator,                                 positional connection method.                               - Implementation of error checking in                                 operator<<'s.                               - Implementation of the function test_module_prm.                               - Implementation of set_stack_size().      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/#include <assert.h>#include <math.h>#include <stdio.h>#include "systemc/kernel/sc_event.h"#include "systemc/kernel/sc_kernel_ids.h"#include "systemc/kernel/sc_macros_int.h"#include "systemc/kernel/sc_module.h"#include "systemc/kernel/sc_module_registry.h"#include "systemc/kernel/sc_name_gen.h"#include "systemc/kernel/sc_object_manager.h"#include "systemc/kernel/sc_process.h"#include "systemc/kernel/sc_process_int.h"#include "systemc/kernel/sc_simcontext.h"#include "systemc/kernel/sc_simcontext_int.h"#include "systemc/communication/sc_communication_ids.h"#include "systemc/communication/sc_interface.h"#include "systemc/communication/sc_port.h"#include "systemc/utils/sc_iostream.h"// ----------------------------------------------------------------------------//  CLASS : sc_module_dynalloc_list////  Garbage collection for modules dynamically allocated with SC_NEW.// ----------------------------------------------------------------------------class sc_module_dynalloc_list{public:    sc_module_dynalloc_list()        {}    ~sc_module_dynalloc_list();    void add( sc_module* p )        { m_list.push_back( p ); }private:    sc_plist<sc_module*> m_list;};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIsc_module_dynalloc_list::~sc_module_dynalloc_list(){    sc_plist<sc_module*>::iterator it( m_list );    while( ! it.empty() ) {        delete *it;        it ++;    }}// ----------------------------------------------------------------------------sc_module*sc_module_dynalloc( sc_module* module_ ){    static sc_module_dynalloc_list dynalloc_list;    dynalloc_list.add( module_ );    return module_;}// ----------------------------------------------------------------------------//  STRUCT : sc_bind_proxy////  Struct for temporarily storing a pointer to an interface or port.//  Used for positional binding.// ----------------------------------------------------------------------------    sc_bind_proxy::sc_bind_proxy(): iface( 0 ),  port( 0 ){}sc_bind_proxy::sc_bind_proxy( sc_interface& iface_ ): iface( &iface_ ),  port( 0 ){}sc_bind_proxy::sc_bind_proxy( sc_port_base& port_ ): iface( 0 ),  port( &port_ ){}const sc_bind_proxy SC_BIND_PROXY_NIL;// ----------------------------------------------------------------------------//  CLASS : sc_module////  Base class for all structural entities.// ----------------------------------------------------------------------------const char* const sc_module::kind_string = "sc_module";voidsc_module::sc_module_init(){    simcontext()->hierarchy_push( this );    m_end_module_called = false;    m_port_vec = new sc_pvector<sc_port_base*>( 16 );    m_port_index = 0;    m_name_gen = new sc_name_gen;    simcontext()->get_module_registry()->insert( *this );}sc_module::sc_module( const char* nm ): sc_object(nm),  sensitive(this),  sensitive_pos(this),  sensitive_neg(this){    sc_module_init();}/* *  This form of the constructor assumes that the user has *  used an sc_module_name parameter for his/her constructor. *  That parameter object has been pushed onto the stack, *  and can be looked up by calling the  *  top_of_module_name_stack() function of the object manager. *  This technique has two advantages: * *  1) The user no longer has to write sc_module(name) in the *     constructor initializer. *  2) The user no longer has to call end_module() at the end *     of the constructor -- a common negligence. * *  But it is important to note that sc_module_name may be used *  in the user's constructor's parameter. If it is used anywhere *  else, unexpected things will happen. The error-checking *  mechanism builtin here cannot hope to catch all misuses. * */sc_module::sc_module(): sc_object(::sc_get_curr_simcontext()            ->get_object_manager()            ->top_of_module_name_stack()            ->operator const char*()),  sensitive(this),  sensitive_pos(this),  sensitive_neg(this){    /* When this form is used, we better have a fresh sc_module_name       on the top of the stack */    sc_module_name* mod_name =         simcontext()->get_object_manager()->top_of_module_name_stack();    if (0 == mod_name || 0 != mod_name->m_module)        SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_REQUIRED_, 0 );    mod_name->m_module = this;    sc_module_init();}sc_module::sc_module( const sc_module_name& ): sc_object(::sc_get_curr_simcontext()            ->get_object_manager()            ->top_of_module_name_stack()            ->operator const char*()),  sensitive(this),  sensitive_pos(this),  sensitive_neg(this){    /* For those used to the old style of passing a name to sc_module,       this constructor will reduce the chance of making a mistake */    /* When this form is used, we better have a fresh sc_module_name       on the top of the stack */    sc_module_name* mod_name =         simcontext()->get_object_manager()->top_of_module_name_stack();    if (0 == mod_name || 0 != mod_name->m_module)      SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_REQUIRED_, 0 );    mod_name->m_module = this;    sc_module_init();}sc_module::sc_module( const sc_string& s ): sc_object( s.c_str() ),  sensitive(this),  sensitive_pos(this),  sensitive_neg(this){    sc_module_init();}sc_module::~sc_module(){    delete m_port_vec;    delete m_name_gen;    simcontext()->get_module_registry()->remove( *this );}const sc_pvector<sc_object*>&sc_module::get_child_objects() const{    return m_child_objects;}voidsc_module::add_child_object( sc_object* object_ ){    // no check if object_ is already in the set    m_child_objects.push_back( object_ );}voidsc_module::remove_child_object( sc_object* object_ ){    int size = m_child_objects.size();    for( int i = 0; i < size; ++ i ) {	if( object_ == m_child_objects[i] ) {	    m_child_objects[i] = m_child_objects[size - 1];	    m_child_objects.decr_count();	    return;	}    }    // no check if object_ is really in the set}voidsc_module::end_module(){    if( ! m_end_module_called ) {	/* TBD: Can check here to alert the user that end_module                was not called for a previous module. */	(void) simcontext()->hierarchy_pop();	simcontext()->reset_curr_proc(); 	m_end_module_called = true;    }}// to prevent initialization for SC_METHODs and SC_THREADsvoidsc_module::dont_initialize(){    sc_curr_proc_handle cpi = simcontext()->get_curr_proc_info();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?