Abc
Result module-attribute
Result: TypeAlias = (
SSAValue | tuple[SSAValue, ...] | Statement | None
)
Result of lowering a node. This is used to indicate that the node can be lowered to a SSAValue or None.
If the node is corresponding to a single statement that has a single result value, the result can also be a Statement for convenience.
If the node can be assigned to a variable syntax-wise, it returns the SSAValue. If the node cannot be assigned to a variable, it returns None.
LoweringABC dataclass
LoweringABC(dialects: DialectGroup)
Bases: ABC, Generic[ASTNodeType]
flowchart TD
kirin.lowering.abc.LoweringABC[LoweringABC]
click kirin.lowering.abc.LoweringABC href "" "kirin.lowering.abc.LoweringABC"
Base class for lowering.
This class is used to lower the AST nodes to IR. It contains the lowering process and the state of the lowering process.
dialects instance-attribute
dialects: DialectGroup
dialects to lower to
lower_global abstractmethod
lower_global(
state: State[ASTNodeType], node: ASTNodeType
) -> 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/abc.py
86 87 88 89 90 91 92 93 94 95 96 97 98 | |
lower_global_no_raise
lower_global_no_raise(
state: State[ASTNodeType], node: ASTNodeType
) -> LoweringABC.Result | None
Transform a given global expression to a SSAValue.
This method can be overridden by the subclass to transform a given global AST expression to a SSAValue.
Source code in src/kirin/lowering/abc.py
100 101 102 103 104 105 106 107 108 109 110 111 | |
visit abstractmethod
visit(
state: State[ASTNodeType], node: ASTNodeType
) -> 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/abc.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |