use super::LowerCtx;
use std::fmt;
impl LowerCtx<'_> {
#[inline]
pub(crate) fn write_pad(&self, out: &mut impl fmt::Write) -> fmt::Result {
write_indent(out, self.indent)
}
/// Map an IR variable name to a safe WGSL identifier.
///
/// WGSL reserves identifiers starting with `__` and several keywords
/// (`active`, `target`, `texture`, `sampler`, etc.). Instead of
/// maintaining an ever-growing deny-list, every IR variable name is
/// prefixed with `_v_` at the emission boundary. IR authors can use
/// any name they want — this method guarantees a legal WGSL identifier.
pub(super) fn safe_var(name: &str) -> String {
format!("_v_{name}")
}
}
#[inline]
pub(crate) fn write_indent(out: &mut impl fmt::Write, indent: usize) -> fmt::Result {
for _ in 0..indent {
out.write_str(" ")?;
}
Ok(())
}