Files
wgpu/naga/src/common/predeclared.rs
T
Jim Blandy 6dcccc40a1 [naga] Move predeclared type name generation to common code.
Add a new module, `naga::common::predeclared`, which implements a new
`struct_name` method on `naga::ir::PredeclaredType`, to produce the
name of the struct type corresponding to that `PredeclaredType` value.
Use this new method in `naga::front::type_gen`.
2025-04-02 18:27:19 -04:00

34 lines
1002 B
Rust

//! Generating names for predeclared types.
use crate::ir;
use alloc::format;
use alloc::string::String;
impl ir::PredeclaredType {
pub fn struct_name(&self) -> String {
use crate::PredeclaredType as Pt;
match *self {
Pt::AtomicCompareExchangeWeakResult(scalar) => {
format!(
"__atomic_compare_exchange_result<{:?},{}>",
scalar.kind, scalar.width,
)
}
Pt::ModfResult { size, scalar } => frexp_mod_name("modf", size, scalar),
Pt::FrexpResult { size, scalar } => frexp_mod_name("frexp", size, scalar),
}
}
}
fn frexp_mod_name(function: &str, size: Option<ir::VectorSize>, scalar: ir::Scalar) -> String {
let bits = 8 * scalar.width;
match size {
Some(size) => {
let size = size as u8;
format!("__{function}_result_vec{size}_f{bits}")
}
None => format!("__{function}_result_f{bits}"),
}
}