naga/common/
predeclared.rs

1//! Generating names for predeclared types.
2
3use crate::ir;
4
5use alloc::format;
6use alloc::string::String;
7
8impl ir::PredeclaredType {
9    pub fn struct_name(&self) -> String {
10        use crate::PredeclaredType as Pt;
11        match *self {
12            Pt::AtomicCompareExchangeWeakResult(scalar) => {
13                format!(
14                    "__atomic_compare_exchange_result<{:?},{}>",
15                    scalar.kind, scalar.width,
16                )
17            }
18            Pt::ModfResult { size, scalar } => frexp_mod_name("modf", size, scalar),
19            Pt::FrexpResult { size, scalar } => frexp_mod_name("frexp", size, scalar),
20        }
21    }
22}
23
24fn frexp_mod_name(function: &str, size: Option<ir::VectorSize>, scalar: ir::Scalar) -> String {
25    let bits = 8 * scalar.width;
26    match size {
27        Some(size) => {
28            let size = size as u8;
29            format!("__{function}_result_vec{size}_f{bits}")
30        }
31        None => format!("__{function}_result_f{bits}"),
32    }
33}