Cleaned clippy lint warnings from machine.rs

This commit is contained in:
François Autin 2023-03-10 10:59:14 +01:00
parent 44e3f586e2
commit be8435cf83
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -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<File> {
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);