migen
migen copied to clipboard
feature: add Module.print_hierarchy
Adding a new Module method that prints the hierarchy. Useful for visualising the structure of a module.
I'm adding this PR mainly to start a conversation about where is best to do this sort of thing. I'd like to be able to pretty print some sort of hierarchy view of a design. It would be nice to be able to do something similar to how tree
prints directory hierarchies but I haven't looked further that the simple indentation shown in this PR.
Should this go in the Module
class or in the verilog
module or in some new module?
There do seem to be some nice options for pretty printing this but I'll leave that for another day. This simple indentation works for now I think. https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python
@sbourdeauducq Did the last push do what you were implying?
It's better, there is still an issue with indent handling, just do the *4 multiplication at print time.
Not sure what you mean. The multiplication is done at print time. Did you mean something else?
if indent == 4:
print(self.__class__.__name__)
for name, submodule in self._submodules:
if name is None:
if not include_anon:
# all hierarchy below an anonymous module is skipped
continue
name = "anon"
print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
submodule.print_hierarchy(indent+4, include_anon)
The 4
++verbosity