diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-06 10:51:37 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-06 10:51:37 -0700 |
commit | b7111860f29bb123365794a8cdabbbf473463204 (patch) | |
tree | d6533127bcacd74b2fbe90874bede83f90fcb33f /src/simulator.rs | |
parent | e6d2693a836788894373af1b35ed678b3561f6ac (diff) |
Get rid of Box in memory refs
Diffstat (limited to 'src/simulator.rs')
-rw-r--r-- | src/simulator.rs | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/simulator.rs b/src/simulator.rs index 0101c44..4feb1c0 100644 --- a/src/simulator.rs +++ b/src/simulator.rs @@ -368,34 +368,49 @@ impl<'a> Simulator<'a> { } } - pub fn run(&mut self) { - loop { - let mut ran = false; - for core in self.cores.iter_mut() { - if !core.running { - continue; - } + fn step(&mut self) -> bool { + let mut ran = false; + for core in self.cores.iter_mut() { + if !core.running { + continue; + } - let pc = core.pc; - let pc = core.mmu.translate(pc); - let inst = self.memory.borrow_mut().read_instruction(pc); + let pc = core.pc; + let pc = core.mmu.translate(pc); + let inst = self.memory.borrow_mut().read_instruction(pc); - if let Some(inst) = inst { - core.step(inst); - } - else { - // TODO: trap - } + if let Some(inst) = inst { + core.step(inst); + } + else { + // TODO: trap + } - core.cache.borrow_mut().step(); - ran = true; + core.cache.borrow_mut().step(); + ran = true; + } + if !ran { + println!("All cores are not running, stopping..."); + for (i, core) in self.cores.iter().enumerate() { + println!("Core {}: stalled {} of {}", i, core.stall_count, core.cycle_count); } - if !ran { - println!("All cores are not running, stopping..."); - for (i, core) in self.cores.iter().enumerate() { - println!("Core {}: stalled {} of {}", i, core.stall_count, core.cycle_count); - } - break; + } + + ran + } + + pub fn run(&mut self) { + loop { + if !self.step() { + break + } + } + } + + pub fn run_max(&mut self, cycles: usize) { + for _ in 0..cycles { + if !self.step() { + break } } } |