mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 23:41:01 +01:00
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`.
34 lines
1002 B
Rust
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}"),
|
|
}
|
|
}
|