Пример #1
0
  void proc_tree( unsigned depth, unsigned width, bool as_method, bool spawn_only )
  {
    unsigned w = width;
    if (sc_time_stamp() == SC_ZERO_TIME || spawn_only )
      while( depth && w --> 0 )
    {
      sc_spawn_options sp;
      sp.set_sensitivity( &clk.pos() );

      if(as_method) // we are spawned as method, spawn a thread
      {
        sc_spawn( sc_bind( &top::proc_tree, this, depth-1, width, !as_method, false )
                , sc_gen_unique_name("thread"), &sp );
      }
      else // we are spawned as thread, spawn a method
      {
        sp.spawn_method();
        sc_spawn( sc_bind( &top::proc_tree, this, depth-1, width, !as_method, false )
                , sc_gen_unique_name("method"), &sp );
      }
    }

    if(spawn_only) return;

    std::cout << sc_get_current_process_handle().name()
              << " triggered "
                << "(" << sc_time_stamp() << " @ " << sc_delta_count() << ")"
              << std::endl;

    // start thread
    if( !as_method ) thread_loop();
  }
Пример #2
0
//------------------------------------------------------------------------------
//"sc_method_process::sc_method_process"
//
// This is the object instance constructor for this class.
//------------------------------------------------------------------------------
sc_method_process::sc_method_process( const char* name_p,
                                      bool free_host, SC_ENTRY_FUNC method_p,
                                      sc_process_host* host_p, const sc_spawn_options* opt_p
                                    ):
        sc_process_b(
            name_p && name_p[0] ? name_p : sc_gen_unique_name("method_p"),
            free_host, method_p, host_p, opt_p)
{

    // CHECK IF THIS IS AN sc_module-BASED PROCESS AND SIMUALTION HAS STARTED:

    if ( DCAST<sc_module*>(host_p) != 0 && sc_is_running() )
    {
        SC_REPORT_ERROR( SC_ID_MODULE_METHOD_AFTER_START_, "" );
    }

    // INITIALIZE VALUES:
    //
    // If there are spawn options use them.

    m_process_kind = SC_METHOD_PROC_;
    if (opt_p)
    {
        m_dont_init = opt_p->m_dont_initialize;

        // traverse event sensitivity list
        for (unsigned int i = 0; i < opt_p->m_sensitive_events.size(); i++)
        {
            sc_sensitive::make_static_sensitivity(
                this, *opt_p->m_sensitive_events[i]);
        }

        // traverse port base sensitivity list
        for ( unsigned int i = 0; i < opt_p->m_sensitive_port_bases.size(); i++)
        {
            sc_sensitive::make_static_sensitivity(
                this, *opt_p->m_sensitive_port_bases[i]);
        }

        // traverse interface sensitivity list
        for ( unsigned int i = 0; i < opt_p->m_sensitive_interfaces.size(); i++)
        {
            sc_sensitive::make_static_sensitivity(
                this, *opt_p->m_sensitive_interfaces[i]);
        }

        // traverse event finder sensitivity list
        for ( unsigned int i = 0; i < opt_p->m_sensitive_event_finders.size();
                i++)
        {
            sc_sensitive::make_static_sensitivity(
                this, *opt_p->m_sensitive_event_finders[i]);
        }
    }

    else
    {
        m_dont_init = false;
    }
}
Пример #3
0
 void abc()
 {
     for ( int i = 0; i < 3; i++ )
     {
         cout << "Time  Spawn Start Stop " << endl;
         cout << "----- ----- ----- ----" << endl;
         int              ii = 2;
         int              spawn_i;
         int              spawn_n = 8;
         sc_spawn_options options;
         sc_join          join;
         options.set_sensitivity(&m_clk.pos());
         for ( spawn_i = 0; spawn_i < spawn_n; spawn_i++ )
         {
             int process_i = spawn_i + i * spawn_n;
             cout << sc_time_stamp() << " " << process_i << endl;
             join.add_process(sc_spawn(
                                  sc_bind(&TB::process, this, sc_ref(process_i)),
                                  sc_gen_unique_name("pipe"), &options ) );
             sc_core::wait(ii);
         }
         cout << sc_time_stamp() << " waiting for termination of "
              << join.process_count() << " processes" << endl;
         join.wait();
         cout << sc_time_stamp() << " back from termination wait " << endl;
     }
 }
