From f4bd3f1e0b825f14d208cdb2bc48e9be9cb0e228 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Sat, 14 Dec 2024 19:16:53 +0100 Subject: [PATCH] [topgen] Deepcopy parameter when mangeling Otherwise, the same parameter of a difference instance would be overwritten Signed-off-by: Robert Schilling --- util/topgen/intermodule.py | 15 +++++++++++++-- util/topgen/merge.py | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/util/topgen/intermodule.py b/util/topgen/intermodule.py index 6bcc339e163f1..0659da25999bb 100644 --- a/util/topgen/intermodule.py +++ b/util/topgen/intermodule.py @@ -778,8 +778,19 @@ def check_intermodule(topcfg: Dict, prefix: str) -> int: err, rsp_struct = check_intermodule_field(rsp_struct) error += err - total_width += rsp_struct["width"] - widths.append(rsp_struct["width"]) + if isinstance(rsp_struct["width"], Parameter): + param = rsp_struct["width"] + if param.expose: + # If it's a top-level exposed parameter, we need to find definition from there + module = lib.get_module_by_name(topcfg, req_m) + width = int(module['param_decl'].get(param.name, rsp_struct["width"].default)) + else: + width = int(req_struct["width"].default) + else: + width = rsp_struct["width"] + + total_width += width + widths.append(width) # Type check # If no package was declared, it is declared with an empty string diff --git a/util/topgen/merge.py b/util/topgen/merge.py index 5906d79f1fd01..3da17cd9372c1 100644 --- a/util/topgen/merge.py +++ b/util/topgen/merge.py @@ -173,6 +173,11 @@ def elaborate_instance(instance, block: IpBlock): if isinstance(s['width'], Parameter): for p in instance["param_list"]: if p['name'] == s['width'].name: + # When mangeling the name, we first need to deep copy the param. Otherwise, we + # reference always the same single parameter. If there are multiple instances + # having the same parameter, we would overwrite the previously mangled param + # of another instance + s['width'] = deepcopy(s['width']) s['width'].name_top = p['name_top'] # An instance must either have a 'base_addr' address or a 'base_addrs'