region-based memory management in a c-like form
at main 674 B view raw
1mod llvm; 2 3use std::process::Command; 4 5use anyhow::Result; 6use clap::ValueEnum; 7use frontend::{Ctx, mir::Module}; 8 9#[derive(ValueEnum, Clone, Debug)] 10pub enum CodegenBackend { 11 SelfHost, 12 LLVM, 13 Cranelift, 14} 15 16trait Compiler { 17 fn compile(self, module: Module, ctx: Ctx, debug: bool) -> Result<()>; 18} 19 20pub fn codegen(backend: CodegenBackend, module: Module, ctx: Ctx, debug: bool) -> Result<()> { 21 match backend { 22 CodegenBackend::SelfHost => todo!(), 23 CodegenBackend::LLVM => llvm::compile(module, ctx, debug)?, 24 CodegenBackend::Cranelift => todo!(), 25 } 26 27 let _ = Command::new("cc").arg("a.o").arg("lib.c").status()?; 28 29 Ok(()) 30}