pr8.2
This commit is contained in:
@@ -360,6 +360,88 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
|
||||
/// Harness: run exactly `frames` logical frames deterministically.
|
||||
///
|
||||
/// This repeatedly calls `run_budget` with the provided `budget_per_slice` until
|
||||
/// a full logical frame is completed (i.e., a `FrameSync` is observed). If a
|
||||
/// terminal condition is reached earlier (Halt/EndOfRom/Panic/Trap/Breakpoint),
|
||||
/// the function returns early with all collected slice reports so far.
|
||||
pub fn run_frames(
|
||||
&mut self,
|
||||
frames: u64,
|
||||
budget_per_slice: u64,
|
||||
native: &mut dyn NativeInterface,
|
||||
ctx: &mut HostContext,
|
||||
) -> Result<Vec<BudgetReport>, String> {
|
||||
assert!(budget_per_slice > 0, "budget_per_slice must be > 0");
|
||||
|
||||
let mut out = Vec::new();
|
||||
let mut frames_done = 0u64;
|
||||
while frames_done < frames {
|
||||
let rep = self.run_budget(budget_per_slice, native, ctx)?;
|
||||
let terminal = matches!(
|
||||
rep.reason,
|
||||
LogicalFrameEndingReason::Halted
|
||||
| LogicalFrameEndingReason::EndOfRom
|
||||
| LogicalFrameEndingReason::Panic(_)
|
||||
| LogicalFrameEndingReason::Trap(_)
|
||||
| LogicalFrameEndingReason::Breakpoint
|
||||
);
|
||||
|
||||
let is_frame_end = matches!(rep.reason, LogicalFrameEndingReason::FrameSync);
|
||||
out.push(rep);
|
||||
|
||||
if terminal {
|
||||
break;
|
||||
}
|
||||
if is_frame_end {
|
||||
frames_done += 1;
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Harness: alias for `run_frames(frames, ...)`.
|
||||
pub fn run_ticks(
|
||||
&mut self,
|
||||
ticks: u64,
|
||||
budget_per_slice: u64,
|
||||
native: &mut dyn NativeInterface,
|
||||
ctx: &mut HostContext,
|
||||
) -> Result<Vec<BudgetReport>, String> {
|
||||
self.run_frames(ticks, budget_per_slice, native, ctx)
|
||||
}
|
||||
|
||||
/// Harness: run until HALT/EndOfRom/Panic/Trap/Breakpoint deterministically.
|
||||
///
|
||||
/// Repeatedly invokes `run_budget` with a fixed `budget_per_slice`, collecting
|
||||
/// each slice's report until a terminal condition is reached.
|
||||
pub fn run_until_halt(
|
||||
&mut self,
|
||||
budget_per_slice: u64,
|
||||
native: &mut dyn NativeInterface,
|
||||
ctx: &mut HostContext,
|
||||
) -> Result<Vec<BudgetReport>, String> {
|
||||
assert!(budget_per_slice > 0, "budget_per_slice must be > 0");
|
||||
|
||||
let mut out = Vec::new();
|
||||
loop {
|
||||
let rep = self.run_budget(budget_per_slice, native, ctx)?;
|
||||
let terminal = matches!(
|
||||
rep.reason,
|
||||
LogicalFrameEndingReason::Halted
|
||||
| LogicalFrameEndingReason::EndOfRom
|
||||
| LogicalFrameEndingReason::Panic(_)
|
||||
| LogicalFrameEndingReason::Trap(_)
|
||||
| LogicalFrameEndingReason::Breakpoint
|
||||
);
|
||||
out.push(rep);
|
||||
if terminal { break; }
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
|
||||
/// Executes a single instruction at the current Program Counter (PC).
|
||||
///
|
||||
/// This follows the classic CPU cycle:
|
||||
|
||||
Reference in New Issue
Block a user