Lowering
Python dataclass
Python(
dialects: DialectGroup | Iterable[Dialect | ModuleType],
*,
keys: list[str] | None = None
)
Bases: LoweringABC[AST]
flowchart TD
kirin.lowering.python.lowering.Python[Python]
kirin.lowering.abc.LoweringABC[LoweringABC]
kirin.lowering.abc.LoweringABC --> kirin.lowering.python.lowering.Python
click kirin.lowering.python.lowering.Python href "" "kirin.lowering.python.lowering.Python"
click kirin.lowering.abc.LoweringABC href "" "kirin.lowering.abc.LoweringABC"
Python lowering transform.
This class is used to lower Python AST nodes to IR statements via a visitor pattern.
Note
the visitor pattern is not using the ast.NodeVisitor class because it customize the visit method to pass the lowering state and the source information to the visitor methods.
Source code in src/kirin/lowering/python/lowering.py
39 40 41 42 43 44 45 46 47 48 49 | |
dialects instance-attribute
dialects = dialects
dialects to lower to
lower_global
lower_global(
state: State[AST], node: AST
) -> LoweringABC.Result
Transform a given global expression to a SSAValue.
This method is overridden by the subclass to transform a given global AST expression to a value as LoweringABC.Result.
The subclass must implement this method to transform a given global AST expression to a SSAValue.
Source code in src/kirin/lowering/python/lowering.py
135 136 | |
visit
visit(state: State[AST], node: AST) -> Result
Entry point of AST visitors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | State[ASTNodeType] | lowering state | required |
node | ASTNodeType | AST node to be lowered | required |
Returns: SSAValue: if the node can be assigned to a variable syntax-wise, what is the SSAValue. Statement: if the node is a single statement that has a single result value. This is equivalent to returning stmt.results[0]. None: If the node cannot be assigned to a variable syntax-wise. Raises: lowering.BuildError: if the node cannot be lowered.
Source code in src/kirin/lowering/python/lowering.py
139 140 141 142 143 144 145 146 147 148 | |