Skip to content

frontend: Add first operators for the python dialect as well as code generation from AST - #6243

Draft
Saderfing wants to merge 15 commits into
xdslproject:mainfrom
Saderfing:sader/python_dialect
Draft

frontend: Add first operators for the python dialect as well as code generation from AST#6243
Saderfing wants to merge 15 commits into
xdslproject:mainfrom
Saderfing:sader/python_dialect

Conversation

@Saderfing

@Saderfing Saderfing commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Python dialect frontend

Implementing the first python attributs (types) and operators in xDSL including:

  • ConstantOp
  • FuncOp
  • ReturnOp
  • CastOp
  • CallOp
  • PassOp

Implement a code generation from ast representation to the python dialect.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.96143% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.02%. Comparing base (40eddd4) to head (1326d6f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
xdsl/frontend/pydialect/pyfrontend.py 72.92% 41 Missing and 8 partials ⚠️
xdsl/dialects/py/ops.py 75.24% 22 Missing and 3 partials ⚠️
xdsl/dialects/py/attrs.py 80.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6243      +/-   ##
==========================================
- Coverage   87.07%   87.02%   -0.05%     
==========================================
  Files         433      438       +5     
  Lines       65231    65569     +338     
  Branches     7464     7490      +26     
==========================================
+ Hits        56798    57060     +262     
- Misses       6863     6931      +68     
- Partials     1570     1578       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread xdsl/dialects/py.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in xdsl/dialects/py.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xdsl/dialects/py/ directory already exist, should I use it ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I forgot about that! That dialect models things closer to the bytecode, whereas your dialect is closer to the high-level AST. I'm now convinced that somewhere in the middle is best. I would probably first refactor the py directory to split it into ops and attrs kind of like riscv, and then add your code there, probably either replacing or extending those classes. The ObjectType is basically your Type, but I prefer the ObjectType name, for example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add the name of the class to it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using part of it.

  • PyOperation and PyModuleOp seems nice

  • PyConstOp is not as general as the new PyConstantOp

  • PyBinOp will not do as we will use dunders

Do you agree ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking a bit more, it feels like we might actually want two separate dialects. The existing py dialect should be renamed to pybytecode and your dialect should be the new py. I would not change the pybytecode dialect at all, just move it to pybytecode.py in dialects.

Comment thread xdsl/dialects/py.py
@@ -0,0 +1,267 @@
from __future__ import annotations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a file-level doc string describing what the aims are of this dialect. Short is great for now.

Comment thread xdsl/dialects/py.py
Comment on lines +62 to +63
def constr() -> AttrConstraint:
return AnyAttr()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should test for contents of data, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also for the type?

Comment thread xdsl/dialects/py.py


@irdl_attr_definition
class ConstantValue(Data[Any]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this actually can only print and parse strings?

@Saderfing
Saderfing force-pushed the sader/python_dialect branch from d692462 to 71e7b62 Compare July 29, 2026 12:07
Contains a name field to show its content
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

Successfully merging this pull request may close these issues.

2 participants