vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use super::{emit_wgsl, Error};
use crate::ir::model::program::Program;
use crate::ir::{inline_calls, optimize};

/// Lower a vyre `Program` to a complete WGSL compute shader string.
///
/// This is the lowering contract: every op's Rust CPU reference maps to a
/// specific WGSL template.  The output contains:
/// - Buffer struct and binding declarations
/// - A `main` entry point with `@compute @workgroup_size(...)`
/// - All node/expression logic from the Program's entry body
///
/// # Errors
///
/// Returns `Err` if the Program references constructs that cannot be lowered
/// (e.g., unsupported Cast pairs). Validate the Program first via
/// `ir::validate()` to catch most issues at construction time.
#[inline]
pub fn lower(program: &Program) -> Result<String, Error> {
    crate::ops::registry::gate::verify_program_certificate(program)
        .map_err(|err| Error::lowering(err.to_string()))?;
    let program = inline_calls(program).map_err(|err| Error::lowering(err.to_string()))?;
    let program = optimize(program);
    emit_wgsl(&program)
}