ptx_parser/
lib.rs

1//! PTX (Parallel Thread Execution) parser for NVIDIA GPU assembly language.
2//!
3//! This library provides a complete parser for PTX assembly code, including:
4//! - Lexical analysis (tokenization)
5//! - Syntactic parsing into structured types
6//! - Unparsing back to PTX source code
7//!
8//! # Quick Start
9//!
10//! ```no_run
11//! use ptx_parser::{parse_ptx};
12//! use ptx_parser::r#type::{Module, ModuleDirective, Instruction};
13//!
14//! let source = r#"
15//!     .version 8.5
16//!     .target sm_90
17//!     .address_size 64
18//!     
19//!     .entry kernel() {
20//!         add.s32 %r1, %r2, %r3;
21//!         ret;
22//!     }
23//! "#;
24//!
25//! let module: Module = parse_ptx(source).expect("Failed to parse PTX");
26//! println!("Parsed {} directives", module.directives.len());
27//! ```
28//!
29//! # Type Organization
30//!
31//! All types are re-exported at `ptx_parser::r#type::*` for easy access:
32//!
33//! ```rust
34//! use ptx_parser::r#type::{
35//!     Module,              // Root AST node
36//!     Instruction,         // Instruction with label/predicate
37//!     Predicate,           // Predicate guard
38//!     Operand,             // Operand types
39//!     FunctionKernelDirective,
40//!     EntryFunction,
41//!     // ... all other types
42//! };
43//! ```
44//!
45//! Instruction variants are under `instruction::`:
46//!
47//! ```rust
48//! use ptx_parser::r#type::instruction::{Inst, add, mov};
49//! ```
50
51// Internal modules - not part of public API
52mod lexer;
53mod parser;
54mod unlexer;
55mod unparser;
56
57// Type definitions - AST nodes (public)
58pub mod r#type;
59
60// Re-export commonly used items for convenience
61
62// Lexer exports
63pub use lexer::{LexError, PtxToken, Span, tokenize};
64
65// Parser exports
66pub use parser::{
67    ParseErrorKind, PtxParseError, PtxParser, PtxTokenStream, StreamPosition, parse_ptx,
68};
69
70// Unlexer exports
71pub use unlexer::PtxUnlexer;
72
73// Unparser exports
74pub use unparser::PtxUnparser;