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

Do children() and descendants() return a deep copy? #256

Closed
jeras opened this issue Mar 2, 2025 · 3 comments
Closed

Do children() and descendants() return a deep copy? #256

jeras opened this issue Mar 2, 2025 · 3 comments

Comments

@jeras
Copy link

jeras commented Mar 2, 2025

I tried to compare nodes and I noticed separate calls to children() do not return the same objects. Are they deep copies? Is there a specific reason for this implementation?

As an example, two consecutive calls return nodes with different addresses.

            print(node, node.children())
            print(node, node.children())
<AddrmapNode example32 at 0x78aa3d9a1d00> [<RegfileNode example32.tests at 0x78aa3c3d51c0>, <RegfileNode example32.uart0 at 0x78aa3c3d7590>, <RegNode example32.conf at 0x78aa3c3d6ba0>, <RegNode example32.ctrl at 0x78aa3c17d370>, <RegNode example32.stat at 0x78aa3c17c530>, <RegNode example32.ufixed at 0x78aa3c17c380>]
<AddrmapNode example32 at 0x78aa3d9a1d00> [<RegfileNode example32.tests at 0x78aa3c208f80>, <RegfileNode example32.uart0 at 0x78aa3c550ef0>, <RegNode example32.conf at 0x78aa3c3d51c0>, <RegNode example32.ctrl at 0x78aa3c3d6ba0>, <RegNode example32.stat at 0x78aa3c233ef0>, <RegNode example32.ufixed at 0x78aa3c17c920>]
@jeras
Copy link
Author

jeras commented Mar 2, 2025

I had a look at the source code. Let me start by saying I do not have experience with factories so my interpretation of the code is as it is.

Apparently the component hierarchy is static while the node hierarchy is created dynamically during a call to children().

Is there a reliable (preferred) method for comparing two nodes. I would like to know if the two nodes are at the same position in the node tree. I probably could compare paths, and at least for my case, comparing the absolute address seems a good choice. Still is there a preferred way for two nodes are the same node?

@jeras
Copy link
Author

jeras commented Mar 2, 2025

I found it, https://systemrdl-compiler.readthedocs.io/en/stable/api/node.html#systemrdl.node.Node.__eq__

@jeras jeras closed this as completed Mar 2, 2025
@amykyta3
Copy link
Member

amykyta3 commented Mar 3, 2025

Yes using the == operator is the preferred way to check node equivalence.

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

No branches or pull requests

2 participants