From 4425ac747e650fe4cb3ae03865160cb5f09123b1 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 15 Feb 2023 15:45:37 +0100 Subject: [PATCH 1/2] debuging mem_checker::from --- src/simulator/mem_cmp.rs | 12 +++++---- test_file_section.txt | 23 ++++++++++++------ .../simple_arithmerics/unsigned_addition.o | Bin 0 -> 1088 bytes 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.o diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index abddae9..c4a8a5a 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -94,7 +94,10 @@ impl Mem_Checker{ fn from(path: &String) -> Mem_Checker { let file = fs::File::open("test_file_section.txt").expect("Wrong filename"); - let reader = io::BufReader::new(file); + let reader = io::BufReader::new(&file); + let reader2 = io::BufReader::new(&file); + let lines = reader.lines(); + let length = reader2.lines().count(); let mut pc: usize = 0; let mut sp: usize = 0; @@ -103,15 +106,15 @@ impl Mem_Checker{ let mut tmp_addr_str: String = String::new(); let mut tmp_len_str: String = String::new(); - for (i,line) in reader.lines().enumerate() { + for (i,line) in lines.enumerate() { let current_line = line.unwrap(); - if i == current_line.len()-2 { + if i == length-2 { //Lecture de PC pc = string_hex_to_usize(¤t_line); } - else if i == current_line.len()-1 { + else if i == length-1 { //Lecture SP sp = string_hex_to_usize(¤t_line); } @@ -277,7 +280,6 @@ mod tests { } - #[test] fn test_enum_start_at_zero(){ let v = vec![1,2,3]; diff --git a/test_file_section.txt b/test_file_section.txt index 05d3ead..df1b0d2 100644 --- a/test_file_section.txt +++ b/test_file_section.txt @@ -1,8 +1,15 @@ -0 -0 -FF FF -F4A12200 -A0 0A -01022B -0B 0F -FFACBC5CEF +addi sp,sp,-32 +sd s0,24(sp) +addi s0,sp,32 +sw zero,-20(s0) +li a5,1 +sw a5,-24(s0) +lw a5,-20(s0) +mv a4,a5 +lw a5,-24(s0) +addw a5,a4,a5 +sw a5,-20(s0) +nop +ld s0,24(sp) +addi sp,sp,32 +ret \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.o b/test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.o new file mode 100644 index 0000000000000000000000000000000000000000..3d69445f952a67be3ab705cbfff4767457813b8b GIT binary patch literal 1088 zcmbtTPfG$(5TE^H>dlfOs6bJ)ARen}M0hZyy!0Jp)y4L(tGG`w2uck40A2hdow{`B zL-aKwq1)CxdoLd^>EgidZ{|1id-G=4y*g?AqtcHefS*xgiLN0CQ)aU#u{q$&K(BzTJ1Eo-zhpy z*(n`aR^j9zRVb1ovEVF)`Mw*phM;YsYbGN7;c>|=_N<17FQoo8HiHT8U(1S&F4UDh7Vwc6_JZu-k2yx?P{NAUgujc6|U6 zTzk}RBGUd3UI~vnBMPK#QyWM#2!OP@p6B?;&9_NxO8aheK%GEzS_yYh&9<szKHD3M2@Ol;0jpwl-wu1f;wd_pwgA)CBF(;eoFR+YByn9csVg8g8X(b_a zf@ZPwYY7@&xc9~}ipb_<4>R`NFpJ}(?vC+O-e`{nlBxaIF}FpF literal 0 HcmV?d00001 From 9fab99e31f39d73df97ddd4f5e4ef4a9e58051da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rativel?= Date: Wed, 15 Feb 2023 16:14:27 +0100 Subject: [PATCH 2/2] make struct and function public --- src/simulator/mem_cmp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index abddae9..3e2ccd6 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -82,7 +82,7 @@ impl Section{ /* * Representation de l'etat de la mémoire (apres execution.... a confirmer), sous forme de sections */ -struct Mem_Checker{ +pub struct Mem_Checker{ pc: usize, sp: usize, sections: Vec
, @@ -91,7 +91,7 @@ struct Mem_Checker{ impl Mem_Checker{ - fn from(path: &String) -> Mem_Checker { + pub fn from(path: &String) -> Mem_Checker { let file = fs::File::open("test_file_section.txt").expect("Wrong filename"); let reader = io::BufReader::new(file); @@ -151,7 +151,7 @@ impl Mem_Checker{ } - fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){ + pub fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){ machine.sp = m_c.sp; machine.pc = m_c.pc as u64;