Jump to content

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


katang

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?

 

Link to comment
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) {
	}
};

 

Link to comment
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

Link to comment
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. 

 

Link to comment
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

Link to comment
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...