1use gaia_assembler::{
2 backends::{Backend, GeneratedFiles},
3 config::GaiaConfig,
4 program::GaiaModule,
5};
6use gaia_types::{
7 helpers::{AbiCompatible, ApiCompatible, Architecture, CompilationTarget},
8 Result,
9};
10use std::collections::HashMap;
11
12pub struct MslGenerator;
13
14impl Backend for MslGenerator {
15 fn name(&self) -> &'static str {
16 "msl"
17 }
18
19 fn primary_target(&self) -> CompilationTarget {
20 CompilationTarget {
21 build: Architecture::X86_64, host: AbiCompatible::MSL,
23 target: ApiCompatible::Metal,
24 }
25 }
26
27 fn match_score(&self, target: &CompilationTarget) -> f32 {
28 if target.host == AbiCompatible::MSL {
29 100.0
30 }
31 else {
32 0.0
33 }
34 }
35
36 fn generate(&self, program: &GaiaModule, _config: &GaiaConfig) -> Result<GeneratedFiles> {
37 let mut files = HashMap::new();
38 let diagnostics = Vec::new();
39
40 let mut module_source = self.msl_header();
41 module_source.push_str("\n");
42
43 for function in &program.functions {
44 for block in &function.blocks {
45 for instruction in &block.instructions {
46 }
48 }
49 }
50
51 files.insert("module.metal".to_string(), Vec::from(module_source.as_bytes()));
52 files.insert("default.metallib".to_string(), vec![0x4d, 0x54, 0x4c, 0x42]); Ok(GeneratedFiles { files, diagnostics })
56 }
57}
58
59impl MslGenerator {
60 fn msl_header(&self) -> String {
61 "#include <metal_stdlib>\nusing namespace metal;".to_string()
62 }
63}