gen/fhdl/hierachy: Improve and give names to unnamed modules.
This commit is contained in:
parent
9321380f48
commit
f64dc2b799
|
@ -8,22 +8,30 @@ from migen import *
|
|||
|
||||
from litex.gen import *
|
||||
|
||||
|
||||
# LiteX Hierarchy Explorer -------------------------------------------------------------------------
|
||||
|
||||
class LiteXHierarchyExplorer:
|
||||
tree_ident = "│ "
|
||||
tree_entry = "└─── "
|
||||
|
||||
def __init__(self, top, depth=None):
|
||||
self.top = top
|
||||
self.depth = depth
|
||||
|
||||
def get_tree(self, module, ident=0, with_modules=True, with_instances=True):
|
||||
r = ""
|
||||
names = set()
|
||||
names.add(None)
|
||||
# Modules / SubModules.
|
||||
for name, mod in module._submodules:
|
||||
if name is None:
|
||||
name = "Unnamed"
|
||||
n = 0
|
||||
while name in names:
|
||||
name = mod.__class__.__name__.lower() + f"_{n}*"
|
||||
n += 1
|
||||
names.add(name)
|
||||
if with_modules:
|
||||
r += f"{'│ '*ident}├─── {colorer(name, 'cyan')} ({mod.__class__.__name__})\n"
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{colorer(name, 'cyan')} ({mod.__class__.__name__})\n"
|
||||
if (self.depth is None) or (ident < self.depth):
|
||||
r += self.get_tree(mod, ident + 1)
|
||||
|
||||
|
@ -36,11 +44,13 @@ class LiteXHierarchyExplorer:
|
|||
if s in v._fragment.specials:
|
||||
show = False
|
||||
if show:
|
||||
r += f"{'│ '*ident}├─── {colorer(s.of, 'bright')}\n"
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{colorer(s.of + '*', 'yellow')}\n"
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
r = "\n"
|
||||
r += f"{colorer(self.top.__class__.__name__, 'green')}\n"
|
||||
r += f"{colorer(self.top.__class__.__name__, 'underline')}\n"
|
||||
r += self.get_tree(self.top)
|
||||
r += f"{colorer('*', 'cyan')}: Generated name.\n"
|
||||
r += f"{colorer('*', 'yellow')}: BlackBox.\n"
|
||||
return r
|
||||
|
|
Loading…
Reference in New Issue