veryl
veryl copied to clipboard
Adding module hierarchy for library creation and explicit imports
This is a language feature proposal.
Incorporating the ability to publish projects and add dependencies similar in spirit to Rust is a great addition to Veryl. However, one current limitation, it seems to me, is that there isn't a way to organize modules in a hierarchical fashion. I realize that this is likely to align with System Verilog's flat global namespace for modules and what is expected from EDA tools. However, I believe the pros outweigh the cons of organizing modules hierarchically into sharable libraries and that this promotes code reuse.
Lets imagine we are building a core library which contains useful building blocks for digital design:
core
src
register
reg_a.vl
reg_b.vl
fifo
fifo_d.vl
fifo_s.vl
...
Veryl.toml
Veryl.pub
If one then adds this core library as a dependency for a project it would be nice to be able to use its modules explicitly as such:
module foo
use core::register::reg_a;
(...){
// some user logic
inst a_foo : reg_a(...)
Or alternatively:
module foo
use core;
(...){
// some user logic
inst a_foo : core::register::reg_a(...)
This would be preferable over implicit importing once the dependency is defined, where something like this would be allowed:
module foo(...){
// some user logic
inst a_foo : core::register::reg_a(...)
Perhaps a mod.vl
could be added to the core library taking Rust's older approach to organizing modules in a crate. This file mod.vl
for the register subdirectory could have the following contents:
mod reg_a;
mod reg_b;
A similar mod.vl
would thus be added for each logical grouping of Veryl modules like fifo and so on.
Finally the core library would be updated to look like the following:
core
src
register
reg_a.vl
reg_b.vl
mod.vl
fifo
fifo_d.vl
fifo_s.vl
mod.vl
...
Veryl.toml
Veryl.pub