⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_simcontext.cpp

📁 system C源码 一种替代verilog的语言
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************  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_simcontext.cpp -- Provides a simulation context for use with multiple                       simulations.  Original Author: Stan Y. Liao, Synopsys, Inc.                   Martin Janssen, 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: - Added sc_stop() detection into initial_crunch                                 and crunch. This makes it possible to exit out                                 of a combinational loop using sc_stop().      Name, Affiliation, Date: Andy Goodrich, Forte Design Systems 20 May 2003  Description of Modification: - sc_stop mode                               - phase callbacks      Name, Affiliation, Date: Bishnupriya Bhattacharya, Cadence Design Systems,                               25 August 2003  Description of Modification: - support for dynamic process                               - support for sc export registry                               - new member methods elaborate(), 				 prepare_to_simulate(), and initial_crunch()				 that are invoked by initialize() in that order                               - implement sc_get_last_created_process_handle() for use                                 before simulation starts                               - remove "set_curr_proc(handle)" from                                  register_method_process and                                  register_thread_process - led to bugs                                     Name, Affiliation, Date: Andy Goodrich, Forte Design Systems 04 Sep 2003  Description of Modification: - changed process existence structures to				 linked lists to eliminate exponential 				 execution problem with using sc_pvector. *****************************************************************************/// $Log: sc_simcontext.cpp,v $// Revision 1.1.1.1  2006/12/15 20:31:37  acg// SystemC 2.2//// Revision 1.17  2006/04/11 23:13:21  acg//   Andy Goodrich: Changes for reduced reset support that only includes//   sc_cthread, but has preliminary hooks for expanding to method and thread//   processes also.//// Revision 1.16  2006/03/21 00:00:34  acg//   Andy Goodrich: changed name of sc_get_current_process_base() to be//   sc_get_current_process_b() since its returning an sc_process_b instance.//// Revision 1.15  2006/03/13 20:26:50  acg//  Andy Goodrich: Addition of forward class declarations, e.g.,//  sc_reset, to keep gcc 4.x happy.//// Revision 1.14  2006/02/02 23:42:41  acg//  Andy Goodrich: implemented a much better fix to the sc_event_finder//  proliferation problem. This new version allocates only a single event//  finder for each port for each type of event, e.g., pos(), neg(), and//  value_change(). The event finder persists as long as the port does,//  which is what the LRM dictates. Because only a single instance is//  allocated for each event type per port there is not a potential//  explosion of storage as was true in the 2.0.1/2.1 versions.//// Revision 1.13  2006/02/02 21:29:10  acg//  Andy Goodrich: removed the call to sc_event_finder::free_instances() that//  was in end_of_elaboration(), leaving only the call in clean(). This is//  because the LRM states that sc_event_finder instances are persistent as//  long as the sc_module hierarchy is valid.//// Revision 1.12  2006/02/02 21:09:50  acg//  Andy Goodrich: added call to sc_event_finder::free_instances in the clean()//  method.//// Revision 1.11  2006/02/02 20:43:14  acg//  Andy Goodrich: Added an existence linked list to sc_event_finder so that//  the dynamically allocated instances can be freed after port binding//  completes. This replaces the individual deletions in ~sc_bind_ef, as these//  caused an exception if an sc_event_finder instance was used more than//  once, due to a double freeing of the instance.//// Revision 1.10  2006/01/31 21:43:26  acg//  Andy Goodrich: added comments in constructor to highlight environmental//  overrides section.//// Revision 1.9  2006/01/26 21:04:54  acg//  Andy Goodrich: deprecation message changes and additional messages.//// Revision 1.8  2006/01/25 00:31:19  acg//  Andy Goodrich: Changed over to use a standard message id of//  SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.//// Revision 1.7  2006/01/24 20:49:05  acg// Andy Goodrich: changes to remove the use of deprecated features within the// simulator, and to issue warning messages when deprecated features are used.//// Revision 1.6  2006/01/19 00:29:52  acg// Andy Goodrich: Yet another implementation for signal write checking. This// one uses an environment variable SC_SIGNAL_WRITE_CHECK, that when set to// DISABLE will disable write checking on signals.//// Revision 1.5  2006/01/13 18:44:30  acg// Added $Log to record CVS changes into the source.//// Revision 1.4  2006/01/03 23:18:44  acg// Changed copyright to include 2006.//// Revision 1.3  2005/12/20 22:11:10  acg// Fixed $Log lines.//// Revision 1.2  2005/12/20 22:02:30  acg// Changed where delta cycles are incremented to match IEEE 1666. Added the// event_occurred() method to hide how delta cycle comparisions are done within// sc_simcontext. Changed the boolean update_phase to an enum that shows all// the phases.#include "sysc/kernel/sc_cor_fiber.h"#include "sysc/kernel/sc_cor_pthread.h"#include "sysc/kernel/sc_cor_qt.h"#include "sysc/kernel/sc_event.h"#include "sysc/kernel/sc_kernel_ids.h"#include "sysc/kernel/sc_macros_int.h"#include "sysc/kernel/sc_module.h"#include "sysc/kernel/sc_module_registry.h"#include "sysc/kernel/sc_name_gen.h"#include "sysc/kernel/sc_object_manager.h"#include "sysc/kernel/sc_cthread_process.h"#include "sysc/kernel/sc_method_process.h"#include "sysc/kernel/sc_thread_process.h"#include "sysc/kernel/sc_process_handle.h"#include "sysc/kernel/sc_simcontext.h"#include "sysc/kernel/sc_simcontext_int.h"#include "sysc/kernel/sc_reset.h"#include "sysc/kernel/sc_ver.h"#include "sysc/communication/sc_port.h"#include "sysc/communication/sc_export.h"#include "sysc/communication/sc_prim_channel.h"#include "sysc/tracing/sc_trace.h"#include "sysc/utils/sc_mempool.h"#include "sysc/utils/sc_utils_ids.h"namespace sc_core {sc_stop_mode stop_mode = SC_STOP_FINISH_DELTA;// ----------------------------------------------------------------------------//  CLASS : sc_process_table////  Container class that keeps track of all method processes,//  thread processes, and cthread processes.// ----------------------------------------------------------------------------class sc_process_table{  public:    sc_process_table();    ~sc_process_table();    void push_front( sc_method_handle );    void push_front( sc_thread_handle );    void push_front( sc_cthread_handle );    sc_cthread_handle cthread_q_head();    sc_method_handle method_q_head();    sc_cthread_handle remove( sc_cthread_handle );    sc_method_handle remove( sc_method_handle );    sc_thread_handle remove( sc_thread_handle );    sc_thread_handle thread_q_head();  private:    sc_cthread_handle m_cthread_q; // Queue of existing cthread processes.    sc_method_handle  m_method_q;  // Queue of existing method processes.    sc_thread_handle  m_thread_q;  // Queue of existing thread processes.};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIsc_process_table::sc_process_table() :    m_cthread_q(0), m_method_q(0), m_thread_q(0){}sc_process_table::~sc_process_table(){    sc_method_handle  method_next_p;	// Next method to delete.    sc_method_handle  method_now_p;	// Method now deleting.    for( method_now_p = m_method_q; method_now_p; method_now_p = method_next_p )    {	method_next_p = method_now_p->next_exist();	delete method_now_p;    }    if ( m_thread_q || m_cthread_q )    {        ::std::cout << ::std::endl              << "WATCH OUT!! In sc_process_table destructor. "             << "Threads and cthreads are not actually getting deleted here. "	     << "Some memory may leak. Look at the comments here in "	     << "kernel/sc_simcontext.cpp for more details."	     << ::std::endl;    }    // don't delete threads and cthreads. If a (c)thread    // has died, then it has already been deleted. Only (c)threads created    // before simulation-start are in this table. Due to performance    // reasons, we don't look up the dying thread in the process table    // and remove it from there. simcontext::reset and ~simcontext invoke this    // destructor. At present none of these routines are ever invoked.     // We can delete threads and cthreads here if a dying thread figured out    // it was created before simulation-start and took itself off the     // process_table. #if 0    sc_cthread_handle cthread_next_p;	// Next cthread to delete.    sc_cthread_handle cthread_now_p;	// Cthread now deleting.    sc_thread_handle  thread_next_p;	// Next thread to delete.    sc_thread_handle  thread_now_p;	// Thread now deleting.    for(cthread_now_p=m_cthread_q; cthread_now_p; cthread_now_p=cthread_next_p)    {	cthread_next_p = cthread_now_p->next_exist();	delete cthread_now_p;    }    for( thread_now_p=m_thread_q; thread_now_p; thread_now_p=thread_next_p )    {	thread_next_p = thread_now_p->next_exist();	delete thread_now_p;    }#endif // 0}inlinesc_cthread_handle sc_process_table::cthread_q_head(){    return m_cthread_q;}inlinesc_method_handle sc_process_table::method_q_head(){    return m_method_q;}inlinevoidsc_process_table::push_front( sc_method_handle handle_ ){    handle_->set_next_exist(m_method_q);    m_method_q = handle_;}inlinevoidsc_process_table::push_front( sc_thread_handle handle_ ){    handle_->set_next_exist(m_thread_q);    m_thread_q = handle_;}inlinevoidsc_process_table::push_front( sc_cthread_handle handle_ ){    handle_->set_next_exist(m_cthread_q);    m_cthread_q = handle_;}sc_cthread_handlesc_process_table::remove( sc_cthread_handle handle_ ){    sc_cthread_handle now_p;	// Entry now examining.    sc_cthread_handle prior_p;	// Entry prior to one now examining.    prior_p = 0;    for ( now_p = m_cthread_q; now_p; now_p = now_p->next_exist() )    {	if ( now_p == handle_ )	{	    if ( prior_p )		prior_p->set_next_exist( now_p->next_exist() );	    else		m_cthread_q = now_p->next_exist();	    return handle_;	}    }    return 0;}sc_method_handlesc_process_table::remove( sc_method_handle handle_ ){    sc_method_handle now_p;	// Entry now examining.    sc_method_handle prior_p;	// Entry prior to one now examining.    prior_p = 0;    for ( now_p = m_method_q; now_p; now_p = now_p->next_exist() )    {	if ( now_p == handle_ )	{	    if ( prior_p )		prior_p->set_next_exist( now_p->next_exist() );	    else		m_method_q = now_p->next_exist();	    return handle_;	}    }    return 0;}sc_thread_handlesc_process_table::remove( sc_thread_handle handle_ ){    sc_thread_handle now_p;	// Entry now examining.    sc_thread_handle prior_p;	// Entry prior to one now examining.    prior_p = 0;    for ( now_p = m_thread_q; now_p; now_p = now_p->next_exist() )    {	if ( now_p == handle_ )	{	    if ( prior_p )		prior_p->set_next_exist( now_p->next_exist() );	    else		m_thread_q = now_p->next_exist();	    return handle_;	}    }    return 0;}inlinesc_thread_handle sc_process_table::thread_q_head(){    return m_thread_q;}// ----------------------------------------------------------------------------voidpln(){    static bool lnp = false;    if( ! lnp ) {        ::std::cerr << ::std::endl;	::std::cerr << sc_version() << ::std::endl;	::std::cerr << sc_copyright() << ::std::endl;	//  regressions check point        if( getenv( "SYSTEMC_REGRESSION" ) != 0 ) {            ::std::cerr << "SystemC Simulation" << ::std::endl;        }        lnp = true;    }}intsc_notify_time_compare( const void* p1, const void* p2 ){    const sc_event_timed* et1 = static_cast<const sc_event_timed*>( p1 );    const sc_event_timed* et2 = static_cast<const sc_event_timed*>( p2 );    const sc_time& t1 = et1->notify_time();    const sc_time& t2 = et2->notify_time();        if( t1 < t2 ) {	return 1;    } else if( t1 > t2 ) {	return -1;    } else {	return 0;    }}// ----------------------------------------------------------------------------//  CLASS : sc_simcontext////  The simulation context.// ----------------------------------------------------------------------------voidsc_simcontext::init(){    // ALLOCATE VARIOUS MANAGERS AND REGISTRIES:    m_object_manager = new sc_object_manager;    m_module_registry = new sc_module_registry( *this );    m_port_registry = new sc_port_registry( *this );    m_export_registry = new sc_export_registry( *this );    m_prim_channel_registry = new sc_prim_channel_registry( *this );    m_name_gen = new sc_name_gen;    m_process_table = new sc_process_table;    m_current_writer = 0;    // CHECK FOR ENVIRONMENT VARIABLES THAT MODIFY SIMULATOR EXECUTION:    const char* write_check = std::getenv("SC_SIGNAL_WRITE_CHECK");    m_write_check = ( (write_check==0) || strcmp(write_check,"DISABLE") ) ?      true : false;    // FINISH INITIALIZATIONS:    reset_curr_proc();    m_next_proc_id = -1;    m_timed_events = new sc_ppq<sc_event_timed*>( 128, sc_notify_time_compare );    m_something_to_trace = false;    m_runnable = new sc_runnable;    m_time_params = new sc_time_params;    m_curr_time = SC_ZERO_TIME;    m_delta_count = 0;    m_forced_stop = false;    m_ready_to_simulate = false;    m_elaboration_done = false;    m_execution_phase = phase_initialize;    m_error = false;    m_until_event = 0;    m_cor_pkg = 0;    m_cor = 0;    m_in_simulator_control = false;    m_start_of_simulation_called = false;    m_end_of_simulation_called = false;}voidsc_simcontext::clean(){    delete m_object_manager;    delete m_module_registry;    delete m_port_registry;    delete m_export_registry;    delete m_prim_channel_registry;    delete m_name_gen;    delete m_process_table;    m_child_objects.resize(0);    m_delta_events.resize(0);    delete m_timed_events;    for( int i = m_trace_files.size() - 1; i >= 0; -- i ) {	delete m_trace_files[i];    }    m_trace_files.resize(0);    delete m_runnable;    delete m_time_params;    if( m_until_event != 0 ) {        delete m_until_event;    }    if( m_cor_pkg != 0 ) {	delete m_cor_pkg;    }}

⌨️ 快捷键说明

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