ml_switcheroo.core.mlir.nodes¶

MLIR Concrete Syntax Tree Nodes.

This module defines the data structures for representing MLIR source code. It ensures structural hierarchy (Module -> Operation -> Region -> Block) and trivia preservation for high-fidelity round-tripping.

Classes¶

MlirNode

Abstract base class for all MLIR CST nodes.

TriviaNode

Represents non-semantic tokens (whitespace, comments).

ValueNode

Represents an SSA Value identifier (e.g. %0).

TypeNode

Represents a type annotation.

AttributeNode

Represents a named attribute.

BlockNode

Represents a Basic Block within a Region.

RegionNode

Represents a Region containing Blocks.

OperationNode

Represents a specific MLIR Operation.

ModuleNode

Top-level container.

Module Contents¶

class ml_switcheroo.core.mlir.nodes.MlirNode[source]¶

Bases: abc.ABC

Abstract base class for all MLIR CST nodes.

abstractmethod to_text() → str[source]¶

Return the textual MLIR representation of this node.

class ml_switcheroo.core.mlir.nodes.TriviaNode[source]¶

Bases: MlirNode

Represents non-semantic tokens (whitespace, comments).

content: str¶
kind: str = 'whitespace'¶
to_text() → str[source]¶

Return the trivia content verbatim.

class ml_switcheroo.core.mlir.nodes.ValueNode[source]¶

Bases: MlirNode

Represents an SSA Value identifier (e.g. %0).

name: str¶
to_text() → str[source]¶

Return the SSA identifier.

class ml_switcheroo.core.mlir.nodes.TypeNode[source]¶

Bases: MlirNode

Represents a type annotation.

body: str¶
to_text() → str[source]¶

Return the type string.

class ml_switcheroo.core.mlir.nodes.AttributeNode[source]¶

Bases: MlirNode

Represents a named attribute. Value can be a string literal or a list of string literals (e.g. for bases).

name: str¶
value: str | List[str]¶
type_annotation: str | None = None¶
to_text() → str[source]¶

Return ‘key = value’ string format.

class ml_switcheroo.core.mlir.nodes.BlockNode[source]¶

Bases: MlirNode

Represents a Basic Block within a Region.

label: str¶
operations: List[OperationNode] = []¶
arguments: List[Tuple[ValueNode, TypeNode]] = []¶
leading_trivia: List[TriviaNode] = []¶
to_text() → str[source]¶

Formats the block including label, arguments, and operations.

class ml_switcheroo.core.mlir.nodes.RegionNode[source]¶

Bases: MlirNode

Represents a Region containing Blocks.

blocks: List[BlockNode] = []¶
to_text() → str[source]¶

Formats the region enclosed in braces.

class ml_switcheroo.core.mlir.nodes.OperationNode[source]¶

Bases: MlirNode

Represents a specific MLIR Operation.

name: str¶
results: List[ValueNode] = []¶
operands: List[ValueNode] = []¶
attributes: List[AttributeNode] = []¶
regions: List[RegionNode] = []¶
result_types: List[TypeNode] = []¶
leading_trivia: List[TriviaNode] = []¶
name_trivia: List[TriviaNode] = []¶
trailing_trivia: List[TriviaNode] = []¶
to_text() → str[source]¶

Formats the operation string following MLIR syntax rules.

class ml_switcheroo.core.mlir.nodes.ModuleNode[source]¶

Bases: MlirNode

Top-level container.

body: BlockNode¶
to_text() → str[source]¶

Return module body text.