// +----------------------------------------------------------------------------
// |"sc_object_manager::create_name"
// | 
// | This method creates a hierarchical name based on the name of the active 
// | object and the supplied leaf name. If the resultant name is not unique it 
// | will be made unique and a warning message issued.
// |
// | Arguments:
// |     leaf_name = name to use for the leaf of the hierarchy.
// | Result is an std::string containing the name.
// +----------------------------------------------------------------------------
std::string sc_object_manager::create_name(const char* leaf_name) 
{ 
    bool        clash;                  // true if path name exists in obj table
    std::string leafname_string;        // string containing the leaf name.
    std::string parentname_string;      // parent path name 
    sc_object*  parent_p;               // parent for this instance or NULL.
    std::string result_orig_string;     // save for warning message.
    std::string result_string;          // name to return.
 
    // CONSTRUCT PATHNAME TO THE NAME TO BE RETURNED:
    // 
    // If there is not a leaf name generate one. 

    parent_p = sc_get_curr_simcontext()->active_object();
    parentname_string = parent_p ? parent_p->name() : ""; 
    leafname_string = leaf_name; 
    if (parent_p) {
        result_string = parentname_string;
	result_string += SC_HIERARCHY_CHAR;
	result_string += leafname_string;
    } else { 
        result_string = leafname_string;
    } 

    // SAVE the original path name 

    result_orig_string = result_string;

    // MAKE SURE THE ENTITY NAME IS UNIQUE:
    // 
    // If not use unique name generator to make it unique. 

    clash = false; 
    for (;;)
    {
	instance_table_t::iterator it = m_instance_table.find(result_string);
	if ( it == m_instance_table.end() ||
	     (it->second.m_event_p == NULL && it->second.m_object_p == NULL ) )
	{
	    break;
	}
        clash = true; 
        leafname_string = sc_gen_unique_name(leafname_string.c_str(), false); 
	if (parent_p) {
	    result_string = parentname_string;
	    result_string += SC_HIERARCHY_CHAR;
	    result_string += leafname_string;
	} else { 
	    result_string = leafname_string;
	} 
    } 
    if (clash) { 
	std::string message = result_orig_string;
	message += ". Latter declaration will be renamed to ";
	message += result_string;
        SC_REPORT_WARNING( SC_ID_INSTANCE_EXISTS_, message.c_str());
    } 

    return result_string;
}
Пример #5
0
/// Standard constructor.
ac_module::ac_module() : sc_module(sc_gen_unique_name("ac_module")),
			 mod_id(next_mod_id++),
			 ac_exit_status(0),
			 instr_in_batch(0),
			 instr_batch_size(500) {
  this_mod = mods_list.insert(mods_list.end(), this);
  return;
}
Пример #6
0
sc_port_base::sc_port_base(
    int max_size_, sc_port_policy policy
) :
        sc_object( sc_gen_unique_name( "port" ) ),
        m_bind_info( new sc_bind_info( max_size_, policy ) )
{
    simcontext()->get_port_registry()->insert( this );
}
sc_semaphore::sc_semaphore( int init_value_ )
: sc_object( sc_gen_unique_name( "semaphore" ) ),
  m_free( (std::string(SC_KERNEL_EVENT_PREFIX)+"_free_event").c_str() ),
  m_value( init_value_ )
{
    if( m_value < 0 ) {
	report_error( SC_ID_INVALID_SEMAPHORE_VALUE_ );
    }
}
Пример #8
0
/// Standard constructor.
ac_module::ac_module() : sc_module(sc_gen_unique_name("ac_module")),
			 mod_id(next_mod_id++),
			 ac_exit_status(0){
  ac_qk.set_global_quantum( sc_time(100, SC_NS) );
  ac_qk.reset();
  module_period_ns=5;  //200 MHz = 5ns
  this_mod = mods_list.insert(mods_list.end(), this);
  return;
}
Пример #9
0
sc_clock::sc_clock()
: sc_signal<bool>( sc_gen_unique_name( "clock" ) )
{
    init( sc_time( 1.0, true ),
	  0.5,
	  SC_ZERO_TIME,
	  true );

    m_next_posedge_event.notify_internal( m_start_time );
}
Пример #10
0
std::string
sc_vector_base::make_name( const char* prefix, size_type /* idx */ )
{
  // TODO: How to handle name clashes due to interleaved vector
  //       creation and init()?
  //       sc_vector< foo > v1, v2;
  //       v1.name() == "vector", v2.name() == "vector_0"
  //       v1.init( 1 ); -> v1[0].name() == "vector_0" -> clash
  return sc_gen_unique_name( prefix );
}
Пример #11
0
T* create( const char* nm )
{
  try {
    return new T( sc_gen_unique_name(nm) );
  }
  catch ( sc_report const & x )
  {
      std::cout << "\n" << x.what() << std::endl;
  }
  return 0; // error detected, return NULL
}
Пример #12
0
void sc_clock::before_end_of_elaboration()
{
    std::string gen_base;
    sc_spawn_options posedge_options;	// Options for posedge process.
    sc_spawn_options negedge_options;	// Options for negedge process.

    posedge_options.spawn_method();
    posedge_options.dont_initialize();
    posedge_options.set_sensitivity(&m_next_posedge_event);
    gen_base = basename();
    gen_base += "_posedge_action";
    sc_spawn(sc_clock_posedge_callback(this),
	sc_gen_unique_name( gen_base.c_str() ), &posedge_options);

    negedge_options.spawn_method();
    negedge_options.dont_initialize();
    negedge_options.set_sensitivity(&m_next_negedge_event);
    gen_base = basename();
    gen_base += "_negedge_action";
    sc_spawn( sc_clock_negedge_callback(this),
    	sc_gen_unique_name( gen_base.c_str() ), &negedge_options );
}
sc_object::sc_object(const char* nm) : 
    m_attr_cltn_p(0), m_child_events(), m_child_objects(), m_name(),
    m_parent(0), m_simc(0)
{
    int namebuf_alloc = 0;
    char* namebuf = 0;
    const char* p;

    // null name or "" uses machine generated name.
    
    if ( !nm || !*nm )
	nm = sc_gen_unique_name("object");
    p = nm;

    if (nm && sc_enable_name_checking) {
        namebuf_alloc = 1 + strlen(nm);
        namebuf = (char*) sc_mempool::allocate(namebuf_alloc);
        char* q = namebuf;
        const char* r = nm;
        bool has_illegal_char = false;
        while (*r) {
            if (object_name_illegal_char(*r)) {
                has_illegal_char = true;
                *q = '_';
            } else {
                *q = *r;
            }
            r++;
            q++;
        }
        *q = '\0';
        p = namebuf;
        if (has_illegal_char)
	{
	    std::string message = nm;
	    message += " substituted by ";
	    message += namebuf;
            SC_REPORT_WARNING( SC_ID_ILLEGAL_CHARACTERS_, message.c_str());
	}
    }
    sc_object_init(p);
    sc_mempool::release( namebuf, namebuf_alloc );
}
Пример #14
0
sc_trace_file_base::sc_trace_file_base( const char* name, const char* extension )
  : sc_trace_file()
