advice for dependency analysis? #1630
Replies: 6 comments 10 replies
-
|
I would expect the existing dependency tracking stuff to do what you're saying, so perhaps there is a bug to be fixed there. The existing logic looks at references in the parse tree, which you could replicate in pyslang easily enough. Using the AST should be unnecessary unless you want to figure out dependencies in some more specific way based on the results of elaboration / full name resolution. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your response.
I don't follow you very well. Isn't the AST the same as the parse tree? I will do some experimentation. If you are interested, here is my test case (just a modified version of code from an online library); it should find the following dependencies: |
Beta Was this translation helpful? Give feedback.
-
|
I see. That is useful, and is something I could utilize. Right now my build system uses all the files contained in the input include directories as dependencies. In other words, if any file changes in the directory supplied to the preprocessor, all dependencies using that directory will be recompiled even if that file is not actually used. Your solution is more efficient and more correct than what I am currently doing. Thanks for the explanation. |
Beta Was this translation helpful? Give feedback.
-
|
I looked at the getSortedDependencies method in Driver.cpp. Are you suggesting that this functionality could be duplicated using pyslang? I attempted this: but the resulting "trees" data structure does not appear to have the data exposed to Python that getSortedDependencies is using. Am I wrong about that? Maybe I am not running the compilation process correctly? For example, there is no "getMetadata()" method exposed to the elements of the "trees" list returned in the code above. I suppose I could attempt to write a C++ utility that would run getSortedDependencies and print the result. It looks like I could use code inthe "optionallyWriteDepFiles()" method as a model. But I would prefer to do this using only python code. |
Beta Was this translation helpful? Give feedback.
-
|
I have built a new C++ utility based on the code in getSortedDependencies. I am not familiar enough with exposing C++ classes to python to go the python route. The utility almost works. But it is not finding the "test_if" interface reference in the port map of the example I provided above. Is this because SV tools typically wait until elaboration to find data types like this? Do you have any suggestions? When I write out the CST, I see the following: Is there any existing method that will help me find this, or must I walk the tree myself? It might be tricky to distinguish this type from other types that do not represent external dependencies. |
Beta Was this translation helpful? Give feedback.
-
|
One more question: Is there a built in way to parse data from stdin, or would I need to add that? Other tools use a file name like "-" to indicate that stdin should be used. I suppose my need for this is because I do not have python bindings, so maybe that is an option too. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am exploring the possibility of using slang for a python-based HDL build system (I am currently using a different parser, but slang seems to have some advantages over my current solution). I need to extract the dependencies of an arbitrary SystemVerilog file. To do this correctly requires preprocessing and parsing the SV code. Is there a way use use slang/pyslang that you would recommend for this application? Do I need to parse the code and then walk the AST? I found the "runPreprocessor" method in the Driver.py namespace, and I am experimenting with that. But I would very much appreciate any advice you might have.
Note that I looked at the "-Mall" option of the slang executable, but the resulting output does not find most of the dependencies for my test case. Specifically, it misses package, interface and module dependencies. I would be happy to share my test case if it would be helpful.
Beta Was this translation helpful? Give feedback.
All reactions