katang Posted May 19, 2017 Report Posted May 19, 2017 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? Quote
Philipp A Hartmann Posted May 19, 2017 Report Posted May 19, 2017 Recommended practice is to put SC_HAS_PROCESS within the scope of the module itself: SC_MODULE(Module) { SC_HAS_PROCESS(Module); // ... }; Hope that helps, Philipp maehne 1 Quote
CapUnderPantsRLZ Posted December 11, 2017 Report Posted December 11, 2017 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(){ } Quote
David Black Posted December 11, 2017 Report Posted December 11, 2017 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(){ } DS1701 1 Quote
CapUnderPantsRLZ Posted December 12, 2017 Report Posted December 12, 2017 "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. Quote
DS1701 Posted November 30, 2018 Report Posted November 30, 2018 Dear @David Black Thanks for your support , I have a question: " Why haven't you never used <systems.h> ?" What is different between <systemc> and <systemc.h> ? Thanks. Quote
AmeyaVS Posted November 30, 2018 Report Posted November 30, 2018 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: https://stackoverflow.com/questions/10269012/global-scope-vs-global-namespace 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 Quote
DS1701 Posted December 1, 2018 Report Posted December 1, 2018 Dear @AmeyaVS I appreciate all of your help . Thanks Quote
DS1701 Posted June 7, 2019 Report Posted June 7, 2019 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 Quote
Recommended Posts
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.