Skip to main content

gaia_assembler/backends/msl/
mod.rs

1//! MSL (Metal Shading Language) backend compiler
2
3use std::collections::HashMap;
4
5use crate::{config::GaiaConfig, program::GaiaModule, Backend, GeneratedFiles};
6use gaia_types::{
7    helpers::{AbiCompatible, ApiCompatible, Architecture, ArtifactType, CompilationTarget},
8    Result,
9};
10
11/// MSL Backend implementation
12#[derive(Default)]
13pub struct MslBackend {}
14
15impl Backend for MslBackend {
16    fn name(&self) -> &'static str {
17        "MSL"
18    }
19
20    fn primary_target(&self) -> CompilationTarget {
21        CompilationTarget { build: Architecture::Unknown, host: AbiCompatible::MSL, target: ApiCompatible::Metal }
22    }
23
24    fn artifact_type(&self) -> ArtifactType {
25        ArtifactType::Source
26    }
27
28    fn match_score(&self, target: &CompilationTarget) -> f32 {
29        if target.host == AbiCompatible::MSL {
30            return 80.0;
31        }
32        0.0
33    }
34
35    fn generate(&self, _program: &GaiaModule, config: &GaiaConfig) -> Result<GeneratedFiles> {
36        #[cfg(feature = "msl-assembler")]
37        {
38            Ok(GeneratedFiles { artifact_type: self.artifact_type(), files: HashMap::new(), custom: None, diagnostics: vec![] })
39        }
40        #[cfg(not(feature = "msl-assembler"))]
41        {
42            Err(gaia_types::GaiaError::custom_error("MSL feature is not enabled"))
43        }
44    }
45}