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

[Feature] Generics for code block #793

Open
taichi-ishitani opened this issue Jun 20, 2024 · 3 comments
Open

[Feature] Generics for code block #793

taichi-ishitani opened this issue Jun 20, 2024 · 3 comments
Labels
lang Language design

Comments

@taichi-ishitani
Copy link
Contributor

SV's text macro is useful feature to reduce coding cost for repeated code blocks.
I need this kind of feature to import code below to Very.
https://github.com/rggen/rggen-sample/blob/b0439abf7d5fa6086c4d0aef0ffcdc6836506f06/uart_csr.sv#L1-L9

I think it can be achieved if the generics feature handle code blocks.

@dalance
Copy link
Collaborator

dalance commented Jun 20, 2024

A syntax idea about generic block declaration.

block rggen_connect_bit_field_if::<RIF, FIF, LSB, WIDTH> {
    assign  FIF.valid                 = RIF.valid;
    assign  FIF.read_mask             = RIF.read_mask[LSB+:WIDTH];
    assign  FIF.write_mask            = RIF.write_mask[LSB+:WIDTH];
    assign  FIF.write_data            = RIF.write_data[LSB+:WIDTH];
    assign  RIF.read_data[LSB+:WIDTH] = FIF.read_data;
    assign  RIF.value[LSB+:WIDTH]     = FIF.value;
}

module ModuleA {
    inst u_block: rggen_connect_bit_field_if::<bit_field_if, bit_field_sub_if, 0, 8>;
}

@taichi-ishitani
Copy link
Contributor Author

It looks good.
But why is instance name need? Is it to separate namespace?

@dalance
Copy link
Collaborator

dalance commented Jun 20, 2024

It looks good. But why is instance name need? Is it to separate namespace?

Yes. And adding name-less instantiation increases syntax and name-resolver complexity.
The generated SV will become like below:

if (1) begin: u_block
    assign  FIF.valid                 = RIF.valid;
    assign  FIF.read_mask             = RIF.read_mask[LSB+:WIDTH];
    assign  FIF.write_mask            = RIF.write_mask[LSB+:WIDTH];
    assign  FIF.write_data            = RIF.write_data[LSB+:WIDTH];
    assign  RIF.read_data[LSB+:WIDTH] = FIF.read_data;
    assign  RIF.value[LSB+:WIDTH]     = FIF.value;
end

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

No branches or pull requests

2 participants