From b7d5f0883544be47b675d11baff3a79bd028996b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 4 Apr 2026 09:31:51 +0100 Subject: Reorder flatbuffer conversions --- patio-to-cranelift/src/patio/flatbuffers.rs | 136 +++++++++++++++------------- 1 file changed, 72 insertions(+), 64 deletions(-) diff --git a/patio-to-cranelift/src/patio/flatbuffers.rs b/patio-to-cranelift/src/patio/flatbuffers.rs index d6c2d1ff..ad4e1c8e 100644 --- a/patio-to-cranelift/src/patio/flatbuffers.rs +++ b/patio-to-cranelift/src/patio/flatbuffers.rs @@ -10,70 +10,7 @@ use crate::{ }, }; -impl From> for PatioType { - fn from(value: patio_generated::patio::PatioType<'_>) -> Self { - match value.value_type() { - PatioTypeValue::PatioBoolType => Self::Bool, - PatioTypeValue::PatioByteType => Self::Byte, - PatioTypeValue::PatioDataPtrType => Self::DataPtr, - PatioTypeValue::PatioFunctionPtrType => Self::FunctionPtr, - PatioTypeValue::PatioIntType => Self::Int, - PatioTypeValue::PatioInt32Type => Self::Int32, - PatioTypeValue::PatioVoidType => Self::Void, - - type_type => { - todo!( - "Unhandled type type: {:?} {}", - type_type.variant_name(), - type_type.0 - ) - } - } - } -} - -impl From> for PatioDataLayout { - fn from(value: patio_generated::patio::PatioDataLayout<'_>) -> Self { - match value.value_type() { - PatioDataLayoutValue::PatioDataLayoutArray => { - let array = value.value_as_patio_data_layout_array().unwrap(); - PatioDataLayout::array(array.element().into(), array.size()) - } - - PatioDataLayoutValue::PatioDataLayoutBool => PatioDataLayout::Bool, - - PatioDataLayoutValue::PatioDataLayoutByte => PatioDataLayout::Byte, - - PatioDataLayoutValue::PatioDataLayoutDataPtr => PatioDataLayout::DataPtr, - - PatioDataLayoutValue::PatioDataLayoutFunctionPtr => PatioDataLayout::FunctionPtr, - - PatioDataLayoutValue::PatioDataLayoutInt => PatioDataLayout::Int, - - PatioDataLayoutValue::PatioDataLayoutInt32 => PatioDataLayout::Int32, - - PatioDataLayoutValue::PatioDataLayoutStruct => { - let struct_ = value.value_as_patio_data_layout_struct().unwrap(); - - PatioDataLayout::struct_( - struct_ - .elements() - .iter() - .map(|element| element.into()) - .collect(), - ) - } - - layout_type => { - todo!( - "Unhandled data layout type: {:?} {}", - layout_type.variant_name(), - layout_type.0 - ) - } - } - } -} +// == Compilation unit elements == impl From> for PatioLocal { fn from(value: patio_generated::patio::PatioLocal<'_>) -> Self { @@ -114,6 +51,8 @@ impl From for PatioVisibility { } } +// == Int values == + impl From> for PatioIntValue { fn from(value: patio_generated::patio::PatioIntValue<'_>) -> Self { match value.value_type() { @@ -147,3 +86,72 @@ impl From> for PatioIntValue { } } } + +// == Types == + +impl From> for PatioType { + fn from(value: patio_generated::patio::PatioType<'_>) -> Self { + match value.value_type() { + PatioTypeValue::PatioBoolType => Self::Bool, + PatioTypeValue::PatioByteType => Self::Byte, + PatioTypeValue::PatioDataPtrType => Self::DataPtr, + PatioTypeValue::PatioFunctionPtrType => Self::FunctionPtr, + PatioTypeValue::PatioIntType => Self::Int, + PatioTypeValue::PatioInt32Type => Self::Int32, + PatioTypeValue::PatioVoidType => Self::Void, + + type_type => { + todo!( + "Unhandled type type: {:?} {}", + type_type.variant_name(), + type_type.0 + ) + } + } + } +} + +// == Data layouts == + +impl From> for PatioDataLayout { + fn from(value: patio_generated::patio::PatioDataLayout<'_>) -> Self { + match value.value_type() { + PatioDataLayoutValue::PatioDataLayoutArray => { + let array = value.value_as_patio_data_layout_array().unwrap(); + PatioDataLayout::array(array.element().into(), array.size()) + } + + PatioDataLayoutValue::PatioDataLayoutBool => PatioDataLayout::Bool, + + PatioDataLayoutValue::PatioDataLayoutByte => PatioDataLayout::Byte, + + PatioDataLayoutValue::PatioDataLayoutDataPtr => PatioDataLayout::DataPtr, + + PatioDataLayoutValue::PatioDataLayoutFunctionPtr => PatioDataLayout::FunctionPtr, + + PatioDataLayoutValue::PatioDataLayoutInt => PatioDataLayout::Int, + + PatioDataLayoutValue::PatioDataLayoutInt32 => PatioDataLayout::Int32, + + PatioDataLayoutValue::PatioDataLayoutStruct => { + let struct_ = value.value_as_patio_data_layout_struct().unwrap(); + + PatioDataLayout::struct_( + struct_ + .elements() + .iter() + .map(|element| element.into()) + .collect(), + ) + } + + layout_type => { + todo!( + "Unhandled data layout type: {:?} {}", + layout_type.variant_name(), + layout_type.0 + ) + } + } + } +} -- cgit v1.2.3