ml_switcheroo.compiler.frontends.rdnaΒΆ
RDNA Frontend Package.
Contains the parser and lifter logic for converting AMD RDNA/GCN assembly text into Abstract Syntax Trees (AST) and then into the Logical Graph IR.
SubmodulesΒΆ
ClassesΒΆ
Represents a line comment. |
|
Represents an assembler directive. |
|
Represents a literal constant value. |
|
Represents a single RDNA operation line. |
|
Represents a jump target label. |
|
Represents a reference to a label (e.g. as a jump target) or generic identifier operand. |
|
Represents a memory address operand, typically used in generic loads/stores. |
|
Represents an instruction modifier or attribute. |
|
Base class for instruction operands (Registers, Immediates, etc.). |
|
Abstract base class for all RDNA AST nodes. |
|
Represents a Scalar General Purpose Register (e.g., s0, s10). |
|
Represents a Vector General Purpose Register (e.g., v0, v255). |
|
Recursive descent parser for AMD RDNA / GCN assembly. |
|
Regex-based Lexer for AMD RDNA / GCN assembly. |
|
Represents a lexical unit. |
|
Enumeration of valid RDNA token types. |
|
Reconstructs a LogicalGraph from a sequence of RDNA AST nodes. |
|
Analyzes sequences of RDNA instructions to reverse-engineer high-level parameters. |
FunctionsΒΆ
|
Helper to create a single SGPR. |
|
Helper to create a single VGPR. |
Package ContentsΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Comment[source]ΒΆ
Bases:
RdnaNodeRepresents a line comment. RDNA assembly uses ; for comments.
Format: ; {text}
- textΒΆ
The comment content.
- Type:
str
- text: strΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Directive[source]ΒΆ
Bases:
RdnaNodeRepresents 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] = []ΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Immediate[source]ΒΆ
Bases:
OperandRepresents 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ΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Instruction[source]ΒΆ
Bases:
RdnaNodeRepresents 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
- opcode: strΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Label[source]ΒΆ
Bases:
RdnaNodeRepresents a jump target label.
Format: {name}:
- nameΒΆ
The label identifier.
- Type:
str
- name: strΒΆ
- class ml_switcheroo.compiler.frontends.rdna.LabelRef[source]ΒΆ
Bases:
OperandRepresents a reference to a label (e.g. as a jump target) or generic identifier operand.
- nameΒΆ
The label identifier.
- Type:
str
- name: strΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Memory[source]ΒΆ
Bases:
OperandRepresents 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.
- offsetΒΆ
Immediate byte offset.
- Type:
Optional[int]
- offset: int | None = NoneΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Modifier[source]ΒΆ
Bases:
OperandRepresents an instruction modifier or attribute. e.g., glc, slc, off.
- nameΒΆ
The modifier string.
- Type:
str
- name: strΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Operand[source]ΒΆ
Bases:
RdnaNodeBase class for instruction operands (Registers, Immediates, etc.).
- class ml_switcheroo.compiler.frontends.rdna.RdnaNode[source]ΒΆ
Bases:
abc.ABCAbstract base class for all RDNA AST nodes.
- class ml_switcheroo.compiler.frontends.rdna.SGPR[source]ΒΆ
Bases:
OperandRepresents 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ΒΆ
- class ml_switcheroo.compiler.frontends.rdna.VGPR[source]ΒΆ
Bases:
OperandRepresents 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ΒΆ
- ml_switcheroo.compiler.frontends.rdna.c_SGPR(idx: int) SGPR[source]ΒΆ
Helper to create a single SGPR.
- ml_switcheroo.compiler.frontends.rdna.c_VGPR(idx: int) VGPR[source]ΒΆ
Helper to create a single VGPR.
- class ml_switcheroo.compiler.frontends.rdna.RdnaParser(code: str)[source]ΒΆ
Recursive descent parser for AMD RDNA / GCN assembly.
- lexerΒΆ
- tokensΒΆ
- pos = 0ΒΆ
- parse() List[ml_switcheroo.compiler.frontends.rdna.nodes.RdnaNode][source]ΒΆ
Parses the entire code block.
- class ml_switcheroo.compiler.frontends.rdna.RdnaLexer[source]ΒΆ
Regex-based Lexer for AMD RDNA / GCN assembly.
- regex_pairsΒΆ
- class ml_switcheroo.compiler.frontends.rdna.Token[source]ΒΆ
Represents a lexical unit.
- valueΒΆ
The raw string value.
- Type:
str
- lineΒΆ
Line number in source (1-based).
- Type:
int
- columnΒΆ
Column number in source (1-based).
- Type:
int
- value: strΒΆ
- line: intΒΆ
- column: intΒΆ
- class ml_switcheroo.compiler.frontends.rdna.TokenType(*args, **kwds)[source]ΒΆ
Bases:
enum.EnumEnumeration of valid RDNA token types.
- LABEL_DEFΒΆ
- DIRECTIVEΒΆ
- COMMENTΒΆ
- COMMAΒΆ
- RBRACKETΒΆ
- LBRACKETΒΆ
- COLONΒΆ
- SGPRΒΆ
- VGPRΒΆ
- SPECIAL_REGΒΆ
- IMMEDIATEΒΆ
- MODIFIERΒΆ
- IDENTIFIERΒΆ
- class ml_switcheroo.compiler.frontends.rdna.RdnaLifter[source]ΒΆ
Reconstructs a LogicalGraph from a sequence of RDNA AST nodes.
- lift(nodes: List[ml_switcheroo.compiler.frontends.rdna.nodes.RdnaNode]) ml_switcheroo.compiler.ir.LogicalGraph[source]ΒΆ
Parses a list of RDNA nodes to build a LogicalGraph.
- class ml_switcheroo.compiler.frontends.rdna.RdnaAnalyzer[source]ΒΆ
Analyzes sequences of RDNA instructions to reverse-engineer high-level parameters.
- static analyze_block(kind: str, instructions: List[ml_switcheroo.compiler.frontends.rdna.nodes.Instruction]) Dict[str, Any][source]ΒΆ
Extracts metadata from a block of instructions based on the operation kind.
- Parameters:
kind (str) β The operation type (e.g. βConv2dβ, βLinearβ).
instructions (List[Instruction]) β The assembly lines inside the block.
- Returns:
Extracted parameters (e.g., {βkβ: 3}).
- Return type:
Dict[str, Any]