how to keep chisel variable name when generate verilog
There are several reasons why a name may be disappearing.
Constant Propagation
For many reasons, including interoperability with existing CAD tools, performance, and Verilog debug-ability, Chisel (actually the FIRRTL compiler underneath Chisel) will propagate constants and direct wire connections. For example:
1 | class MyModule extends Module { |
In the above code, wire will be removed because it is simply connected to io.in, the Verilog will just show:
assign io_out = io_in;
Inability to name
Chisel Modules are implemented as Scala Classes. Due to implementation reasons, by default Chisel can only name “top-level” vals in the body of the Module, for example:
1 | class MyModule extends Module { |
suggestName
You can manually name any signal by calling .suggestName(“name”) on it, eg.
1 | def inc(x: UInt): UInt = { |
Enter @chiselName
We can fix the above issue with an experimental feature called @chiselName like so:
1 | import chisel3.experimental.chiselName |
@chiselName is an annotation that can be used on any class or object definition and will ensure vals like incremented can get named. @chiselName effectively rewrites your code to put .suggestName all over the place.
I hope this helps!
EDIT more info:
Disabling Optimizations
I don’t think it’s in a release yet (most recent being 3.1.7, this will be in 3.2.0), but we do have an option to disable all optimizations. You can change the “compiler” used from verilog to mverilog (for “minimum” Verilog, ie. no optimizations). This can be done with the command-line argument -X mverilog either in Chisel or FIRRTL.
Don’t Touch
You can also use chisel3.experimental.dontTouch to mark a signal as something that shouldn’t be deleted. This will prevent optimizations from removing the signal. For example:
1 | import chisel3.experimental.dontTouch |
I’ve edited my response to talk about how to disable optimizations (not in the current release, you can wait for 3.2 which should be out in a couple of weeks or build Chisel manually from master and use that). I should caution that running formal equivalence tools tend to struggle comparing large designs with and without optimizations, but you can try it. For specific signals, dontTouch can help with what you want. o