From b6e159ded1db01f2162cc22457e9e46c4b8643a7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 5 Apr 2026 22:14:12 +0100 Subject: Handle int32 data values in patio-to-cranelift --- patio-to-cranelift/src/codegen/values.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/patio-to-cranelift/src/codegen/values.rs b/patio-to-cranelift/src/codegen/values.rs index c0f60517..39f8d40c 100644 --- a/patio-to-cranelift/src/codegen/values.rs +++ b/patio-to-cranelift/src/codegen/values.rs @@ -39,7 +39,11 @@ fn write_data_value( let value: i64 = eval_int_value(int_value, target_triple).into(); bytes.extend_from_slice(&value.to_le_bytes()); } - PatioDataValue::Int32(_) => todo!(), + PatioDataValue::Int32(int_value) => { + let value: i32 = eval_int_value(int_value, target_triple); + bytes.extend_from_slice(&value.to_le_bytes()); + } + PatioDataValue::Struct { elements } => { for element in elements { write_data_value(element, bytes, target_triple); @@ -113,4 +117,13 @@ mod data_value_to_bytes_test { assert_eq!(bytes.as_ref(), &[0x78, 0x56, 0x34, 0x12, 0, 0, 0, 0]); } + + #[test] + fn int_32_is_written_as_four_bytes() { + let data_value = PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }); + + let bytes = data_value_to_bytes(data_value); + + assert_eq!(bytes.as_ref(), &[0x78, 0x56, 0x34, 0x12]); + } } -- cgit v1.2.3