Crate ptx_parser

Crate ptx_parser 

Source
Expand description

PTX (Parallel Thread Execution) parser for NVIDIA GPU assembly language.

This library provides a complete parser for PTX assembly code, including:

  • Lexical analysis (tokenization)
  • Syntactic parsing into structured types
  • Unparsing back to PTX source code

§Quick Start

use ptx_parser::{parse_ptx};
use ptx_parser::r#type::{Module, ModuleDirective, Instruction};

let source = r#"
    .version 8.5
    .target sm_90
    .address_size 64
     
    .entry kernel() {
        add.s32 %r1, %r2, %r3;
        ret;
    }
"#;

let module: Module = parse_ptx(source).expect("Failed to parse PTX");
println!("Parsed {} directives", module.directives.len());

§Type Organization

All types are re-exported at ptx_parser::r#type::* for easy access:

use ptx_parser::r#type::{
    Module,              // Root AST node
    Instruction,         // Instruction with label/predicate
    Predicate,           // Predicate guard
    Operand,             // Operand types
    FunctionKernelDirective,
    EntryFunction,
    // ... all other types
};

Instruction variants are under instruction:::

use ptx_parser::r#type::instruction::{Inst, add, mov};

Modules§

type
PTX type definitions - Abstract Syntax Tree (AST) nodes.

Structs§

LexError
Lexical analysis error type.
PtxParseError
PTX parsing error with location information.
PtxTokenStream
Token stream wrapper for parsing PTX tokens.
PtxUnlexer
Utility that performs the inverse of the lexer: it writes textual PTX for a sequence of [PtxSpecToken] values.
StreamPosition
Represents a position in the token stream, including both token index and character offset within a token

Enums§

ParseErrorKind
Kinds of parse errors that can occur during PTX parsing.
PtxToken
PTX specification token types for lexical analysis.

Traits§

PtxParser
Trait for types that can be parsed from a PTX token stream.
PtxUnparser
Trait that mirrors crate::parser::PtxParser but for emitting PTX source text from the structured representation.

Functions§

parse_ptx
Parse PTX source code into a structured Module representation.
tokenize
Tokenize a PTX source string into a sequence of tokens with their spans.

Type Aliases§

Span
Byte range in the source.