svod-codegen 0.1.0-alpha.3

Backend code generation for the Svod ML compiler
Documentation
//! Types for code generation.

use svod_dtype::DType;

// Re-export new unified types from device crate
pub use svod_device::device::{ProgramSpec, Variable};
pub use svod_dtype::DeviceSpec;

/// A rendered kernel ready for compilation and execution.
#[derive(Debug, Clone)]
pub struct RenderedKernel {
    /// The generated code (LLVM IR, CUDA C, etc.)
    pub code: String,

    /// Kernel name (used as entry point and for debugging/caching).
    pub name: String,

    /// Buffer argument information.
    pub buffer_args: Vec<BufferArg>,

    /// Variable names in order (for populating vars array at runtime).
    pub var_names: Vec<String>,
}

/// Information about a buffer argument to the kernel.
#[derive(Debug, Clone)]
pub struct BufferArg {
    /// Argument index.
    pub index: usize,

    /// Buffer name.
    pub name: String,

    /// Data type.
    pub dtype: DType,

    /// Whether this is an output buffer.
    pub is_output: bool,
}

impl RenderedKernel {
    /// Create a new rendered kernel.
    pub fn new(code: String, name: String) -> Self {
        Self { code, name, buffer_args: Vec::new(), var_names: Vec::new() }
    }

    /// Add a buffer argument.
    pub fn add_buffer_arg(&mut self, arg: BufferArg) {
        self.buffer_args.push(arg);
    }
}