Jump to content
katang

Scope of SC_HAS_PROCESS

Recommended Posts

I am following the alternative style in book SCFTGU, and I wanted to put two closely related modules in the same source file. I collected the experience that using  SC_HAS_PROCESS for the second module in the same source file provokes error message. Why is it so?

 

Share this post


Link to post
Share on other sites

However, if you are splitting into .h and .cpp files for module, e.g., Blah, you must  place the SC_HAS_PROCESS(Blah), on the top of the implementation (.cpp) file, this way:

 

//.h

#import <systemc.h>

...

class Blah: sc_module {

Blah(sc_module_name);

~Blah();

}

//.cpp file

#include "Blah.h"

SC_HAS_PROCESS(Blah);

 

Blah::Blah(sc_module_name nm): sc_module(nm) {

}

Blah::~Blah(){

}

Share this post


Link to post
Share on other sites

Personally, I prefer to put SC_HAS_PROCESS directly into the constructor body, which works very reliably. All that SC_HAS_PROCESS does is to create a typedef called SC_CURRENT_USER_MODULE which refers to .... the current module name. It is only used in the three macros SC_THREAD, SC_METHOD and SC_CTHREAD. Syntactically, C++ allows a typedef to be created within a function (in this case the constructor function).

Advantages of this approach:

  • It's defined very close to the point of usage.
  • The user of a header file, does not need to see it.
/.h

#import <systemc> // I never use systemc.h

...

class Blah: sc_module {

Blah(sc_module_name);

~Blah();

}

//.cpp file

#include "Blah.h"
using namespace sc_core;
  
Blah::Blah(sc_module_name nm): sc_module(nm) {
    SC_HAS_PROCESS(Blah);
    SC_THREAD(blah_thread);
    ...
}

Blah::~Blah(){

}

 

Share this post


Link to post
Share on other sites

"Personally, I prefer to put SC_HAS_PROCESS directly into the constructor body, which works very reliably. All that SC_HAS_PROCESS does is to create a typedef "

Yep you right: "All that SC_HAS_PROCESS does is to create a typedef", now explain to your compiler to 'construct' something, that it was not defined before the constructor call. how do you do that? (rhetoric) . That it is precisely why the authors of SystemC: From the Ground Up, explained to place SC_HAS_PROCESS before the constructors.

GCC,  lets this kind of 'thing' pass, try with Clang++ now.

 

Plus you don't place that in the header file, instead, it is in the implementation file the .cc, .cpp, (whatever extension you are using) that will contain it inside your own namespace if it is the case.

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

×