Jump to content

Scope of SC_HAS_PROCESS


katang

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?

 

Link to comment
Share on other sites

  • 6 months later...

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(){

}

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

}

 

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

Link to comment
Share on other sites

  • 11 months later...

Hello @Hook,

The "systemc.h" header file actually include the "systemc" header, if you look at the source.

Note: Reproduced below a section of the systemc.h header from SystemC release 2.3.3

202     using std::memset;
203     using std::strerror;
204     using std::strlen;
205
206 // deprecated strstream support
207 #if defined( SC_INCLUDE_STRSTREAM )
208 #include <strstream>
209
210     using std::strstream;
211     using std::strstreambuf;
212     using std::istrstream;
213     using std::ostrstream;
214
215 #endif // SC_INCLUDE_STRSTREAM
216
217 // INCLUDE SYSTEMC DEFINITIONS for sc_dt AND sc_core NAMESPACES:
218
219 #include "systemc"
220
221 // USINGS FOR THE sc_dt NAMESPACE:
222
223 using sc_dt::SC_BIN;
224 using sc_dt::SC_BIN_SM;
225 using sc_dt::SC_BIN_US;

But it also exports the symbols from the SystemC sc_core and sc_dt namespace in the global scope(as evident from the above snippet).

You can find relevant discussion here:

  1. https://stackoverflow.com/questions/10269012/global-scope-vs-global-namespace
  2. https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

It is generally considered a bad C++ coding guideline to export everything in the global scope.

Hope it helps.

Regards,

Ameya Vikram Singh

Link to comment
Share on other sites

  • 6 months later...
On 12/13/2017 at 4:15 AM, CapUnderPantsRLZ said:

"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  "

: "All that SC_HAS_PROCESS does is to create a ", now explain to your compiler to 'construct' something, that it was not defined before the constructor call. do you do that? ) 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.

 

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

Hi @CapUnderPantsRLZ

in 1666-2011.pdf

Quote

macro SC_HASS_PROCESS shall be invoked within the class definition or the constructor body of the module.

So, I think @David Black is exactly.

https://stackoverflow.com/questions/45308468/systemc-multiple-module-implementations-in-single-cpp-file

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...