Jump to content
kocha

Why sc_object menber function trace() deprecated?

Recommended Posts

Hi,

Would you teach?

Example, I want to trace sc_in/out/inout and sc_signal of all hierarchy.

 void all_trace(sc_trace_file *tf, std::vector<sc_object*>& children){
for (std::vector<sc_object*>::iterator i = children.begin(); i != children.end(); i++){
  if ( std::string((*i)->kind())=="sc_module" ) {
	sc_module* mptr = dynamic_cast<sc_module*>(*i);
	std::vector<sc_object*> r_children = mptr->get_child_objects();
	all_trace(tf, r_children);
  }else if(  std::string((*i)->kind()) == "sc_in"
		  || std::string((*i)->kind()) == "sc_out"
		  || std::string((*i)->kind()) == "sc_inout"
		  || std::string((*i)->kind()) == "sc_signal"){
	(*i)->trace(tf);
  }
}
 }
 :
 std::vector<sc_object*> children = top.get_child_objects();
 all_trace(tf, children);
 :

Are there any means to realize otherwise etc.?

Share this post


Link to post
Share on other sites

Unfortunately there is no easy solution.

trace is not part of the standard anymore. So you can not be sure if its implementation is available (and as far as I know it is not available for sc_in, etc. ).

According to the standard, you should use sc_trace. But you need to know the exact runtime type to use sc_trace.

Since C++ lacks of full introspection, there is no possibility to get it.

There are two solutions I know, but both are not really nice.

First: try to dynamic_cast your object. Only possible if you know all the types the object possibly might have.

if ((*i)-kind() == "sc_signal")
{
 sc_signal<bool>* signal_bool;
 sc_signal<sc_logic>* signal_logic;
 if (signal_bool  = dynamic_cast<sc_signal<bool>*>(obj))
   sc_trace(tf, *signal_bool, signal_bool->name());
 if (signal_logic = dynamic_cast<sc_signal<sc_logic>*>(obj))
   sc_trace(tf, *signal_logic, signal_logic->name());
 // repeat for every possible type
....
}

Second way: Use your own class 'sc_module_plus' derived from sc_module to implement your modules. Add a virtual function 'trace_your_members' to this class. Give the trace file handle as a parameter to this class and let each module register its own members for tracing.

Then you may run through the hierarchy as before and call this function for every module you find.

Share this post


Link to post
Share on other sites

Thank you for giving a reply.

There is a means to realize the code which I presented.

1. add trace function sc_in/sc_in<bool> ...

file:sc_signal_ports.h

modify:

    void trace(sc_trace_file* tf) const{
  add_trace(tf, base_type::name());
}

2. compile option 「 -DDEBUG_SYSTEMC」

g++ ... -DDEBUG_SYSTEMC

Performing is possible if the above correction is made.

But, SystemC log...

Info: (I804) /IEEE_Std_1666/deprecated: sc_signal<T>::trace() is deprecated

Info: (I804) /IEEE_Std_1666/deprecated: sc_signal<T>::addtrace() is deprecated

since -- a reason wants to know.

Best Regards.

Share this post


Link to post
Share on other sites

Kocha,

There is no easy solution for your problem!

Try following solution (I wrote it for systemc-ams, but you can easily modify that):

write a function as follows :

template < typename T > void sc_trace_template(sca_util::sca_trace_file* tf,sc_object* obj) {
   T* object ;
   if ((object  = dynamic_cast < T* >(obj))) sca_util::sca_trace(tf, *object , object->name());
}

Then create another function like as follows:


void sc_trace(sca_util::sca_trace_file* tf, const sc_module& mod, const std::string& txt) {


 std::vector < sc_object* > ch = mod.get_child_objects();

 for ( unsigned i = 0; i < ch.size(); i++ ) {
   sc_object* obj = ch[i];

//  signals :
   sc_trace_template < sc_core::sc_signal < bool > > (tf,obj);

//  Add all other data types below (sc_in <T> , sc_out <T>, T needs to be explicitly specified):
   ......


//  modules :
   sc_module* m;
   if ((m = dynamic_cast < sc_module* > (obj))) sc_trace(tf, *m, m->name());

}

}



Call sc_trace @ sc_main

This is an extremely medicore solution, but will work.

Regards,

Sumit

Share this post


Link to post
Share on other sites

Sumit,

Thank you for giving a reply.

Although it may be difficult to be sure with the present specification,
By mounting a trace function in sc_object,
I think whether the thing which I would like to do becomes possible.

I would like to know the propriety about the specification change here.

Best Regards.

Share this post


Link to post
Share on other sites

Short answer:  The standard requires an sc_trace overload for a user-defined (signal) datatype if and only if you actually trace this particular type.  Defining the virtual function sc_object::trace would require an overload for each and every data type used within a primitive channel supporting traces, even if those signals are never traced.  This would be quite inconvenient.

 

/Philipp

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...