memory context load

This commit is contained in:
Moysan Gabriel 2023-02-08 15:50:14 +01:00
parent 8b84dee271
commit 297a4d1d0a

View File

@ -1,6 +1,7 @@
use std::fs; use std::fs;
use std::io; use std::io;
use std::io::BufRead; use std::io::BufRead;
use crate::Machine;
const MEM_SIZE : usize = 4096; const MEM_SIZE : usize = 4096;
@ -156,35 +157,43 @@ impl Mem_Checker{
} }
fn Mem_Checker_check(m_c: &Mem_Checker, memory: [u8 ; MEM_SIZE]){ fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){
/*
* Check pc, sp machine.sp = m_c.sp;
*/ machine.pc = m_c.pc as u64;
for section in m_c.sections.iter() {
for (i,b) in section.content.iter().enumerate() {
machine.main_memory[section.addr + i] = *b;
}
}
}
/* /*
* Check sections * FOR DEBUG
*/ */
fn compare_print_m_c_machine(m_c: &Mem_Checker, machine: &mut Machine){
for(i, s) in m_c.sections.iter().enumerate() { Mem_Checker::print_Mem_Checker(m_c);
let addr = s.addr;
let len = s.len;
let segment = &s.content;
/* for section in m_c.sections.iter() {
regarder dans mem[addr]
a cette adresse verifier len octets
*/
for j in 0..(len-1){ print!("\n\n");
if segment[j] != memory[addr + j] {
println!("missmatch"); println!("Content addr : {}", section.addr);
println!("Content len (number of bytes) : {}", section.len);
for i in 0..section.len {
println!("mem[{}] = {}", section.addr + i, machine.main_memory[section.addr + i]);
} }
} }
} }
}
} }
@ -261,7 +270,31 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_create_Mem_Chercker(){ fn test_fill_memory(){
let path = "osef".to_string();
let m_c = Mem_Checker::from(&path);
let mut machine = Machine::_init_machine();
Mem_Checker::fill_memory_from_Mem_Checker(&m_c, &mut machine);
print!("\n Comparing memory from loaded context\n\n");
Mem_Checker::compare_print_m_c_machine(&m_c, &mut machine);
}
#[test]
fn test_enum_start_at_zero(){
let v = vec![1,2,3];
for (i,val) in v.iter().enumerate() {
println!("i = {} :: v[i] = {}", i, val);
}
}
#[test]
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 = Mem_Checker::from(&path);
Mem_Checker::print_Mem_Checker(&m_c); Mem_Checker::print_Mem_Checker(&m_c);