-
Notifications
You must be signed in to change notification settings - Fork 72
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
tool: tblgen-to-py script #3210
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3210 +/- ##
=======================================
Coverage ? 89.91%
=======================================
Files ? 440
Lines ? 55279
Branches ? 8624
=======================================
Hits ? 49705
Misses ? 4149
Partials ? 1425 ☔ View full report in Codecov by Sentry. |
Would it likely be better to go with "script that prints out some python code" than what I've done here? Programatically generating the classes seems to introduce some difficulties and makes caching harder |
I think that would make a lot of sense. |
Just pushed version 2 which just creates a python file. Think this is close to being ready, just need to work out how to test it |
Struggling to come up with a way to test this, as I'd ideally like a filecheck test similar to the one for
Would love to hear any good ideas for this. |
Either this or a manually crafted json file that tests the key features? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't get through all the code yet, but can you add some more comments, and maybe a readme for this tool? Oh, also some minimal tests would be super neat to see what it actually does!
|
||
@dataclass | ||
class TblgenLoader: | ||
js: Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a docstring to the class (and this attribute) to explain roughly what it does?
@alexarice I think hand-crafting a json example would a good way to test this |
I could remove all the argument constraints for a first pass, which would simplify it a little
I agree with the end goal. At least short term my problems with it are:
|
Yeah I agree, let's do this right now, we'll see later if IRDL turns out to be usable enough to make it pass through it ;) |
Think I've fixed up all the comments, was there a consensus on trying to split this up into separate PRs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual dialect definition is missing, do we want to include it? Also, the dialect name is missing from all the ops.
It would be great to have more documentation about this, like how the json was generated
tests/tblgen_to_py/test_tblgen.py
Outdated
output = subprocess.run( | ||
[ | ||
"xdsl-tblgen", | ||
"-i", | ||
"tests/tblgen_to_py/test.json", | ||
], | ||
capture_output=True, | ||
text=True, | ||
) | ||
|
||
out_str = output.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to go via subprocess here now that we've separated the command-line parsing from the generation? This feels more like an integration test than a unit test to me...
xdsl/tools/tblgen_to_py.py
Outdated
if output_file is not None: | ||
with open(output_file, "w") as out_file: | ||
print(json.dumps(culled), file=out_file) | ||
else: | ||
print(json.dumps(culled)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it feels like the caller should do this dance, and the out parameter here should be IO[str] | None
tests/tblgen_to_py/test.py
Outdated
|
||
@irdl_attr_definition | ||
class Test_SingletonAType(ParametrizedAttribute, TypeAttribute): | ||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well also drop these empty docstrings
Ready for review again |
This is the start of a "tblgen-to-py" script for reading the json output of `llvm-tblgen --dump-json` and creating an xdsl dialect.
This is the start of a "tblgen-to-py" script for reading the json output of
llvm-tblgen --dump-json
and creating an xdsl dialect. I would like some help/advice on how to best integrate this into the existing tooling. I think something similar to the "irdl-to-pyrdl" script would be good, where the irdl file is used to create a python file.I've included some json files for reference, but as they are huge I expect we would want to cache the result of this script in practice.
Quite a few constraints are missing at the moment but this can be iterated on.