Add user parameters to regblock package. #112

This commit is contained in:
Alex Mykyta
2025-04-10 22:16:13 -07:00
parent 0a9a3ad51e
commit 48ae215eda
6 changed files with 65 additions and 0 deletions

View File

@@ -49,6 +49,23 @@ class Hwif:
return self.exp.ds.top_node return self.exp.ds.top_node
def get_extra_package_params(self) -> str:
lines = []
for param in self.top_node.inst.parameters:
value = param.get_value()
if isinstance(value, int):
lines.append(
f"localparam {param.name} = {SVInt(value)};"
)
elif isinstance(value, str):
lines.append(
f"localparam {param.name} = {value};"
)
return "\n".join(lines)
def get_package_contents(self) -> str: def get_package_contents(self) -> str:
""" """
If this hwif requires a package, generate the string If this hwif requires a package, generate the string

View File

@@ -7,6 +7,8 @@ package {{ds.package_name}};
localparam {{ds.module_name.upper()}}_MIN_ADDR_WIDTH = {{ds.addr_width}}; localparam {{ds.module_name.upper()}}_MIN_ADDR_WIDTH = {{ds.addr_width}};
localparam {{ds.module_name.upper()}}_SIZE = {{SVInt(ds.top_node.size)}}; localparam {{ds.module_name.upper()}}_SIZE = {{SVInt(ds.top_node.size)}};
{{hwif.get_extra_package_params()|indent}}
{{hwif.get_package_contents()|indent}} {{hwif.get_package_contents()|indent}}
endpackage endpackage
{# (eof newline anchor) #} {# (eof newline anchor) #}

View File

View File

@@ -0,0 +1,11 @@
addrmap top #(
longint N_REGS = 1,
longint REGWIDTH = 32,
string NAME = "abcd"
) {
reg reg_t {
regwidth = REGWIDTH;
field {sw=rw; hw=na;} f[REGWIDTH] = 1;
};
reg_t regs[N_REGS];
};

View File

@@ -0,0 +1,8 @@
{% extends "lib/tb_base.sv" %}
{% block seq %}
{% sv_line_anchor %}
assert(regblock_pkg::N_REGS == {{testcase.n_regs}});
assert(regblock_pkg::REGWIDTH == {{testcase.regwidth}});
assert(regblock_pkg::NAME == "{{testcase.name}}");
{% endblock %}

View File

@@ -0,0 +1,27 @@
from parameterized import parameterized_class
from ..lib.sim_testcase import SimTestCase
from ..lib.test_params import get_permutations
PARAMS = get_permutations({
"n_regs" : [1, 2],
"regwidth" : [8, 16],
"name" : ["hello", "world"],
})
@parameterized_class(PARAMS)
class TestRetimedFanin(SimTestCase):
n_regs = 20
regwidth = 32
name = "xyz"
@classmethod
def setUpClass(cls):
cls.rdl_elab_params = {
"N_REGS": cls.n_regs,
"REGWIDTH": cls.regwidth,
"NAME": f'"{cls.name}"',
}
super().setUpClass()
def test_dut(self):
self.run_test()