circt icon indicating copy to clipboard operation
circt copied to clipboard

Support for Adding Parameter Annotations to Generated Modules (e.g., as Comments)

Open farukyld opened this issue 5 months ago • 2 comments
trafficstars

Context

I'm using PyCDE to generate parameterized modules and test them using a handwritten Verilator testbench. To simplify the testbench logic, I instantiate different versions of the module under test using a single testbench. For that to work, all the modules must have the same top-level name.

To achieve this, I prefixed the module builder's argument with an underscore ("_"). With that, generated module's name doesn't contain parameters and is unified, but it creates another problem…

Problem

By removing the parameters from the module name, I lose visibility into what configuration a given module was generated from. This makes it difficult to track which parameters were used for which module, especially when dealing with multiple variations. As a result, debugging and traceability suffer.

Question/Feature Request

Is there a way to annotate the generated Verilog/SystemVerilog module with a comment that includes the parameter values? Ideally, I’d like to see something like this:

// Parameters: WIDTH=32, DEPTH=64
module my_module (...);

If this is already supported in PyCDE, could you provide an example of how to do it? If not, would it be feasible to add such a feature?

farukyld avatar Jun 02 '25 05:06 farukyld

Sorry it took me so long to post here.

Turns out there is a property in hw.module to emit a comment above. So this is a simple feature addition. I was thinking that the docstring should be put above the module. WDYT?

teqdruid avatar Jun 10 '25 17:06 teqdruid

Does it make sense to also add the module parameters? How about the metadata which you can optionally add?

teqdruid avatar Jun 10 '25 18:06 teqdruid

ı didn't tried yet but probably all your suggestions would work for me. ı want to add metadata/comment to generated verilog module (maybe wire, register,...). it doesnt have to derived automatically from parameters. maybe this is already possible but the problem is ı dont know how to achieve that. sorry for the overspecific issue title btw. I made an ai rephrase it.

farukyld avatar Jun 24 '25 14:06 farukyld

also ı want module names to unified, currently ı do it by prefixing the parameter with underscore. but this disturbs the parameter caching behavior.

farukyld avatar Jun 24 '25 14:06 farukyld

also ı want module names to unified, currently ı do it by prefixing the parameter with underscore. but this disturbs the parameter caching behavior.

I forgot to reply. You can override the output module name for all modules, not just externs.

teqdruid avatar Jul 22 '25 02:07 teqdruid

thank you. if it is okay, you may close the issue

farukyld avatar Jul 29 '25 06:07 farukyld