Lowering
lowering
¶
FunctionDefinitionConstructor = Callable[[str, FunctionType, Region, Location], Operation]
module-attribute
¶
Construct the operation for a function from its name, signature, body and location.
ReturnConstructor = Callable[[Sequence[SSAValue], Location], Operation | None]
module-attribute
¶
Construct a return operation, or return None when no terminator is needed.
BINARY_OPERATOR_OVERLOADS = {'Add': '__add__', 'Sub': '__sub__', 'Mult': '__mul__', 'Div': '__truediv__', 'FloorDiv': '__floordiv__', 'Mod': '__mod__', 'Pow': '__pow__', 'LShift': '__lshift__', 'RShift': '__rshift__', 'BitOr': '__or__', 'BitXor': '__xor__', 'BitAnd': '__and__', 'MatMult': '__matmul__'}
module-attribute
¶
The method overloading each binary operator, by the name of its ast class.
COMPARISON_OPERATOR_OVERLOADS = {'Eq': '__eq__', 'Gt': '__gt__', 'GtE': '__ge__', 'Lt': '__lt__', 'LtE': '__le__', 'NotEq': '__ne__', 'In': '__contains__'}
module-attribute
¶
The method overloading each comparison operator, by the name of its ast class.
UNSUPPORTED_COMPARISON_OPERATORS = ('Is', 'IsNot', 'NotIn')
module-attribute
¶
The comparison operators without an overload: "is" and "is not" compare object
identity, which is not preserved, and "not in" is the negation of __contains__
rather than a method of its own.
ErrorConstructor = Callable[[str], Exception]
module-attribute
¶
Construct the error to raise from its message, located by the caller.
PyLowering
dataclass
¶
Lowers the py operations generated from a Python function to the operations
registered for them.
Operations are lowered in order, so the types of the operands of an operation are known when it is lowered: every value gets the type of the operation it becomes.
Source code in xdsl/frontend/pyast/lowering.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
type_converter: TypeConverter
instance-attribute
¶
The registries, and the globals in which names in the program are resolved.
file: str | None
instance-attribute
¶
Path of the file containing the program being processed.
function_definition_constructor: FunctionDefinitionConstructor = build_func
class-attribute
instance-attribute
¶
Construct the operation for each function.
return_constructor: ReturnConstructor = build_return
class-attribute
instance-attribute
¶
Construct return operations, optionally omitting the terminator.
variables: dict[str, Attribute] = field(default_factory=dict[str, Attribute], init=False)
class-attribute
instance-attribute
¶
The types of the variables of the function being lowered.
packs: dict[SSAValue, tuple[tuple[SSAValue, ...], Operation]] = field(default_factory=dict[SSAValue, tuple[tuple[SSAValue, ...], Operation]], init=False)
class-attribute
instance-attribute
¶
The py values that stand for a number of values other than one, such as the
results of a call or the elements of a tuple, with the operation that produced
them. These values can only be unpacked.
__init__(type_converter: TypeConverter, file: str | None, function_definition_constructor: FunctionDefinitionConstructor = build_func, return_constructor: ReturnConstructor = build_return) -> None
¶
lower(op: Operation) -> None
¶
Lower all py operations nested in op.
build_func(name: str, signature: FunctionType, body: Region, location: Location) -> func.FuncOp
¶
build_return(values: Sequence[SSAValue], location: Location) -> func.ReturnOp
¶
resolve_callee(type_converter: TypeConverter, callee: str, error: ErrorConstructor) -> Callable[..., Operation]
¶
The constructor of the operation registered for callee, the name of a function
or of a class method in the program's globals.
Source code in xdsl/frontend/pyast/lowering.py
resolve_binary_operator(type_converter: TypeConverter, op_name: str, lhs: SSAValue, rhs: SSAValue, error: ErrorConstructor) -> Operation
¶
The registered operation for the binary operator op_name on two values.
Source code in xdsl/frontend/pyast/lowering.py
resolve_comparison_operator(type_converter: TypeConverter, op_name: str, lhs: SSAValue, rhs: SSAValue, error: ErrorConstructor) -> Operation
¶
The registered operation for the comparison operator op_name on two values,
which must not be one of UNSUPPORTED_COMPARISON_OPERATORS.