Skip to main content

nxpu_parser/
lib.rs

1//! WGSL parser for NxPU.
2//!
3//! Parses WGSL source text into an [`nxpu_ir::Module`] by using
4//! [naga](https://crates.io/crates/naga)'s WGSL frontend and then
5//! lowering the resulting `naga::Module` to NxPU-IR.
6
7mod lower;
8
9/// Parse WGSL source into an NxPU IR module.
10///
11/// Only `@compute` entry points are retained; vertex/fragment shaders
12/// and GPU-only features (images, samplers, derivatives) are rejected.
13pub fn parse(source: &str) -> Result<nxpu_ir::Module, ParseError> {
14    let naga_module = naga::front::wgsl::parse_str(source)?;
15    lower::lower_module(&naga_module)
16}
17
18#[derive(Debug, thiserror::Error)]
19pub enum ParseError {
20    #[error(transparent)]
21    Wgsl(#[from] naga::front::wgsl::ParseError),
22    #[error("unsupported: {0}")]
23    Unsupported(String),
24    #[error("lowering: {0}")]
25    Lowering(String),
26}