Skip to content

Commit

Permalink
feat(groups): Accept ungrouped entries in confs, blocks and csrs.
Browse files Browse the repository at this point in the history
Related to IObundle#83
  • Loading branch information
arturum1 committed Nov 24, 2024
1 parent 283b98c commit a37d92f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
15 changes: 13 additions & 2 deletions py2hwsw/lib/hardware/iob_csrs/scripts/iob_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ def __post_init__(self):
fail_with_msg("CSR group name is not set", ValueError)


def create_csr_group(*args, regs=[], **kwargs):
def create_csr_group(*args, **kwargs):
"""Creates a new csr group object"""

group_kwargs = kwargs
regs = kwargs.pop("regs", None)
# If kwargs provided a single reg instead of a group, then create a general group for it.
if regs is None:
regs = [kwargs]
group_kwargs = {
"name": "general_operation",
"descr": "General operation group",
}

# Convert user reg dictionaries into 'iob_csr' objects
csr_obj_list = convert_dict2obj_list(regs, iob_csr)
csr_group = iob_csr_group(*args, regs=csr_obj_list, **kwargs)
csr_group = iob_csr_group(regs=csr_obj_list, **group_kwargs)
return csr_group
83 changes: 42 additions & 41 deletions py2hwsw/scripts/iob_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,34 @@ def __post_init__(self):


attrs = [
"name",
[
"-c",
"blocks",
{"nargs": "+"},
["name:width"],
], # FIXME: According to block parameters
"core_name",
"instance_name",
["-p", "parameters", {"nargs": "+"}, "pairs"],
["-c", "connect", {"nargs": "+"}, "pairs"],
["--no_autoaddr", "autoaddr", {"action": "store_false"}],
["--rw_overlap", "rw_overlap", {"action": "store_true"}],
["--csr_if", "csr_if"],
{
"--csr-group&csrs": [
"name",
{
"-r&regs": [
"name:n_bits",
["-t", "type"],
["--rst_val", "rst_val"],
["--addr", "addr", {"type": int}],
["--log2n_items", "log2n_items"],
["--no_autoreg", "autoreg", {"action": "store_false"}],
],
},
]
},
["-b", "blocks", {"nargs": "+"}],
]


@str_to_kwargs(attrs)
def create_block_group(core, *args, blocks=[], **kwargs):
def create_block_group(core, *args, **kwargs):
"""Creates a new block group object and adds it to the core's block list
param core: core object
"""
Expand All @@ -49,57 +65,42 @@ def create_block_group(core, *args, blocks=[], **kwargs):
# Ensure 'blocks' list exists
core.set_default_attribute("blocks", [])

group_kwargs = kwargs
blocks = kwargs.pop("blocks", None)
# If kwargs provided a single block instead of a group, then create a general group for it.
if blocks is None:
blocks = [kwargs]
group_kwargs = {
"name": "general_operation",
"descr": "General operation group",
}

block_obj_list = []
if type(blocks) is list:
# Convert user blocks dictionaries into 'iob_block' objects
for block in blocks:
block_obj_list.append(create_block(core, **block))
block_obj = create_block(core, **block)
if block_obj:
block_obj_list.append(block_obj)
else:
fail_with_msg(
f"blocks attribute must be a list. Error at block group \"{kwargs.get('name', '')}\".\n{blocks}",
f"blocks attribute must be a list. Error at block group \"{group_kwargs.get('name', '')}\".\n{blocks}",
TypeError,
)

assert_attributes(
iob_block_group,
kwargs,
error_msg=f"Invalid {kwargs.get('name', '')} block group attribute '[arg]'!",
group_kwargs,
error_msg=f"Invalid {group_kwargs.get('name', '')} block group attribute '[arg]'!",
)

block_group = iob_block_group(*args, blocks=block_obj_list, **kwargs)
block_group = iob_block_group(blocks=block_obj_list, **group_kwargs)
core.blocks.append(block_group)
except Exception:
add_traceback_msg(f"Failed to create block_group '{kwargs['name']}'.")
add_traceback_msg(f"Failed to create block/group '{kwargs['name']}'.")
raise


attrs = [
"core_name",
"instance_name",
["-p", "parameters", {"nargs": "+"}, "pairs"],
["-c", "connect", {"nargs": "+"}, "pairs"],
["--no_autoaddr", "autoaddr", {"action": "store_false"}],
["--rw_overlap", "rw_overlap", {"action": "store_true"}],
["--csr_if", "csr_if"],
{
"--csr-group&csrs": [
"name",
{
"-r&regs": [
"name:n_bits",
["-t", "type"],
["--rst_val", "rst_val"],
["--addr", "addr", {"type": int}],
["--log2n_items", "log2n_items"],
["--no_autoreg", "autoreg", {"action": "store_false"}],
],
},
]
},
]


@str_to_kwargs(attrs)
def create_block(core, core_name: str = "", instance_name: str = "", **kwargs):
"""Create an instante of a module, but only if we are not using a
project wide special target (like clean)
Expand Down
29 changes: 21 additions & 8 deletions py2hwsw/scripts/iob_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,53 @@ def __post_init__(self):
fail_with_msg("Conf group name is not set", ValueError)


# attrs = ["name", ["-t", "type"], ["-v", "val"], ["-m", "min"], ["-M", "max"]]
attrs = [
"name",
["-c", "confs", {"nargs": "+"}, ["name:width"]], # FIXME: According to above
["-t", "type"],
["-v", "val"],
["-m", "min"],
["-M", "max"],
["-c", "confs", {"nargs": "+"}],
]


@str_to_kwargs(attrs)
def create_conf_group(core, *args, confs=[], **kwargs):
def create_conf_group(core, *args, **kwargs):
"""Creates a new conf group object and adds it to the core's conf list
param core: core object
"""
try:
# Ensure 'confs' list exists
core.set_default_attribute("confs", [])

group_kwargs = kwargs
confs = kwargs.pop("confs", None)
# If kwargs provided a single conf instead of a group, then create a general group for it.
if confs is None:
confs = [kwargs]
group_kwargs = {
"name": "general_operation",
"descr": "General operation group",
}

conf_obj_list = []
if type(confs) is list:
# Convert user confs dictionaries into 'iob_conf' objects
conf_obj_list = convert_dict2obj_list(confs, iob_conf)
else:
fail_with_msg(
f"Confs attribute must be a list. Error at conf group \"{kwargs.get('name', '')}\".\n{confs}",
f"Confs attribute must be a list. Error at conf group \"{group_kwargs.get('name', '')}\".\n{confs}",
TypeError,
)

assert_attributes(
iob_conf_group,
kwargs,
error_msg=f"Invalid {kwargs.get('name', '')} conf group attribute '[arg]'!",
group_kwargs,
error_msg=f"Invalid {group_kwargs.get('name', '')} conf group attribute '[arg]'!",
)

conf_group = iob_conf_group(*args, confs=conf_obj_list, **kwargs)
conf_group = iob_conf_group(confs=conf_obj_list, **group_kwargs)
core.confs.append(conf_group)
except Exception:
add_traceback_msg(f"Failed to create conf_group '{kwargs['name']}'.")
add_traceback_msg(f"Failed to create conf/group '{kwargs['name']}'.")
raise

0 comments on commit a37d92f

Please sign in to comment.