Warning fix

This commit is contained in:
Rémi Rativel 2023-03-08 13:04:03 +01:00
parent da30122c87
commit e60ca57bc7

View File

@ -1,5 +1,4 @@
use std::fs; use std::fs;
use std::io;
use std::io::BufRead; use std::io::BufRead;
use std::io::BufReader; use std::io::BufReader;
use std::io::Lines; use std::io::Lines;
@ -70,11 +69,11 @@ impl Section{
} }
} }
Section{addr:addr, len:len, content:content} Section{addr, len, content}
} }
fn print_Section(s: &Section){ fn print_section(s: &Section){
println!("ADDR :: {:x}", s.addr); println!("ADDR :: {:x}", s.addr);
println!("LEN :: {:x}", s.len); println!("LEN :: {:x}", s.len);
println!("CONTENT :: {:?}", s.content); println!("CONTENT :: {:?}", s.content);
@ -84,14 +83,14 @@ impl Section{
/* /*
* Representation de l'etat de la mémoire (apres execution.... a confirmer), sous forme de sections * Representation de l'etat de la mémoire (apres execution.... a confirmer), sous forme de sections
*/ */
pub struct Mem_Checker{ pub struct MemChecker{
pc: usize, pc: usize,
sp: usize, sp: usize,
sections: Vec<Section>, sections: Vec<Section>,
} }
impl Mem_Checker{ impl MemChecker{
///Translate lines of a file in e Vector of String ///Translate lines of a file in e Vector of String
///We need this method to parse the memory we received ///We need this method to parse the memory we received
@ -104,7 +103,7 @@ impl Mem_Checker{
/// - A vector of String where each line of the file os an element of the vector /// - A vector of String where each line of the file os an element of the vector
fn vect_from_lines(lines: &mut Lines<BufReader<fs::File>>, pc: &mut usize, sp: &mut usize) -> Vec<String>{ fn vect_from_lines(lines: &mut Lines<BufReader<fs::File>>, pc: &mut usize, sp: &mut usize) -> Vec<String>{
let mut vector = Vec::new(); let mut vector = Vec::new();
for (i,line) in lines.enumerate() { for (_,line) in lines.enumerate() {
vector.push(line.unwrap()); vector.push(line.unwrap());
} }
let size = vector.len(); let size = vector.len();
@ -121,16 +120,16 @@ impl Mem_Checker{
/// ///
/// ### Return /// ### Return
/// Mem-checker filled /// Mem-checker filled
pub fn from(path: &String) -> Mem_Checker { pub fn from(path: &String) -> MemChecker {
let file = fs::File::open(path).expect("Wrong filename"); let file = fs::File::open(path).expect("Wrong filename");
let reader = io::BufReader::new(file); let reader = BufReader::new(file);
let mut lines = reader.lines(); let mut lines = reader.lines();
let mut pc: usize = 0; let mut pc: usize = 0;
let mut sp: usize = 0; let mut sp: usize = 0;
let vector = Mem_Checker::vect_from_lines(&mut lines, &mut pc, &mut sp); let vector = MemChecker::vect_from_lines(&mut lines, &mut pc, &mut sp);
let mut sections: Vec<Section> = Vec::new(); let mut sections: Vec<Section> = Vec::new();
let mut tmp_addr_str: String = String::new(); let mut tmp_addr_str: String = String::new();
@ -159,7 +158,7 @@ impl Mem_Checker{
} }
Mem_Checker{pc:pc, sp:sp, sections:sections} MemChecker{pc, sp, sections}
} }
@ -168,13 +167,13 @@ impl Mem_Checker{
/// ### Parameter /// ### Parameter
/// ///
/// - **m_c** Contains the data we want to print /// - **m_c** Contains the data we want to print
pub fn print_Mem_Checker(m_c: &Mem_Checker){ pub fn print_mem_checker(m_c: &MemChecker){
println!("PC :: {:x}", m_c.pc); println!("PC :: {:x}", m_c.pc);
println!("SP :: {:x}", m_c.sp); println!("SP :: {:x}", m_c.sp);
for(i,s) in m_c.sections.iter().enumerate() { for(i,s) in m_c.sections.iter().enumerate() {
println!("\nSection {}\n", i); println!("\nSection {}\n", i);
Section::print_Section(&s); Section::print_section(&s);
} }
} }
@ -185,7 +184,7 @@ impl Mem_Checker{
/// ///
/// - **m_c** contains the data /// - **m_c** contains the data
/// - **machine** contains the memry to fill /// - **machine** contains the memry to fill
pub fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){ pub fn fill_memory_from_mem_checker(m_c: &MemChecker, machine: &mut Machine){
machine.sp = m_c.sp; machine.sp = m_c.sp;
machine.int_reg.set_reg(2, m_c.pc as i64); machine.int_reg.set_reg(2, m_c.pc as i64);
@ -204,9 +203,9 @@ impl Mem_Checker{
/* /*
* FOR DEBUG * FOR DEBUG
*/ */
fn compare_print_m_c_machine(m_c: &Mem_Checker, machine: &mut Machine){ fn compare_print_m_c_machine(m_c: &MemChecker, machine: &mut Machine){
Mem_Checker::print_Mem_Checker(m_c); MemChecker::print_mem_checker(m_c);
for section in m_c.sections.iter() { for section in m_c.sections.iter() {
@ -222,7 +221,7 @@ impl Mem_Checker{
} }
pub fn compare_machine_memory(m_c: &Mem_Checker, machine: &Machine) -> bool { pub fn compare_machine_memory(m_c: &MemChecker, machine: &Machine) -> bool {
for section in m_c.sections.iter() { for section in m_c.sections.iter() {
for i in 0..section.len { for i in 0..section.len {
@ -252,7 +251,7 @@ fn string_hex_to_usize(s: &String) -> usize {
for (i,c )in s.chars().enumerate(){ for (i,c )in s.chars().enumerate(){
//println!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32)); //println!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32));
let tmp: usize = (one_hex_to_dec(c) as usize); let tmp: usize = one_hex_to_dec(c) as usize;
ret_value += base.pow(max_pow - (i as u32))*tmp; ret_value += base.pow(max_pow - (i as u32))*tmp;
} }
@ -297,7 +296,7 @@ fn two_hex_to_u8(c1: char, c2: char) -> u8 {
*/ */
fn test_show_sections_file(){ fn test_show_sections_file(){
let file = fs::File::open("test_file_section.txt").expect("Wrong filename"); let file = fs::File::open("test_file_section.txt").expect("Wrong filename");
let reader = io::BufReader::new(file); let reader = BufReader::new(file);
for line in reader.lines() { for line in reader.lines() {
//println!("Tailles de la ligne : {}", //println!("Tailles de la ligne : {}",
@ -318,14 +317,14 @@ mod tests {
#[test] #[test]
fn test_fill_memory(){ fn test_fill_memory(){
let path = "osef".to_string(); let path = "osef".to_string();
let m_c = Mem_Checker::from(&path); let m_c = MemChecker::from(&path);
let mut machine = Machine::_init_machine(); let mut machine = Machine::_init_machine();
Mem_Checker::fill_memory_from_Mem_Checker(&m_c, &mut machine); MemChecker::fill_memory_from_mem_checker(&m_c, &mut machine);
print!("\n Comparing memory from loaded context\n\n"); print!("\n Comparing memory from loaded context\n\n");
Mem_Checker::compare_print_m_c_machine(&m_c, &mut machine); MemChecker::compare_print_m_c_machine(&m_c, &mut machine);
} }
@ -339,10 +338,10 @@ mod tests {
} }
#[test] #[test]
fn test_create_Mem_Checker(){ fn test_create_mem_checker(){
let path: String = "osef".to_string(); let path: String = "osef".to_string();
let m_c = Mem_Checker::from(&path); let m_c = MemChecker::from(&path);
Mem_Checker::print_Mem_Checker(&m_c); MemChecker::print_mem_checker(&m_c);
} }