#if SC_TRACING_PHASE_CALLBACKS_
  , sc_object( sc_gen_unique_name("$$$$kernel_tracefile$$$$") )
#endif
  , fp(0)
  , timescale_unit()
  , timescale_set_by_user(false)
  , filename_() 
  , initialized_(false)
  , trace_delta_cycles_(false)
{
    if( !name || !*name ) {
        SC_REPORT_ERROR( SC_ID_TRACING_FOPEN_FAILED_, "no name given" );
        return;
    } else {
        std::stringstream ss;
        ss << name << "." << extension;
        ss.str().swap( filename_ );
    }

#if SC_TRACING_PHASE_CALLBACKS_ == 1
    // remove from hierarchy
    sc_object::detach();
    // register regular (non-delta) callbacks
    sc_object::register_simulation_phase_callback(
        // Note: Usually, one would expect to dump the initial values
        //       of the traced variables at the end of the initialization
        //       phase.  The "non-callback" implementation dumps those
        //       values only after the first delta cycle, though.
        // SC_END_OF_INITIALIZATION |
        SC_BEFORE_TIMESTEP |
        SC_PAUSED | SC_STOPPED
    );
#else // explicitly register with simcontext
    sc_get_curr_simcontext()->add_trace_file( this );
#endif
}
sc_object::sc_object( const sc_object& that ) : 
    m_attr_cltn_p(0), m_child_events(), m_child_objects(), m_name(),
    m_parent(0), m_simc(0)
{
    sc_object_init( sc_gen_unique_name( that.basename() ) );
}
Пример #16
0
/**
 * Constructor for the class
 *
 * @param[in] clk             one clock cycle delay represented by a sc_time object
 * @param[in] flit_width      flit width of the network
 * @param[in] n_masters       total number of masters in the system.
 * @param[in] n_slaves        total number of slaves in the system.
 * @param[in] src_queue_size  default number of outstanding transaction for source_ni 
 * @param[in] dest_queue_size default number of outstanding transaction for dest_ni 
 * @param[in] _n              name of the network module
 */
