Skip to main content

gaia_assembler/backends/
mod.rs

1//! Backend compiler module
2//!
3//! Contains compiler implementations for various target platforms
4
5pub mod gcn;
6pub mod jvm;
7pub mod msil;
8pub mod pe;
9pub mod sass;
10pub mod wasi;
11pub mod x86;
12
13// Re-export backend structs
14#[cfg(feature = "clr")]
15pub use self::msil::ClrBackend;
16pub use self::{gcn::GcnBackend, jvm::JvmBackend, pe::PeBackend, sass::SassBackend, wasi::WasiBackend, x86::X86Backend};
17
18use crate::{config::GaiaConfig, program::GaiaModule};
19use gaia_types::{helpers::CompilationTarget, Result};
20use std::collections::HashMap;
21
22/// Backend compiler trait
23pub trait Backend {
24    /// Get backend name
25    fn name(&self) -> &'static str;
26
27    /// 获取此后端支持的主要编译目标
28    fn primary_target(&self) -> CompilationTarget;
29
30    /// 计算与给定编译目标的匹配度 (0-100)
31    /// 0 表示不支持
32    fn match_score(&self, target: &CompilationTarget) -> f32;
33
34    /// Compile Gaia program to target platform
35    fn generate(&self, program: &GaiaModule, config: &GaiaConfig) -> Result<GeneratedFiles>;
36}
37
38pub struct GeneratedFiles {
39    pub files: HashMap<String, Vec<u8>>,
40    pub diagnostics: Vec<gaia_types::GaiaError>,
41}