Andreas Posted November 14, 2014 Report Share Posted November 14, 2014 Hi, I am reciving Error: (E100) port specified outside of module: port 'port_0' (sc_port_base) In file: ../../../../src/sysc/communication/sc_port.cpp:231 When I try to bild my systemc simulation. I have written a small example, that reproduce the error on my machine: main.cpp #include "systemc.h" #include "exampleModule.cpp" int sc_main (int argc, char* argv[]) { ExampleModule example("example"); } exampleModule.cpp #include "systemc.h" struct ExampleModule : ::sc_core::sc_module{ public: sc_fifo_in<int> out; void readData(){ } SC_HAS_PROCESS(ExampleModule); ExampleModule( const char* name ): sc_module( sc_module_name(name) ) { cout << "name:" << this->name() << endl; SC_THREAD(readData); } }; It looks like the error is in ExampleModule( const char* name ): sc_module( sc_module_name(name) ) While debuggin this part I get an unexpected jump to sc_port. When I'm changing the code to ExampleModule( const char* name ): sc_module( name ) everything is fine. But this is deprecated. Has anyone a suggestion what im doing wrong? Regards Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted November 14, 2014 Report Share Posted November 14, 2014 Hi, the following line ExampleModule( const char* name ): sc_module( sc_module_name(name) ); seems to instantiate more than on sc_module_name object. SystemC uses the creation ond destruction of sc_module_name to setup the module hierarchy and becomes confused here. It works without the explicit sc_module_name constructor. ExampleModule( const char* name ): sc_module( name ); Greetings Ralph Quote Link to comment Share on other sites More sharing options...
Andreas Posted November 14, 2014 Author Report Share Posted November 14, 2014 Well good to know it is not my fault . I know it works with: ExampleModule( const char* name ): sc_module( name ); So I have to work with this. But I don't like it, because it's deprecated. Thank you Regards Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted November 14, 2014 Report Share Posted November 14, 2014 The following should work as well without deprecated warning: ExampleModule( const sc_module_name & name ) : sc_module( name ) Greetings Ralph Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted November 15, 2014 Report Share Posted November 15, 2014 Well good to know it is not my fault . Strictly speaking, it is your fault. Quoting 1666-2011, section 5.2.3 (sc_module, constraints on usage), emphasis mine: Every class derived (directly or indirectly) from class sc_module shall have at least one constructor. Every such constructor shall have one and only one parameter of class sc_module_name but may have further parameters of classes other than sc_module_name. So the last variant posted by Ralph is the correct definition. /Philipp maehne 1 Quote Link to comment Share on other sites More sharing options...
Andreas Posted November 17, 2014 Author Report Share Posted November 17, 2014 Hey I would prefer to use this way, but it seems not as easy for me. I try to generate Python bindings folowing this (http://forums.accellera.org/topic/1458-python-bindings-for-systemc/) paper (at the end of the topic). I am not finished now. But Swig could only pass char* as parameter. So my preffered way to create an object is using a call to: ExampleModule( const char* name ) Regards Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted November 17, 2014 Report Share Posted November 17, 2014 I try to generate Python bindings folowing this (http://forums.accellera.org/topic/1458-python-bindings-for-systemc/) paper (at the end of the topic). I am not finished now. But Swig could only pass char* as parameter. So my preffered way to create an object is using a call to: ExampleModule( const char* name ) As said before, you have to have an sc_module_name parameter in the (leaf) constructor of your module class hierarchy. Using the deprecated constructor will likely mess up your object hierarchy during elaboration. You can directly call such a constructor with a const char* argument, as you can implicitly construct an sc_module_name from a const char*. Maybe this is all you need. Otherwise, you can create a wrapper (or a derived class), with no own sc_object/sc_module members and construct the real SystemC module from within C++. hth, Philipp Quote Link to comment Share on other sites More sharing options...
Andreas Posted November 18, 2014 Author Report Share Posted November 18, 2014 Finally I had implemented the workaround you mentioned. something like: struct ExampleModulePython :ExampleModule { ExampleModulePython(const char* name):ExampleModule(name){} }; But now I have a different problem. As long as I used ExampleModule( const char* name ) I was able to create the Ports in Python. Now I get the same Error.I guess that after the Module is registered using SC_HAS_PROCESS and SC_THREAD It is not possible to add any prots? I am rigth that there are no checks for this if you are using the deprecated way? Regards Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted November 18, 2014 Report Share Posted November 18, 2014 (edited) I was able to create the Ports in Python. Now I get the same Error. I guess that after the Module is registered using SC_HAS_PROCESS and SC_THREAD It is not possible to add any prots? I am rigth that there are no checks for this if you are using the deprecated way? Quoting my earlier reply (emphasis added): "Otherwise, you can create a wrapper (or a derived class), with no own sc_object/sc_module members and construct the real SystemC module from within C++." The module/object hierarchy creation is closely related to the sc_module_name stack. Once the sc_module_name instance is destroyed (after the completion of your ExampleModule (base class) constructor), the "current module" is removed from this stack. Therefore, the ports you create afterwards can not be assigned to the correct module. Again, a workaround may be to create the ports via Python from within before_end_of_elaboration callback, where the module hierarchy is correctly restored without having a proper sc_module_name stack. The deprecated constructor comes from very old versions of SystemC (before the introduction of sc_module_name) and requires you to manually call the (similarly non-standard) function end_module after the creation of all sc_object members at the end of the constructor. Otherwise, your hierarchy will be messed up in case of multiple (nested) modules. I would not recommend this approach. Greetings from Oldenburg, Philipp Edited November 18, 2014 by Philipp A. Hartmann Quote Link to comment Share on other sites More sharing options...
Andreas Posted November 19, 2014 Author Report Share Posted November 19, 2014 Otherwise, you can create a wrapper (or a derived class), with no own sc_object/sc_module members and construct the real SystemC module from within C++. I am a little bit confused now. Isn't this what I had done with struct ExampleModulePython :ExampleModule { ExampleModulePython(const char* name):ExampleModule(name){} }; Again, a workaround may be to create the ports via Python from within before_end_of_elaboration callback, where the module hierarchy is correctly restored without having a proper sc_module_name stack. I will try this approach. Thanks Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted November 19, 2014 Report Share Posted November 19, 2014 I am a little bit confused now. Isn't this what I had done with [...] Well, but you tried to add these "members" from Python during the construction phase afterwards. /Philipp Quote Link to comment Share on other sites More sharing options...
Andreas Posted November 19, 2014 Author Report Share Posted November 19, 2014 Well, you are rigth. However the workaround using before_end_of_elaboration is working. Thank you Regards Andreas Quote Link to comment Share on other sites More sharing options...
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.