approx_network_base::approx_network_base (sc_time clk, int flit_width, int n_masters, int n_slaves, bool sample_bandwidth, bool sample_latency, bool print_trans, bool sample_energy, int src_queue_size, int dest_queue_size, sc_module_name _n)
  : sc_module( _n ),
    abstract_noc::network_base(n_masters, n_slaves, sample_bandwidth, sample_latency, print_trans, sample_energy),
    m_clk ( clk ),
    m_flit_width ( flit_width )
{
#if 0    
    for(int i=0; i< m_n_masters+m_n_slaves; i++) {
        if(i < m_n_masters) {
            map<int, vci_request> toPut;
            
            m_req_trans_map.push_back(toPut);
            stringstream ss1;
            ss1 << "source_ni(mstr="<< i << ",cosi=" << i << ")";
            source_ni<vci_request> *s_ni = new source_ni<vci_request>(this, m_clk, i, m_flit_width, src_queue_size, sc_gen_unique_name(ss1.str().c_str())); 
            
            stringstream ss2;
            ss2 << "dest_ni(mstr="<< i << ",cosi=" << i << ")";
            dest_ni<vci_response> *d_ni = new dest_ni<vci_response>(this, m_clk, i, m_flit_width, dest_queue_size, sc_gen_unique_name(ss2.str().c_str()));
            
            m_source_ni[i] = s_ni;
            m_dest_ni[i] = d_ni;
        } else {
            map<int, vci_response> toPut;
            
            m_res_trans_map.push_back(toPut);
            stringstream ss1;
            ss1 << "source_ni(slave="<< i-m_n_masters << ",cosi=" << i << ")";
            source_ni<vci_response> *s_ni = new source_ni<vci_response>(this, m_clk, i-m_n_masters, m_flit_width, src_queue_size, sc_gen_unique_name(ss1.str().c_str()));
     
            stringstream ss2;
            ss2 << "dest_ni(slave=" << i-m_n_masters << ",cosi=" << i << ")";
            dest_ni<vci_request> *d_ni = new dest_ni<vci_request>(this, m_clk, i-m_n_masters, m_flit_width, dest_queue_size, sc_gen_unique_name(ss2.str().c_str()));
            m_source_ni[i] = s_ni;
            m_dest_ni[i] = d_ni;
        }
    }
#endif
		int i=0;

            map<int, vci_request> toPut;
            
            m_req_trans_map.push_back(toPut);
            stringstream ss1;
            ss1 << "master_vci2axi_source_ni(mstr="<< i << ",cosi=" << i << ")";
            master_vci2axi_source_ni<vci_request> *s_ni = new master_vci2axi_source_ni<vci_request>(this, 0, 1, sc_gen_unique_name(ss1.str().c_str())); 
            m_source_ni[i] = s_ni;
}
Пример #17
0
sc_mutex::sc_mutex()
: sc_object( sc_gen_unique_name( "mutex" ) ),
  m_owner( 0 ),
  m_free( (std::string(SC_KERNEL_EVENT_PREFIX)+"_free_event").c_str() )
{}
Пример #18
0
sc_vector_base::sc_vector_base()
  : sc_object( sc_gen_unique_name("vector") )
  , vec_()
  , objs_vec_()
{}
sc_object::sc_object() : 
    m_attr_cltn_p(0), m_child_events(), m_child_objects(), m_name(),
    m_parent(0), m_simc(0)
{
    sc_object_init( sc_gen_unique_name("object") );
}
Пример #20
0
sc_object::sc_object() : m_parent(0)
{
    sc_object_init( sc_gen_unique_name("object") );
}
Пример #21
0
void 
sc_object::sc_object_init(const char* nm) 
{ 
    bool        clash;                  // True if path name exists in obj table
    const char* leafname_p;             // Leaf name (this object) 
    char        pathname[BUFSIZ];       // Path name 
    char        pathname_orig[BUFSIZ];  // Original path name which may clash 
    const char* parentname_p;           // Parent path name 
    bool        put_in_table;           // True if should put in object table 
 
    // SET UP POINTERS TO OBJECT MANAGER, PARENT, AND SIMULATION CONTEXT: 
	//
    // Make the current simcontext the simcontext for this object 

    m_simc = sc_get_curr_simcontext(); 
    m_attr_cltn_p = 0; 
    sc_object_manager* object_manager = m_simc->get_object_manager(); 
    sc_object*         parent_p = object_manager->hierarchy_curr(); 
    if (!parent_p) { 
        sc_object* proc = (sc_object*)sc_get_current_process_b();
        parent_p = proc; 
    } 
    m_parent = parent_p; 


    // CONSTRUCT PATHNAME TO OBJECT BEING CREATED: 
    // 
    // If there is not a leaf name generate one. 

    parentname_p = parent_p ? parent_p->name() : ""; 
    if (nm && nm[0] ) 
    { 
        leafname_p = nm; 
        put_in_table = true; 
    } 
    else 
    { 
        leafname_p = sc_object_newname(pathname_orig); 
        put_in_table = false; 
    } 
    if (parent_p) { 
        std::sprintf(pathname, "%s%c%s", parentname_p, 
                SC_HIERARCHY_CHAR, leafname_p 
        ); 
    } else { 
        strcpy(pathname, leafname_p); 
    } 

    // SAVE the original path name 
    // 
    strcpy(pathname_orig, pathname); 

    // MAKE SURE THE OBJECT NAME IS UNIQUE 
    // 
    // If not use unique name generator to make it unique. 

    clash = false; 
    while (object_manager->find_object(pathname)) { 
        clash = true; 
        leafname_p = sc_gen_unique_name(leafname_p); 
        if (parent_p) { 
            std::sprintf(pathname, "%s%c%s", parentname_p, 
                    SC_HIERARCHY_CHAR, leafname_p 
            ); 
        } else { 
            strcpy(pathname, leafname_p); 
        } 
    } 
    if (clash) { 
	std::string message = pathname_orig;
	message += ". Latter declaration will be renamed to ";
	message += pathname;
        SC_REPORT_WARNING( SC_ID_OBJECT_EXISTS_, message.c_str());
    } 


    // MOVE OBJECT NAME TO PERMANENT STORAGE 
    // 
    // Note here we pull a little trick -- use the first byte to store 
    // information about whether to put the object in the object table in the 
    // object manager 

    char* ptr = new char[strlen( pathname ) + 2]; 
    ptr[0] = put_in_table; 
    m_name = ptr + 1; 
    strcpy(m_name, pathname); 

    if (put_in_table) { 
        object_manager->insert_object(m_name, this); 
        sc_module* curr_module = m_simc->hierarchy_curr(); 
        if( curr_module != 0 ) { 
            curr_module->add_child_object( this ); 
        } else { 
            sc_process_b* curr_proc = sc_get_current_process_b();
            if (curr_proc) { 
                curr_proc->add_child_object( this ); 
            } else { 
                m_simc->add_child_object( this ); 
            } 
        } 
    } 
}