Skip to content

Commit

Permalink
gen/fhdl/instance: Ident Parameters/IOs on max length of names.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Nov 3, 2023
1 parent 4627e89 commit 0090239
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions litex/gen/fhdl/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
from migen.fhdl.verilog import _printexpr as verilog_printexpr
from migen.fhdl.specials import *

# Helpers ------------------------------------------------------------------------------------------

def get_max_name_length(ios):
r = 0
for io in ios:
if len(io.name) > r:
r = len(io.name)
return r

# LiteX Instance Verilog Generation ----------------------------------------------------------------

def _instance_generate_verilog(instance, ns, add_data_file):
Expand All @@ -26,6 +35,7 @@ def _instance_generate_verilog(instance, ns, add_data_file):
# Instance Parameters.
# --------------------
parameters = list(filter(lambda i: isinstance(i, Instance.Parameter), instance.items))
ident = get_max_name_length(parameters)
if parameters:
r += "#(\n"
first = True
Expand All @@ -34,7 +44,7 @@ def _instance_generate_verilog(instance, ns, add_data_file):
if not first:
r += ",\n"
first = False
r += f"\t.{p.name}("
r += f"\t.{p.name}{' '*(ident-len(p.name))} ("
# Constant.
if isinstance(p.value, Constant):
r += verilog_printexpr(ns, p.value)[0]
Expand All @@ -61,7 +71,8 @@ def _instance_generate_verilog(instance, ns, add_data_file):
inputs = list(filter(lambda i: isinstance(i, Instance.Input), instance.items))
outputs = list(filter(lambda i: isinstance(i, Instance.Output), instance.items))
inouts = list(filter(lambda i: isinstance(i, Instance.InOut), instance.items))
first = True
first = True
ident = get_max_name_length(inputs + outputs + inouts)
for io in (inputs + outputs + inouts):
if not first:
r += ",\n"
Expand All @@ -74,7 +85,7 @@ def _instance_generate_verilog(instance, ns, add_data_file):
name_inst = io.name
name_design = verilog_printexpr(ns, io.expr)[0]
first = False
r += f"\t.{name_inst}({name_design})"
r += f"\t.{name_inst}{' '*(ident-len(name_inst))} ({name_design})"
if not first:
r += "\n"

Expand Down

0 comments on commit 0090239

Please sign in to comment.