aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-04 09:31:51 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-04 09:31:51 +0100
commitb7d5f0883544be47b675d11baff3a79bd028996b (patch)
treec214f20cd6ad96bc8358de19a2620d730af26a97
parent0e22bc328e98235986c1ac7c4b7135d0d04d43f0 (diff)
Reorder flatbuffer conversions
-rw-r--r--patio-to-cranelift/src/patio/flatbuffers.rs136
1 files 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<patio_generated::patio::PatioType<'_>> 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<patio_generated::patio::PatioDataLayout<'_>> 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<patio_generated::patio::PatioLocal<'_>> for PatioLocal {
fn from(value: patio_generated::patio::PatioLocal<'_>) -> Self {
@@ -114,6 +51,8 @@ impl From<patio_generated::patio::PatioVisibility> for PatioVisibility {
}
}
+// == Int values ==
+
impl From<patio_generated::patio::PatioIntValue<'_>> for PatioIntValue {
fn from(value: patio_generated::patio::PatioIntValue<'_>) -> Self {
match value.value_type() {
@@ -147,3 +86,72 @@ impl From<patio_generated::patio::PatioIntValue<'_>> for PatioIntValue {
}
}
}
+
+// == Types ==
+
+impl From<patio_generated::patio::PatioType<'_>> 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<patio_generated::patio::PatioDataLayout<'_>> 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
+ )
+ }
+ }
+ }
+}