diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:21:30 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:21:30 +0100 |
| commit | d6b32251f9f607780df1cb25069785da4a634e71 (patch) | |
| tree | 51ac25c1698f92f2e93ca55b05e59323f316d25f /patio-to-cranelift | |
| parent | c290560c84e06d3ccff1c983dd577923ff9af78f (diff) | |
Support array data values in patio-to-cranelift
Diffstat (limited to 'patio-to-cranelift')
| -rw-r--r-- | patio-to-cranelift/src/codegen/values.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/patio-to-cranelift/src/codegen/values.rs b/patio-to-cranelift/src/codegen/values.rs index abc43459..74eaa669 100644 --- a/patio-to-cranelift/src/codegen/values.rs +++ b/patio-to-cranelift/src/codegen/values.rs @@ -26,8 +26,12 @@ fn write_data_value( match value { PatioDataValue::Array { element_layout: _, - elements: _, - } => todo!(), + elements, + } => { + for element in elements { + write_data_value(element, bytes, target_triple); + } + } PatioDataValue::Bool(value) => bytes.push(if *value { 1 } else { 0 }), @@ -75,7 +79,10 @@ pub(crate) fn eval_int_value(value: &PatioIntValue, target_triple: &target_lexic mod data_value_to_bytes_test { use std::str::FromStr; - use crate::patio::values::{PatioDataValue, PatioIntValue}; + use crate::patio::{ + types::PatioDataLayout, + values::{PatioDataValue, PatioIntValue}, + }; fn data_value_to_bytes(data_value: PatioDataValue) -> Box<[u8]> { super::data_value_to_bytes( @@ -85,6 +92,24 @@ mod data_value_to_bytes_test { } #[test] + fn array_is_written_as_elements() { + let data_value = PatioDataValue::Array { + element_layout: PatioDataLayout::Int32, + elements: vec![ + PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }), + PatioDataValue::Int32(PatioIntValue::Literal { value: 0x23456789 }), + ], + }; + + let bytes = data_value_to_bytes(data_value); + + assert_eq!( + bytes.as_ref(), + &[0x78, 0x56, 0x34, 0x12, 0x89, 0x67, 0x45, 0x23] + ); + } + + #[test] fn false_is_single_byte_0() { let data_value = PatioDataValue::Bool(false); |
