ml_switcheroo.compiler.frontends.sass.nodes

SASS AST Nodes.

Defines the data structures for the NVIDIA SASS syntax tree. Each node corresponds to a syntactic element in SASS assembly and implements __str__ to emit valid code.

Classes

SassNode

Abstract base class for all SASS AST nodes.

Operand

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

Register

Represents a general-purpose register (e.g., R0, RZ).

Predicate

Represents a predicate register (e.g., @P0, !P1).

Immediate

Represents a literal constant value.

Memory

Represents a memory address operand.

Instruction

Represents a single SASS operation line.

Label

Represents a jump target label.

Directive

Represents an assembler directive.

Comment

Represents a line comment.

Module Contents

class ml_switcheroo.compiler.frontends.sass.nodes.SassNode[source]

Bases: abc.ABC

Abstract base class for all SASS AST nodes.

abstractmethod __str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Operand[source]

Bases: SassNode

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

class ml_switcheroo.compiler.frontends.sass.nodes.Register[source]

Bases: Operand

Represents 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”).

absolute

If True, wraps in absolute value pipes (e.g., “|R0|”).

name: str
negated: bool = False
absolute: bool = False
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Predicate[source]

Bases: Operand

Represents 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
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.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., “0x1”).

Type:

bool

value: int | float
is_hex: bool = False
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Memory[source]

Bases: Operand

Represents 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]

base: str | Register
offset: int | None = None
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Instruction[source]

Bases: SassNode

Represents a single SASS operation line.

Format: @{predicate} {opcode} {operands};

opcode

The instruction mnemonic (e.g., “FADD”, “MOV”).

Type:

str

operands

List of operand nodes.

Type:

List[Operand]

predicate

Optional predicate guard executed before instruction.

Type:

Optional[Predicate]

opcode: str
operands: List[Operand] = []
predicate: Predicate | None = None
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Label[source]

Bases: SassNode

Represents a jump target label.

Format: {name}:

name

The label identifier.

Type:

str

name: str
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Directive[source]

Bases: SassNode

Represents 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] = []
__str__() str[source]

Returns the valid SASS string representation of the node.

class ml_switcheroo.compiler.frontends.sass.nodes.Comment[source]

Bases: SassNode

Represents a line comment.

Format: // {text}

text

The comment content.

text: str
__str__() str[source]

Returns the valid SASS string representation of the node.