Skip to main content

gaia_assembler/backends/elf/
mod.rs

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