gaia-assembler 0.1.1

Universal assembler framework for Gaia project
Documentation
//! LLVM IR backend compiler

use crate::{config::GaiaConfig, program::GaiaModule, Backend, GeneratedFiles};
use gaia_types::{
    helpers::{AbiCompatible, ApiCompatible, Architecture, ArtifactType, CompilationTarget},
    Result,
};
use std::collections::HashMap;

/// LLVM Backend implementation
#[derive(Default)]
pub struct LlvmBackend {}

impl Backend for LlvmBackend {
    fn name(&self) -> &'static str {
        "LLVM"
    }

    fn primary_target(&self) -> CompilationTarget {
        CompilationTarget { build: Architecture::Unknown, host: AbiCompatible::LlvmIr, target: ApiCompatible::Unknown }
    }

    fn artifact_type(&self) -> ArtifactType {
        ArtifactType::Assembly
    }

    fn match_score(&self, target: &CompilationTarget) -> f32 {
        if target.host == AbiCompatible::LlvmIr {
            return 80.0;
        }
        0.0
    }

    fn generate(&self, _program: &GaiaModule, config: &GaiaConfig) -> Result<GeneratedFiles> {
        #[cfg(feature = "llvm-assembler")]
        {
            Ok(GeneratedFiles { artifact_type: self.artifact_type(), files: HashMap::new(), custom: None, diagnostics: vec![] })
        }
        #[cfg(not(feature = "llvm-assembler"))]
        {
            Err(gaia_types::GaiaError::custom_error("LLVM feature is not enabled"))
        }
    }
}