From be8435cf834780cc2d226b3122fcd28c95102e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Fri, 10 Mar 2023 10:59:14 +0100 Subject: [PATCH] Cleaned clippy lint warnings from machine.rs --- src/simulator/machine.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 48ff028..9aeadef 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -149,7 +149,7 @@ impl Machine { /// ### Parameters /// /// - **machine** contains the memory - pub fn extract_memory(machine: &mut Machine){ + pub fn _extract_memory(machine: &mut Machine){ let file_path = "burritos_memory.txt"; let write_to_file = |path| -> std::io::Result { let mut file = File::create(path)?; @@ -221,8 +221,8 @@ impl Machine { panic!("ERROR : number max of instructions rushed"); } let mut val: [u8; 4] = [0; 4]; - for i in 0..4 { - val[i] = machine.main_memory[machine.pc as usize + i]; + for (i, mut _item) in val.iter_mut().enumerate() { + _item = &mut machine.main_memory[machine.pc as usize + i]; } let val = u32::from_be_bytes(val) as u64; @@ -345,7 +345,7 @@ impl Machine { machine.int_reg.set_reg(inst.rd as usize, machine.int_reg.get_reg(inst.rs1 as usize) + inst.imm12_I_signed as i64); }, RISCV_OPI_SLTI => { - machine.int_reg.set_reg(inst.rd as usize, if machine.int_reg.get_reg(inst.rs1 as usize) < inst.imm12_I_signed as i64 { 1 } else { 0 } ); + machine.int_reg.set_reg(inst.rd as usize, (machine.int_reg.get_reg(inst.rs1 as usize) < inst.imm12_I_signed as i64) as i64); }, RISCV_OPI_XORI => { machine.int_reg.set_reg(inst.rd as usize, machine.int_reg.get_reg(inst.rs1 as usize) ^ inst.imm12_I_signed as i64); @@ -465,12 +465,11 @@ impl Machine { machine.int_reg.set_reg(inst.rd as usize, result); }, RISCV_OPIW_SRW => { - let result; - if inst.funct7 == RISCV_OPIW_SRW_SRLIW { - result = (local_data >> inst.shamt) & machine.shiftmask[32 + inst.shamt as usize] as i64; + let result = if inst.funct7 == RISCV_OPIW_SRW_SRLIW { + (local_data >> inst.shamt) & machine.shiftmask[32 + inst.shamt as usize] as i64 } else { // SRAIW - result = local_data >> inst.shamt; - } + local_data >> inst.shamt + }; machine.int_reg.set_reg(inst.rd as usize, result); }, _ => { @@ -627,13 +626,13 @@ impl Machine { RISCV_FP_FCMP => { match inst.funct3 { RISCV_FP_FCMP_FEQ => { - machine.int_reg.set_reg(inst.rd as usize, if machine.fp_reg.get_reg(inst.rs1 as usize) == machine.fp_reg.get_reg(inst.rs2 as usize) {1} else {0}); + machine.int_reg.set_reg(inst.rd as usize, (machine.fp_reg.get_reg(inst.rs1 as usize) == machine.fp_reg.get_reg(inst.rs2 as usize)) as i64); }, RISCV_FP_FCMP_FLT => { - machine.int_reg.set_reg(inst.rd as usize, if machine.fp_reg.get_reg(inst.rs1 as usize) < machine.fp_reg.get_reg(inst.rs2 as usize) {1} else {0}); + machine.int_reg.set_reg(inst.rd as usize, (machine.fp_reg.get_reg(inst.rs1 as usize) < machine.fp_reg.get_reg(inst.rs2 as usize)) as i64); }, RISCV_FP_FCMP_FLE => { - machine.int_reg.set_reg(inst.rd as usize, if machine.fp_reg.get_reg(inst.rs1 as usize) <= machine.fp_reg.get_reg(inst.rs2 as usize) {1} else {0}); + machine.int_reg.set_reg(inst.rd as usize, (machine.fp_reg.get_reg(inst.rs1 as usize) <= machine.fp_reg.get_reg(inst.rs2 as usize)) as i64); }, _ => { panic!("this instruction ({}) doesn't exists", inst.value); @@ -653,14 +652,14 @@ impl Machine { _ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)}, } - return 0; + 0 } /// print memory FOR DEBUG /// /// "@"adresse [16 bytes] - pub fn print_memory(machine : &mut Machine, from: usize, to: usize) { + pub fn _print_memory(machine : &mut Machine, from: usize, to: usize) { for i in from..to { if i%16 == 0 { print!("\n@{:04x} ", i);