ml_switcheroo.compiler.frontends.sass¶
SASS Frontend (Parser & Lifter).
Handles the parsing of NVIDIA SASS assembly text into an Abstract Syntax Tree (AST) and the lifting of that AST into the high-level Logical Graph IR.
Submodules¶
Classes¶
Represents a line comment. |
|
Represents an assembler directive. |
|
Represents a literal constant value. |
|
Represents a single SASS operation line. |
|
Represents a jump target label. |
|
Represents a memory address operand. |
|
Base class for instruction operands (Registers, Immediates, etc.). |
|
Represents a predicate register (e.g., @P0, !P1). |
|
Represents a general-purpose register (e.g., R0, RZ). |
|
Abstract base class for all SASS AST nodes. |
|
Recursive descent parser for NVIDIA SASS. |
|
Regex-based Lexer for NVIDIA SASS assembly. |
|
Represents a lexical unit. |
|
Enumeration of valid SASS token types. |
|
Reconstructs a LogicalGraph from a sequence of SASS AST nodes. |
|
Analyzes sequences of SASS instructions to reverse-engineer high-level parameters. |
Package Contents¶
- class ml_switcheroo.compiler.frontends.sass.Comment[source]¶
Bases:
SassNodeRepresents a line comment.
Format: // {text}
- text¶
The comment content.
- text: str¶
- class ml_switcheroo.compiler.frontends.sass.Directive[source]¶
Bases:
SassNodeRepresents an assembler directive.
Format: .{name} {params}
- name¶
The directive name (e.g., “headerflags”).
- Type:
str
- params¶
List of string parameters.
- Type:
List[str]
- name: str¶
- params: List[str] = []¶
- class ml_switcheroo.compiler.frontends.sass.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., “0x1”).
- Type:
bool
- value: int | float¶
- is_hex: bool = False¶
- class ml_switcheroo.compiler.frontends.sass.Instruction[source]¶
Bases:
SassNodeRepresents a single SASS operation line.
Format: @{predicate} {opcode} {operands};
- opcode¶
The instruction mnemonic (e.g., “FADD”, “MOV”).
- Type:
str
- opcode: str¶
- class ml_switcheroo.compiler.frontends.sass.Label[source]¶
Bases:
SassNodeRepresents a jump target label.
Format: {name}:
- name¶
The label identifier.
- Type:
str
- name: str¶
- class ml_switcheroo.compiler.frontends.sass.Memory[source]¶
Bases:
OperandRepresents a memory address operand.
Supports Constant Bank access (e.g., c[0x0][0x4]) and Global/Local addressing (e.g., [R1], [R1 + 0x4]).
- base¶
The base register (e.g., “R1”) or constant bank string (e.g., “c[0x0]”).
- Type:
Union[str, Register]
- offset¶
Optional byte offset to add to the base.
- Type:
Optional[int]
- offset: int | None = None¶
- class ml_switcheroo.compiler.frontends.sass.Operand[source]¶
Bases:
SassNodeBase class for instruction operands (Registers, Immediates, etc.).
- class ml_switcheroo.compiler.frontends.sass.Predicate[source]¶
Bases:
OperandRepresents a predicate register (e.g., @P0, !P1).
Used both as instruction guards (preceding the opcode) and as operands in logical instructions (ISETP).
- name¶
The predicate identifier (e.g., “P0”, “PT”).
- Type:
str
- negated¶
If True, indicates logical NOT (e.g., “!P0”).
- Type:
bool
- name: str¶
- negated: bool = False¶
- class ml_switcheroo.compiler.frontends.sass.Register[source]¶
Bases:
OperandRepresents a general-purpose register (e.g., R0, RZ).
- name¶
The register identifier (e.g., “R0”, “RZ”).
- Type:
str
- negated¶
If True, prepends a negation sign (e.g., “-R0”).
- name: str¶
- negated: bool = False¶
- absolute: bool = False¶
- class ml_switcheroo.compiler.frontends.sass.SassNode[source]¶
Bases:
abc.ABCAbstract base class for all SASS AST nodes.
- class ml_switcheroo.compiler.frontends.sass.SassParser(code: str)[source]¶
Recursive descent parser for NVIDIA SASS.
- lexer¶
- tokens¶
- pos = 0¶
- parse() List[ml_switcheroo.compiler.frontends.sass.nodes.SassNode][source]¶
Parses the entire code block.
- Returns:
A list of AST nodes.
- Return type:
List[SassNode]
- class ml_switcheroo.compiler.frontends.sass.SassLexer[source]¶
Regex-based Lexer for NVIDIA SASS assembly.
- regex_pairs¶
- class ml_switcheroo.compiler.frontends.sass.Token[source]¶
Represents a lexical unit.
- value¶
The raw string content.
- 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.sass.TokenType(*args, **kwds)[source]¶
Bases:
enum.EnumEnumeration of valid SASS token types.
- LABEL_DEF¶
- DIRECTIVE¶
- COMMENT¶
- SEMICOLON¶
- COMMA¶
- PREDICATE¶
- REGISTER¶
- MEMORY¶
- IMMEDIATE¶
- IDENTIFIER¶
- class ml_switcheroo.compiler.frontends.sass.SassLifter[source]¶
Reconstructs a LogicalGraph from a sequence of SASS AST nodes.
- lift(nodes: List[ml_switcheroo.compiler.frontends.sass.nodes.SassNode]) ml_switcheroo.compiler.ir.LogicalGraph[source]¶
Parses a list of SASS nodes to build a LogicalGraph.
Captures instructions within BEGIN/END blocks to feed into the Analyzer. Captures orphan instructions into individual functional nodes (1:1 mapping).
- class ml_switcheroo.compiler.frontends.sass.SassAnalyzer[source]¶
Analyzes sequences of SASS instructions to reverse-engineer high-level parameters.
- static analyze_block(kind: str, instructions: List[ml_switcheroo.compiler.frontends.sass.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., {“kernel_size”: 3}).
- Return type:
Dict[str, Any]