diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-31 14:45:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-31 15:22:40 +0100 |
| commit | 91860485774924e82da9b0774179d4c3c8da810a (patch) | |
| tree | e06f52f147502e80aea139c20adac706479cb7ea /patio-to-cranelift/src/lib.rs | |
| parent | 410fff7b7ecf6f36a0a46ab1d90553169e3728f1 (diff) | |
Use transient-0 instead of flatbuffersmain
Diffstat (limited to 'patio-to-cranelift/src/lib.rs')
| -rw-r--r-- | patio-to-cranelift/src/lib.rs | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/patio-to-cranelift/src/lib.rs b/patio-to-cranelift/src/lib.rs index 80d22840..2c7e8d8f 100644 --- a/patio-to-cranelift/src/lib.rs +++ b/patio-to-cranelift/src/lib.rs @@ -1,19 +1,61 @@ -use std::{path::Path, str::FromStr}; +use std::{io::Cursor, path::Path, str::FromStr}; -use crate::{errors::CompileError, patio::compilation_unit::PatioCompilationUnit}; - -#[allow(dead_code, unused_imports)] -#[path = "./gen/patio_generated.rs"] -mod patio_generated; - -#[allow(dead_code, unused_imports)] -#[path = "./gen/sources_generated.rs"] -mod sources_generated; +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<usize, i64>, + ) -> std::io::Result<()> { + todo!(); + } + + fn decode_source_text( + reader: &mut impl std::io::Read, + shared_values: &mut Vec<Arc<dyn Any + Sync + Send>>, + ) -> std::io::Result<SourceText> { + 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, @@ -21,10 +63,11 @@ pub fn compile( ) -> Result<(), CompileError> { let source_bytes = std::fs::read(source_path).map_err(CompileError::ReadSourceBytes)?; - let compilation_unit: PatioCompilationUnit = - patio_generated::patio::root_as_patio_compilation_unit(&source_bytes) - .map_err(CompileError::InvalidFlatbuffer)? - .into(); + 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)?; |
