Search code examples
chisel

How to generate Verilog code with parametized modules in Chisel?


The following module definition in chisel:

class Mux2 (width: Int = 4) extends Module

does not result in a Verilog module that is parametrized. The generated Verilog RTL will instead substitute the parameter value that the user instantiated the module with.

Is there a way to generate Verilog with actual parametrized module definitions.

module Mux2 #(parameter width = 4)

If there is no way to do this this would be a very useful feature to add.


Solution

  • Unfortunately this is probably an impossible feature to add. Chisel is really just a Scala library of hardware primitives that enables you to write a Scala program to elaborate a circuit. Parameterization of Chisel generators is arbitrary Scala code which would be impossible to map to Verilog constructs in the general case. In fact, the primary utility of Chisel comes from enabling designers to use these higher-level constructs that do not exist in [synthesizable] Verilog (eg. object-oriented programming, functional programming).