1mod writer;
8
9use thiserror::Error;
10
11pub use writer::{Writer, WriterFlags};
12
13#[derive(Error, Debug)]
14pub enum Error {
15 #[error(transparent)]
16 FmtError(#[from] std::fmt::Error),
17 #[error("{0}")]
18 Custom(String),
19 #[error("{0}")]
20 Unimplemented(String), #[error("Unsupported math function: {0:?}")]
22 UnsupportedMathFunction(crate::MathFunction),
23 #[error("Unsupported relational function: {0:?}")]
24 UnsupportedRelationalFunction(crate::RelationalFunction),
25}
26
27pub fn write_string(
28 module: &crate::Module,
29 info: &crate::valid::ModuleInfo,
30 flags: WriterFlags,
31) -> Result<String, Error> {
32 let mut w = Writer::new(String::new(), flags);
33 w.write(module, info)?;
34 let output = w.finish();
35 Ok(output)
36}
37
38impl crate::AtomicFunction {
39 const fn to_wgsl(self) -> &'static str {
40 match self {
41 Self::Add => "Add",
42 Self::Subtract => "Sub",
43 Self::And => "And",
44 Self::InclusiveOr => "Or",
45 Self::ExclusiveOr => "Xor",
46 Self::Min => "Min",
47 Self::Max => "Max",
48 Self::Exchange { compare: None } => "Exchange",
49 Self::Exchange { .. } => "CompareExchangeWeak",
50 }
51 }
52}