diff --git a/util/topgen/lib.py b/util/topgen/lib.py index 91c928aa5186a..9286ea806468e 100644 --- a/util/topgen/lib.py +++ b/util/topgen/lib.py @@ -244,6 +244,14 @@ def get_pad_list(padstr): return pads +def idx_of_last_module_with_params(top): + last = -1 + for idx, module in enumerate(top["module"]): + if len(module["param_list"]): + last = idx + return last + + # Template functions def ljust(x, width): return "{:<{width}}".format(x, width=width) diff --git a/util/topgen/templates/toplevel.sv.tpl b/util/topgen/templates/toplevel.sv.tpl index 854370ee607a1..9035ed6fc5e38 100644 --- a/util/topgen/templates/toplevel.sv.tpl +++ b/util/topgen/templates/toplevel.sv.tpl @@ -37,6 +37,8 @@ for m in top['memory']: if m['type'] == 'rom': has_toplevel_rom = True +last_modidx_with_params = lib.idx_of_last_module_with_params(top) + %>\ `include "prim_assert.sv" @@ -59,12 +61,15 @@ module top_${top["name"]} #( p_lhs = f'{p_type_word}{p_exp["name_top"]}' p_rhs = p_exp['default'] + + params_follow = not loop.last or loop.parent.index < last_modidx_with_params + comma_char = ',' if params_follow else '' %>\ % if 12 + len(p_lhs) + 3 + len(p_rhs) + 1 < 100: - parameter ${p_lhs} = ${p_rhs}${"" if loop.parent.last & loop.last else ","} + parameter ${p_lhs} = ${p_rhs}${comma_char} % else: parameter ${p_lhs} = - ${p_rhs}${"" if loop.parent.last & loop.last else ","} + ${p_rhs}${comma_char} % endif % endfor % endfor