OMark Posted August 4, 2020 Report Share Posted August 4, 2020 Hello, I have defined one class "Class A" and when creating instances of that class e.g. A* instA1 = new A (); I want to attach the instA1 object to an sc_in port of my SystemC module as an attribute of that port. - Can I use for that purpose the add_attribute function? - How safe is that? - Are there any other recommended mechanisms (as alternatives)? Thanks. Quote Link to comment Share on other sites More sharing options...
Eyck Posted August 4, 2020 Report Share Posted August 4, 2020 Basically yes but just add_attribute is not enough. From the top of my head: you need to declare in your sc_module: sc_core::sc_attribute<A*> attr{"attr", nullptr}; sc_core::sc_in<bool> pin{"pin"}; in the constructor of your sc_module you need to add the attribute to the sc_object/sc_port: pin.add_attribute(attr); via attr.value = new A(); you can assign a value. This way the attribute can be found e.g. via the SystemC object tree (sc_core::sc_get_top_level_objects() ). Alternatives depend of your goal. One option would be to use CCI, esp. cci_param. But again, it depends what you want to achieve... swami-cst 1 Quote Link to comment Share on other sites More sharing options...
OMark Posted August 12, 2020 Author Report Share Posted August 12, 2020 Hello, I tried out your method as follows: sc_object* test_object_find = sc_core::sc_find_object(port_name); sc_core::sc_object& obj = dynamic_cast <sc_core::sc_object&>(*test_object_find); PortElement<sc_logic>* PE = new PortElement<sc_logic>(count,hierarchical_name,port_name,obj); sc_core::sc_attribute<PortElement<sc_logic>*> attr{"PortElement", nullptr}; attr.value = PE; Until here, I am capable to build and run without issue. Then when I follow up the above lines of code with this one: obj.add_attribute(attr); I can build, but when I run the simulation it crashes suddenly. Which failure did I make when adding the attribute to the port object? Thanks for your help. On 8/4/2020 at 8:11 PM, Eyck said: Quote Link to comment Share on other sites More sharing options...
Eyck Posted August 12, 2020 Report Share Posted August 12, 2020 Do you have an error message or stacktrace (gdb)? 'simulation [...] crashes suddenly' is very generic and can have manifold root causes... Where do you execute the code? You can only create sc_object based elements during elaboration. But if PortElement is a plain C++ class I have no idea why it fails... 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.