diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:14:12 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:14:12 +0100 |
| commit | b6e159ded1db01f2162cc22457e9e46c4b8643a7 (patch) | |
| tree | 2165954eafa2d75cbcc02510260af18874788670 | |
| parent | b73b9d8bc68ef53ae6ade149809f9f84c0b8a80a (diff) | |
Handle int32 data values in patio-to-cranelift
| -rw-r--r-- | patio-to-cranelift/src/codegen/values.rs | 15 |
1 files changed, 14 insertions, 1 deletions
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]); + } } |
