ml_switcheroo.core.mlir.emitter¶
MLIR Emitter Logic.
This module provides the PythonToMlirEmitter, a compiler front-end that transforms Python LibCST trees into the MLIR CST object model.
Classes¶
Manages Single Static Assignment (SSA) variable scopes and ID allocation. |
|
Translates Python LibCST modules into MLIR structural nodes. |
Module Contents¶
- class ml_switcheroo.core.mlir.emitter.SSAContext¶
Manages Single Static Assignment (SSA) variable scopes and ID allocation.
- enter_scope() None¶
Push a new variable scope onto the stack.
- exit_scope() None¶
Pop the current variable scope from the stack.
- declare(name: str, value: ml_switcheroo.core.mlir.nodes.ValueNode) None¶
Register a variable name in the current scope.
- Parameters:
name – The Python variable identifier.
value – The MLIR ValueNode (SSA value) associated with it.
- lookup(name: str) ml_switcheroo.core.mlir.nodes.ValueNode | None¶
Resolve a Python variable name to its current SSA value. Searches scopes from innermost to outermost.
- Parameters:
name – The Python identifier to look up.
- Returns:
The associated ValueNode or None if not found.
- allocate_ssa(prefix: str = '%') ml_switcheroo.core.mlir.nodes.ValueNode¶
Generates a new unique SSA value.
- Parameters:
prefix – String prefix for the ID (default “%”).
- Returns:
A new ValueNode with a unique ID (e.g. “%0”, “%1”).
- class ml_switcheroo.core.mlir.emitter.PythonToMlirEmitter¶
Translates Python LibCST modules into MLIR structural nodes.
- ctx¶
- convert(node: libcst.Module) ml_switcheroo.core.mlir.nodes.ModuleNode¶
Entry point: Converts a CST Module to an MLIR ModuleNode.
- Parameters:
node – The Python LibCST Module.
- Returns:
The resulting MLIR ModuleNode containing the translated operations.