Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Nov 8, 2023

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?

continue
name = "anon"
print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
self._iter_submodules(submodule, indent=indent+4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call print_hierarchy instead and merge the two functions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed _iter_submodules.

@ghost ghost force-pushed the feature/print_hierarchy branch from 64f1182 to f5b678e Compare November 8, 2023 10:43
@ghost
Copy link
Author

ghost commented Nov 8, 2023

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

continue
name = "anon"
print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
self.print_hierarchy(submodule, indent+4, include_anon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just submodule.print_hierarchy and remove the module argument?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see what you're getting at.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix that I think did what you wanted. Each submodule is called in turn and we call the submodule.print_hierarchy(indent+4, include_anon).

Adding a new Module method that prints the hierarchy. Useful for visualising
the structure of a module.
@ghost ghost force-pushed the feature/print_hierarchy branch from f5b678e to 1303e93 Compare November 8, 2023 11:15
@ghost
Copy link
Author

ghost commented Nov 29, 2023

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

@sbourdeauducq
Copy link
Member

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

@ghost
Copy link
Author

ghost commented Nov 30, 2023

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)

@sbourdeauducq
Copy link
Member

The 4

@ghost
Copy link
Author

ghost commented Dec 1, 2023

++verbosity

@ghost ghost closed this by deleting the head repository Nov 8, 2025
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant