ml_switcheroo.compiler.frontends.rdna.nodesΒΆ

RDNA AST Nodes.

Defines the data structures for the AMD RDNA / GCN syntax tree. Each node corresponds to a syntactic element in RDNA assembly and implements __str__ to emit valid assembly code.

ClassesΒΆ

RdnaNode

Abstract base class for all RDNA AST nodes.

Operand

Base class for instruction operands (Registers, Immediates, etc.).

LabelRef

Represents a reference to a label (e.g. as a jump target) or generic identifier operand.

SGPR

Represents a Scalar General Purpose Register (e.g., s0, s10).

VGPR

Represents a Vector General Purpose Register (e.g., v0, v255).

Immediate

Represents a literal constant value.

Modifier

Represents an instruction modifier or attribute.

Memory

Represents a memory address operand, typically used in generic loads/stores.

Instruction

Represents a single RDNA operation line.

Label

Represents a jump target label.

Directive

Represents an assembler directive.

Comment

Represents a line comment.

FunctionsΒΆ

c_SGPR(β†’Β SGPR)

Helper to create a single SGPR.

c_VGPR(β†’Β VGPR)

Helper to create a single VGPR.

Module ContentsΒΆ

class ml_switcheroo.compiler.frontends.rdna.nodes.RdnaNode[source]ΒΆ

Bases: abc.ABC

Abstract base class for all RDNA AST nodes.

abstractmethod __str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Operand[source]ΒΆ

Bases: RdnaNode

Base class for instruction operands (Registers, Immediates, etc.).

__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.LabelRef[source]ΒΆ

Bases: Operand

Represents a reference to a label (e.g. as a jump target) or generic identifier operand.

nameΒΆ

The label identifier.

Type:

str

name: strΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.SGPR[source]ΒΆ

Bases: Operand

Represents a Scalar General Purpose Register (e.g., s0, s10).

indexΒΆ

The register index.

Type:

int

countΒΆ

If > 1, represents a range/multi-register (e.g., s[0:3]).

Type:

int

index: intΒΆ
count: int = 1ΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.VGPR[source]ΒΆ

Bases: Operand

Represents a Vector General Purpose Register (e.g., v0, v255).

indexΒΆ

The register index.

Type:

int

countΒΆ

If > 1, represents a range/multi-register (e.g., v[0:3]).

Type:

int

index: intΒΆ
count: int = 1ΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

ml_switcheroo.compiler.frontends.rdna.nodes.c_SGPR(idx: int) β†’ SGPR[source]ΒΆ

Helper to create a single SGPR.

ml_switcheroo.compiler.frontends.rdna.nodes.c_VGPR(idx: int) β†’ VGPR[source]ΒΆ

Helper to create a single VGPR.

class ml_switcheroo.compiler.frontends.rdna.nodes.Immediate[source]ΒΆ

Bases: Operand

Represents a literal constant value.

valueΒΆ

The numeric value.

Type:

Union[int, float]

is_hexΒΆ

If True, renders as hex string (e.g., 0xff).

Type:

bool

value: int | floatΒΆ
is_hex: bool = FalseΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Modifier[source]ΒΆ

Bases: Operand

Represents an instruction modifier or attribute. e.g., glc, slc, off.

nameΒΆ

The modifier string.

Type:

str

name: strΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Memory[source]ΒΆ

Bases: Operand

Represents a memory address operand, typically used in generic loads/stores. RDNA often passes the address as a register or register pair, but explicit offset syntax exists.

Format: method[base + offset] or simply register references depending on op. This node models the bracketed syntax global_load_dword v0, v[1:2], off. Usually, RDNA just uses registers as operands, but sometimes specific addressing notation is used. Here we treat it as an explicit container if needed, primarily for offsets.

baseΒΆ

The base register.

Type:

Union[SGPR, VGPR]

offsetΒΆ

Immediate byte offset.

Type:

Optional[int]

base: SGPR | VGPRΒΆ
offset: int | None = NoneΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Instruction[source]ΒΆ

Bases: RdnaNode

Represents a single RDNA operation line.

Format: {opcode} {operands} Modifiers are treated as operands in the list for flexible placement.

opcodeΒΆ

The instruction mnemonic (e.g., β€œv_add_f32”, β€œs_mov_b32”).

Type:

str

operandsΒΆ

List of operand nodes.

Type:

List[Operand]

opcode: strΒΆ
operands: List[Operand] = []ΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Label[source]ΒΆ

Bases: RdnaNode

Represents a jump target label.

Format: {name}:

nameΒΆ

The label identifier.

Type:

str

name: strΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Directive[source]ΒΆ

Bases: RdnaNode

Represents an assembler directive.

Format: .{name} {params}

nameΒΆ

The directive name (e.g., β€œglobal_base”).

Type:

str

paramsΒΆ

List of string parameters.

Type:

List[str]

name: strΒΆ
params: List[str] = []ΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.

class ml_switcheroo.compiler.frontends.rdna.nodes.Comment[source]ΒΆ

Bases: RdnaNode

Represents a line comment. RDNA assembly uses ; for comments.

Format: ; {text}

textΒΆ

The comment content.

Type:

str

text: strΒΆ
__str__() β†’ str[source]ΒΆ

Returns the valid RDNA string representation of the node.