Skip to main content

oxicuda_ptx/ir/
module.rs

1//! PTX module representation.
2//!
3//! A [`PtxModule`] represents a complete PTX compilation unit, including the
4//! PTX version directive, target architecture, address size, and all function
5//! definitions. It is the top-level IR node from which PTX text is emitted.
6
7use super::function::PtxFunction;
8
9/// A complete PTX module (`.version`, `.target`, functions).
10///
11/// This is the top-level container for PTX code generation. A module
12/// corresponds to a single `.ptx` file and contains the metadata directives
13/// required by `ptxas` as well as one or more kernel/device functions.
14///
15/// # Examples
16///
17/// ```
18/// use oxicuda_ptx::ir::PtxModule;
19///
20/// let module = PtxModule {
21///     version: "8.5".to_string(),
22///     target: "sm_90a".to_string(),
23///     address_size: 64,
24///     functions: Vec::new(),
25/// };
26/// assert_eq!(module.target, "sm_90a");
27/// ```
28#[derive(Debug, Clone)]
29pub struct PtxModule {
30    /// PTX ISA version (e.g., `"8.5"`).
31    pub version: String,
32    /// Target architecture (e.g., `"sm_90a"`, `"sm_100a"`).
33    pub target: String,
34    /// Address size in bits (32 or 64; virtually always 64).
35    pub address_size: u32,
36    /// The functions defined in this module.
37    pub functions: Vec<PtxFunction>,
38}
39
40impl PtxModule {
41    /// Creates a new module targeting the given architecture with PTX 8.5 and 64-bit addressing.
42    #[must_use]
43    pub fn new(target: impl Into<String>) -> Self {
44        Self {
45            version: "8.5".to_string(),
46            target: target.into(),
47            address_size: 64,
48            functions: Vec::new(),
49        }
50    }
51
52    /// Adds a function to this module.
53    pub fn add_function(&mut self, func: PtxFunction) {
54        self.functions.push(func);
55    }
56}