chipsalliance / UHDM

Universal Hardware Data Model. A complete modeling of the IEEE SystemVerilog Object Model with VPI Interface, Elaborator, Serialization, Visitor and Listener. Used as a compiled interchange format in between SystemVerilog tools. Compiles on Linux gcc, Windows msys2-gcc & msvc, OsX
Apache License 2.0
186 stars 38 forks source link

Obtaining module handle based on the full name of the instance #1080

Open mysoreanoop opened 2 days ago

mysoreanoop commented 2 days ago

For a separate/temporary need, is there a way to obtain a submodule instance's vpiHandle based on the full name of the submodule instance?

I have parsed the submodules and have stored their full names in a list. At some point later, I need to recurse into the submodule (conditionally).

I tried saving vpiHandle in the list instead, but it does not seem to link back to the same node when used later (perhaps because I release the handles in the middle, I don't know).

I know the alternative is to recurse into every submodule and match the full names, but that feels inefficient.

Thomasb81 commented 2 days ago

I tried saving vpiHandle in the list instead, but it does not seem to link back to the same node when used later (perhaps >because I release the handles in the middle, I don't know).

It is forbidden to continue to use an handle after having free. See handle like a pointer which is return by malloc function in C. Once you free the pointer and the associate memory space, the space is return to the system and could be recycle for another malloc call in your application.

If keeping track of handle to free them only when you do not need them anymore is too complicate to do it yourself, you need to consider smartptr. Or you can use the python UHDM api : python will do that for you when no more reference on the handle exist in user application, the python runtime will free it.