dilawar Posted May 10, 2019 Report Share Posted May 10, 2019 https://www.doulos.com/knowhow/systemc/new_standard suggests to do the following. sc_port<i_f, 1, SC_ZERO_OR_MORE_BOUND> opt_port; I am trying to replace some of my `sc_out` and `sc_in` with optional ports. I would like to replace them with `sc_out_opt` and `sc_in_opt` class in headers of my modules. What is the best way to derive these classes such that my code-base works with minimal changes to code? 1. Should I derive them from `sc_port<i_f, 1, SC_ZERO_OR_MORE_BOUND>` or `sc_in` and `sc_out` classes? 2. Can I force a port policy on `sc_in` and `sc_out` in module constructor? Any other suggestions? Quote Link to comment Share on other sites More sharing options...
maehne Posted May 10, 2019 Report Share Posted May 10, 2019 If you don't use the member functions added that were added for convenience to `sc_in`, `sc_out`, and `sc_inout` to, e.g., call `read()`, `write()`, and the event member functions via the `.` operator than via the corresponding member function in the interface accessed via the `->` operator, you might be able to avoid entirely the derivation of new port classes. Instead, you could simply use a template alias, which was introduced with C++'11: template<typename T> using sc_in_opt = sc_core::sc_port<sc_signal_in_if<T>, 1, SC_ZERO_OR_MORE_BOUND>; template<typename T> using sc_inout_opt = sc_core::sc_port<sc_signal_inout_if<T>, 1, SC_ZERO_OR_MORE_BOUND>; template<typename T> using sc_out_opt = sc_core::sc_port<sc_signal_inout_if<T>, 1, SC_ZERO_OR_MORE_BOUND>; If you want to also provide all member functions of `sc_in`, `sc_out`, and `sc_inout`, you will have to derive from the `sc_port` class and implement the full interface as defined in IEEE Std 1666-2011. dilawar 1 Quote Link to comment Share on other sites More sharing options...
dilawar Posted May 10, 2019 Author Report Share Posted May 10, 2019 Thank you maehne. I'll use the `sc_port` solution. It clearly marks my intention in declaration. cheers, Dilawar 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.