use std::{io::Cursor, path::Path, str::FromStr}; use crate::errors::CompileError; mod codegen; mod errors; mod patio; mod sources { include!("./gen/sources.rs"); #[allow(unused)] pub(crate) mod transient_0 { include!("./gen/sources/transient_0.rs"); } } mod sourcetext { include!("./gen/sourcetext.rs"); #[derive(Clone, Debug, Hash, PartialEq)] pub struct SourceText { name: String, contents: String, } #[allow(unused)] pub(crate) mod transient_0 { use std::{any::Any, collections::HashMap, sync::Arc}; use crate::sourcetext::SourceText; include!("./gen/sourcetext/transient_0.rs"); fn encode_source_text( value: &SourceText, writer: &mut impl std::io::Write, shared_values: &mut HashMap, ) -> std::io::Result<()> { todo!(); } fn decode_source_text( reader: &mut impl std::io::Read, shared_values: &mut Vec>, ) -> std::io::Result { let name = crate::transient_0::decode_string(reader, shared_values)?; let contents = crate::transient_0::decode_string(reader, shared_values)?; Ok(SourceText { name, contents }) } } } #[allow(unused)] mod transient_0 { include!("./gen/transient_0.rs"); } pub fn compile( source_path: &Path, target_str: &str, main: Option<&str>, ) -> Result<(), CompileError> { let source_bytes = std::fs::read(source_path).map_err(CompileError::ReadSourceBytes)?; let compilation_unit = patio::transient_0::decode_patio_compilation_unit( &mut Cursor::new(source_bytes), &mut Vec::new(), ) .map_err(CompileError::InvalidPatioSource)?; let target_triple = target_lexicon::Triple::from_str(target_str).map_err(CompileError::ParseTargetTriple)?; let object_bytes = codegen::compile_compilation_unit(compilation_unit, main, source_path, target_triple)?; let destination_path = source_path.with_extension("o"); std::fs::write(destination_path, object_bytes).map_err(CompileError::WriteObjectFile)?; Ok(()) }