Jump to content
katang

How to convert 'const char*' to 'const sc_module_name&'

Recommended Posts

For my subclassed constructor

My::My(sc_core::sc_module_name nm, int ID)
    : sc_core::sc_module(((string(nm).append(1,ID<26 ?'A'+ID : 'A'+ID +6)).c_str()))

I receive

Warning: (W569) sc_module(const char*), sc_module(const std::string&) have been deprecated, use sc_module(const sc_module_name&)

Why utilizing those two simple argument types are deprecated, and how can I legally do what I want?

 

Share this post


Link to post
Share on other sites

What do you want exactly? Can you use sc_vector<My> that automatically initializes names? Can you concatenate name and ID before module construction?

SystemC elaboration relies on the fact that sc_module_name will be constructed before module.  This way it can create correct hierarchical names for module fields.

Modern way to declare module is like this:

struct my_module : sc_module {
	my_module(sc_module_name) {
	}
};

More compact way is to use SystemC macros:

SC_MODULE(my_module) {
	SC_CTOR(my_module) {
	}
};

 

Share this post


Link to post
Share on other sites

You may use a temporary object:

My::My(sc_core::sc_module_name nm, int ID)
    : sc_core::sc_module(sc_core::sc_module_name((string(nm).append(1,ID<26 ?'A'+ID : 'A'+ID +6)).c_str()))

But I would move the stuff into a free function:

sc_core::sc_module_name concatenate(sc_core::sc_module_name nm, int ID){
	std::string res(nm);
	res.append(1,ID<26 ? 'A'+ID : 'A'+ID+6);
    return res.c_str();
}

My::My(sc_core::sc_module_name nm, int ID)
    : sc_core::sc_module(concatenate(nm, ID))

This makes the whole code easier to understand and more maintainable...

Cheers

Share this post


Link to post
Share on other sites
4 hours ago, Eyck said:

 


sc_core::sc_module_name concatenate(sc_core::sc_module_name nm, int ID)

This makes the whole code easier to understand and more maintainable...

No, this is not allowed by SystemC LRM "5.3.3 Constraints on usage":  

Quote

Class sc_module_name shall only be used as the type of a parameter of a constructor of a class derived from class sc_module. 

 

Share this post


Link to post
Share on other sites
On 23/03/2018 at 12:54 AM, Eyck said:

My::My(sc_core::sc_module_name nm, int ID)
    : sc_core::sc_module(concatenate(nm, ID))

 

This usage of sc_module_name is wrong and will break the module hierarchy.

The only thing you are allowed (but not even required) to do with the module name object inside your constructor is to forward it to the sc_module base class.

As Roman said, you would have to prepare the name outside of the module instead (or use sc_vector).

/Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×