Restructure and start working on CLI

This commit is contained in:
Fabian Stamm
2025-05-26 16:43:40 +02:00
parent 883b6da7eb
commit b61518de00
38 changed files with 134 additions and 8 deletions

View File

@ -0,0 +1,28 @@
use anyhow::Result;
use crate::{
compile::{Compile, CompileContext},
IR,
};
pub mod rust;
pub fn compile<T: Compile>(ir: IR, output: &str) -> Result<()> {
let mut ctx = CompileContext::new(output);
let mut compiler = T::new(&ir.options)?;
compiler.start(&mut ctx)?;
for step in ir.steps.iter() {
match step {
crate::ir::Step::Type(definition) => compiler.generate_type(&mut ctx, &definition)?,
crate::ir::Step::Enum(definition) => compiler.generate_enum(&mut ctx, &definition)?,
crate::ir::Step::Service(definition) => {
compiler.generate_service(&mut ctx, &definition)?
}
}
}
compiler.finalize(&mut ctx, &ir)?;
Ok(())
}