Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add Module.print_hierarchy #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions migen/fhdl/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,27 @@ def do_finalize(self):
def do_exit(self, *args, **kwargs):
for name, submodule in self._submodules:
submodule.do_exit(*args, **kwargs)

def print_hierarchy(self, indent=4, include_anon=False):
"""Prints a hierarchy tree for the Module.

This method iterates over each submodule in the design and prints out an
indented hierarchy. By default it ignores any anonymous modules but this can be
overridden by passing include_anon=True.

Note that by default, with include_anon=False, all hierarchy below an anonymous
module will be skipped. It is assumed that the user will only use anonymous
instantiations for leaf cells such as CSRs, synchronisers, etc where we don't
particularly care about printing them in a hierarchy view.

"""
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__))
shareefj marked this conversation as resolved.
Show resolved Hide resolved
submodule.print_hierarchy(indent+4, include_anon)