Index
py
This module contains the definition of the Python semantics dialect.
We only guarantee preservation of most1 Python semantics, but do not guarantee preservation of AST or bytecode.
The Python dialect is under heavy development, and the definitions are not yet stable!
1. We assume no exceptions are raised in the code.
Py = Dialect('py', [PyBinOp, PyConstOp], [PyObjectType])
module-attribute
PyObjectType
dataclass
Bases: ParametrizedAttribute, TypeAttribute
Python opaque type
Source code in xdsl/dialects/py/__init__.py
35 36 37 38 39 | |
name = 'py.object'
class-attribute
instance-attribute
PyOperation
dataclass
Bases: IRDLOperation
Source code in xdsl/dialects/py/__init__.py
47 48 | |
PyModuleOp
dataclass
Bases: PyOperation
Python code is organized into modules and functions.
Modules are the top-level code.
Functions are self-explanatory.
For example if you have the following MLIR:
%0 = py.const 0 %1 = py.const 1 %2 = py.binop "add" %0 %1
We mean the following Python code: _0 = 1 _1 = 1 _2 = _0 + _1
Source code in xdsl/dialects/py/__init__.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
name = 'py.module'
class-attribute
instance-attribute
body = region_def()
class-attribute
instance-attribute
PyConstOp
Bases: PyOperation
x = CONST
Source code in xdsl/dialects/py/__init__.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
name = 'py.const'
class-attribute
instance-attribute
assembly_format = '$const attr-dict'
class-attribute
instance-attribute
const = prop_def(IntegerAttr[I64])
class-attribute
instance-attribute
res = result_def(PyObjectType())
class-attribute
instance-attribute
__init__(const: IntegerAttr[I64])
Source code in xdsl/dialects/py/__init__.py
89 90 | |
PyBinOp
Bases: PyOperation
x BINOP y
Source code in xdsl/dialects/py/__init__.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
name = 'py.binop'
class-attribute
instance-attribute
lhs = operand_def(PyObjectType())
class-attribute
instance-attribute
rhs = operand_def(PyObjectType())
class-attribute
instance-attribute
res = result_def(PyObjectType())
class-attribute
instance-attribute
op = prop_def(StringAttr)
class-attribute
instance-attribute
assembly_format = '$op $lhs $rhs attr-dict'
class-attribute
instance-attribute
__init__(op: StringAttr, lhs: Operand, rhs: Operand)
Source code in xdsl/dialects/py/__init__.py
106 107 108 109 110 111 112 113 114 | |