Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use templated functions for the Verilog API #11

Open
SeanMcLoughlin opened this issue Jun 28, 2021 · 3 comments
Open

Use templated functions for the Verilog API #11

SeanMcLoughlin opened this issue Jun 28, 2021 · 3 comments

Comments

@SeanMcLoughlin
Copy link

longint is the sole type that is used in the Verilog API. This makes sense given the limitations of the DPI, but I often end up with compiler warnings due to automatic casts from longint <-> whatever the type of my knob is.

For example, bit types are common for boolean knobs, and the implied casting gives several warnings on this line:

bit my_bit = 0;
// WARNING 1. get_value casts longint -> bit
// WARNING 2. default_value param casts bit -> longint
my_bit = sknobs::get_value("my_value", my_bit); 

In order to avoid these warnings, I have to manually cast everything in a very ugly manner:

bit my_bit = bit'(sknobs::get_value("my_value", longint'(my_bit)));

What I'm proposing is to wrap the API in a templated class, and have the API do the casting internally.

// sknobs.sv
class sknobs #(type T=longint);
  static function T get_value(string name, T default_value=0);
    get_value = T'(sknobs_get_value(name, longint'(default_value)));
  endfuncion
endclass : sknobs

That way, my ugly casting example can become the following in user code:

bit my_bit = 0;
my_bit = sknobs#(bit)::get_value("my_value", my_bit);
@joshuascheid
Copy link
Collaborator

Thanks for the suggestion. This would then be

sknobs::sknobs#(bit)::get_value(...);

What about something like

sknobs::value#(bit)::get(...);

@SeanMcLoughlin
Copy link
Author

Yes, I think that's a better solution. 😃

@joshuascheid
Copy link
Collaborator

I'll ping some others for feedback, but if you want to start a PR, please do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants