migen icon indicating copy to clipboard operation
migen copied to clipboard

feature: add Module.print_hierarchy

Open shareefj opened this issue 1 year ago • 6 comments

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?

shareefj avatar Nov 08 '23 08:11 shareefj

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

shareefj avatar Nov 08 '23 10:11 shareefj

@sbourdeauducq Did the last push do what you were implying?

shareefj avatar Nov 29 '23 10:11 shareefj

It's better, there is still an issue with indent handling, just do the *4 multiplication at print time.

sbourdeauducq avatar Nov 30 '23 01:11 sbourdeauducq

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)

shareefj avatar Nov 30 '23 10:11 shareefj

The 4

sbourdeauducq avatar Nov 30 '23 12:11 sbourdeauducq

++verbosity

shareefj avatar Dec 01 '23 10:12 shareefj