-
Notifications
You must be signed in to change notification settings - Fork 68
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
Publish Surelog builds to PyPi? #2635
Comments
Although Surelog Python API has some use for writing pre-processing and parser AST-level rules (Following the Antlr grammar), |
@alaindargelas Need more information on what exactly do you mean by UHDM Python binding? You want to expose all of UHDM thru' parallel classes in Python? |
Correct, that should be done automatically by code generation like the rest of UHDM. |
Let me investigate this. I have never done extensive work on python bindings. I know AWS Boto3 does a pretty decent job. I will study that as an example. Do you know of any other libraries/projects that does anything similar (not necessarily in context to HDL)?? |
Surelog does C to Python binding itself for the antlr AST api using the python script you just ported from TCL along with swig. it should be a very similar approach, there is no need for additional dependency in my mind. From the UHDM model, you auto generate what is required for swig to do the binding to Python. |
If you create a file uhdm.i and saveit in UHDM/build/generated
cd UHDM/build/generated If we use syntax in the C++ headers of UHDM that Swig understands, then the Python wrappers come for "free". |
A more complete .i file produces a Python wrapper that makes sense, it contains the classes enumerated.
|
The other part Surelog that sould be wrapped in Python is the design parsing and command line options "The main". a Python session should be:
|
Appreciate the pointers. I will try the approach. It might not be for the next few weeks though. Current focus is on LS and Linter implementation. |
No problem, I don't think there is any urgency. For SWIG to be able to read the UHDM headers "as-is", It think some simple
in a few places like some of the RTTI class members, and the "final" keyword for classes will be enough. So the same exact headers can be used for the C++ compilation and the SWIG python binding generation. |
BTW, are you going to contribute back the Linter or the LS? Have you noted the UhdmLinter and SynthSubset optional classes in UHDM? |
Moving the LS conversation to #1712 |
@hzeller FYI |
With the following SWIG file uhdm.i ran in UHDM/include:
swig -I. -python -o uhdm_wrap.c uhdm.i You can produce the VPI API in Python. Link uhdmpython.so and uhdm.so in Python, plus a little wrapper for loading the surelog.uhdm and you should have the python binding of the "C" VPI UHDM. The C++ is much more work as described above. |
I try to follow the provided instruction but it failed :
I found suspicious that even a dummy implementation of Is the proposed swig file correct ? |
UHDM & Surelog packages are not published. This was a discussion about approach and was never followed through. Work on this will begin sometime in near future. |
Hello In my trial to follow:
UHDM.i:
swig_main.h:
swig_main.cpp:
The swig cpp wrapper does not compile at my end with a weird error: related to this line of code
This error seems to me an inconsistency in swig generated code... I am using Ubuntu : Ubuntu 22.10, python 3.10.7, swig 4.0.2. I should retry after updating swig to a later version. |
Problem remain with swig 4.1.0 |
Could you post your changes as a draft PR for me to try locally? Optionally, push them to your own fork and give me access. |
@hs-apotell The 1. Edit: after Thomasb81/UHDM@1338905 commit
|
Add these lines before the
|
BTW, there are lot of examples here on how to use swig for Python code generation. https://github.com/swig/swig under Examples/python directory. Templated code can be challenging so hopefully, the resource can assist you. You can always post more questions on the forum. |
This code does not make sense to me ... but solve the compilation problem. |
In the
This prototype produce following error at compilation time in there respective wrapper generated code:
with in the generated code:
It seems to me that the generated C++ code is wrong as claim by the compiler. Support of va_list in swig 4.0 What is the difference of |
You can comment out both functions in vpi_user.h, just leave a comment that they pose an issue with the SWIG generation, neither have an implementation in C at this point. They are not really needed. That are part of the VPI standard put one can print object content any way they choose to. |
I find an elegant way to exclude them with |
I am confuse... does SV API suppose to be usable to modify or create uhdm db or is the intent is limited to get api ? |
The VPI API (C API) is ready only (as it is supposed to be). We can add a couple of new functions (Should not be in vpi_user.h) to
|
Actually the solution provide by chipsalliance/UHDM#895, is to map of uhdm model class because the vpi api only does not allow to update the uhdm db for usecase where uhdm db need to be change (elaboration step, or design mutation)
This is another enhancement that could probably be considered in the future. But it need probably to be done in Surelog not in UHDM. |
I missed some comments here. Yes, there could be some use cases for mutation, but that also could be accommodated by creating a few new "C" routines that edit the model. At any rate, we will know soon enough if chipsalliance/UHDM#895 succeed. If it does, there are still users who would rather use the Standard documented VPI "C" API rather than the C++ one. Basically exposing sv_vpi_user.h to Python. |
As Surelog has a complete Python API, does it make sense for Surelog to be available via PyPi? If so it would be great to automatically publish PyPi packages.
The text was updated successfully, but these errors were encountered: