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 *
|
from litex.gen import *
|
||||||
|
|
||||||
|
|
||||||
# LiteX Hierarchy Explorer -------------------------------------------------------------------------
|
# LiteX Hierarchy Explorer -------------------------------------------------------------------------
|
||||||
|
|
||||||
class LiteXHierarchyExplorer:
|
class LiteXHierarchyExplorer:
|
||||||
|
tree_ident = "│ "
|
||||||
|
tree_entry = "└─── "
|
||||||
|
|
||||||
def __init__(self, top, depth=None):
|
def __init__(self, top, depth=None):
|
||||||
self.top = top
|
self.top = top
|
||||||
self.depth = depth
|
self.depth = depth
|
||||||
|
|
||||||
def get_tree(self, module, ident=0, with_modules=True, with_instances=True):
|
def get_tree(self, module, ident=0, with_modules=True, with_instances=True):
|
||||||
r = ""
|
r = ""
|
||||||
|
names = set()
|
||||||
|
names.add(None)
|
||||||
# Modules / SubModules.
|
# Modules / SubModules.
|
||||||
for name, mod in module._submodules:
|
for name, mod in module._submodules:
|
||||||
if name is None:
|
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:
|
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):
|
if (self.depth is None) or (ident < self.depth):
|
||||||
r += self.get_tree(mod, ident + 1)
|
r += self.get_tree(mod, ident + 1)
|
||||||
|
|
||||||
|
@ -36,11 +44,13 @@ class LiteXHierarchyExplorer:
|
||||||
if s in v._fragment.specials:
|
if s in v._fragment.specials:
|
||||||
show = False
|
show = False
|
||||||
if show:
|
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
|
return r
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
r = "\n"
|
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 += self.get_tree(self.top)
|
||||||
|
r += f"{colorer('*', 'cyan')}: Generated name.\n"
|
||||||
|
r += f"{colorer('*', 'yellow')}: BlackBox.\n"
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in New Issue