diff --git a/asm_utils/src/data_parser.rs b/asm_utils/src/data_parser.rs index a3a4be0cda..63b97520fb 100644 --- a/asm_utils/src/data_parser.rs +++ b/asm_utils/src/data_parser.rs @@ -91,13 +91,15 @@ fn extract_data_value( arguments: &[Argument], ) -> Vec { match (directive, arguments) { + (".zero", [Argument::Expression(Expression::Number(n))]) => { + vec![DataValue::Zero(*n as usize)] + } ( ".zero", - [Argument::Expression(Expression::Number(n))] - // TODO not clear what the second argument is - | [Argument::Expression(Expression::Number(n)), _], + [Argument::Expression(Expression::Number(n)), Argument::Expression(Expression::Number(value))], ) => { - vec![DataValue::Zero(*n as usize)] + assert!(0 <= *value && *value <= 0xff); + vec![DataValue::Direct(vec![*value as u8; *n as usize])] } (".ascii", [Argument::StringLiteral(data)]) => { vec![DataValue::Direct(data.clone())] @@ -107,38 +109,34 @@ fn extract_data_value( data.push(0); vec![DataValue::Direct(data)] } - (".word", data) => { - data - .iter() - .map(|x| { - match x { - Argument::Expression(Expression::Number(n)) =>{ - let n = *n as u32; - DataValue::Direct(vec![ - (n & 0xff) as u8, - (n >> 8 & 0xff) as u8, - (n >> 16 & 0xff) as u8, - (n >> 24 & 0xff) as u8, - ]) - } - Argument::Expression(Expression::Symbol(sym)) => { - DataValue::Reference(sym.clone()) - } - Argument::Expression( - Expression::BinaryOp(BinaryOpKind::Sub, args) - ) => match args.as_slice() { - [Expression::Symbol(a), Expression::Symbol(b)] => DataValue::Offset(a.to_string(), b.to_string()), - _ => panic!("Invalid .word directive") - } - _ => panic!("Invalid .word directive") + (".word", data) => data + .iter() + .map(|x| match x { + Argument::Expression(Expression::Number(n)) => { + let n = *n as u32; + DataValue::Direct(vec![ + (n & 0xff) as u8, + (n >> 8 & 0xff) as u8, + (n >> 16 & 0xff) as u8, + (n >> 24 & 0xff) as u8, + ]) + } + Argument::Expression(Expression::Symbol(sym)) => DataValue::Reference(sym.clone()), + Argument::Expression(Expression::BinaryOp(BinaryOpKind::Sub, args)) => { + match args.as_slice() { + [Expression::Symbol(a), Expression::Symbol(b)] => { + DataValue::Offset(a.to_string(), b.to_string()) } - }) - .collect::>() - } + _ => panic!("Invalid .word directive"), + } + } + _ => panic!("Invalid .word directive"), + }) + .collect::>(), (".byte", data) => { // TODO alignment? - vec![DataValue::Direct(data - .iter() + vec![DataValue::Direct( + data.iter() .map(|x| { if let Argument::Expression(Expression::Number(n)) = x { *n as u8 @@ -146,8 +144,9 @@ fn extract_data_value( panic!("Invalid argument to .byte directive") } }) - .collect::>())] + .collect::>(), + )] } - _ => panic!() + _ => panic!(), } } diff --git a/riscv/tests/riscv.rs b/riscv/tests/riscv.rs index cdd5ae69ed..fd70c04ac6 100644 --- a/riscv/tests/riscv.rs +++ b/riscv/tests/riscv.rs @@ -12,6 +12,13 @@ fn test_trivial() { verify_file(case, vec![], &CoProcessors::base()) } +#[test] +#[ignore = "Too slow"] +fn test_zero_with_values() { + let case = "zero_with_values.rs"; + verify_file(case, vec![], &CoProcessors::base()) +} + #[test] #[ignore = "Too slow"] fn test_poseidon_gl() { diff --git a/riscv/tests/riscv_data/zero_with_values.rs b/riscv/tests/riscv_data/zero_with_values.rs new file mode 100644 index 0000000000..797649dc49 --- /dev/null +++ b/riscv/tests/riscv_data/zero_with_values.rs @@ -0,0 +1,12 @@ +#![no_std] + +// This is stored as a data with the ".zero" directive, +// but in the variant where it repeats something else than zero. +const DATA: &str = "1111111111111111"; + +#[no_mangle] +pub fn main() { + for c in DATA.chars() { + assert_eq!(c, '1'); + } +}