// SPDX-License-Identifier: MIT //! Run lockstep scripts (scripts/lockstep_gen.py, or rung 3's closed-box streams) on this core //! and print the trace that scripts/lockstep_ref.py prints for sn76489-python (rungs 2 and 3). //! //! sn76489-trace SCRIPT [SCRIPT ...] [--out-dir DIR] //! //! With one script and no --out-dir the trace goes to stdout; otherwise each script's trace is //! written to DIR/.trace. The trace lines are listed in scripts/lockstep_ref.py. use std::fs; use std::path::{Path, PathBuf}; #[path = "common/trace.rs"] mod trace; fn main() { let mut args: Vec = std::env::args().skip(1).collect(); let mut out_dir: Option = None; if let Some(i) = args.iter().position(|a| a == "--out-dir") { out_dir = Some(PathBuf::from(&args[i + 1])); args.drain(i..i + 2); } for name in &args { let result = trace::trace(&fs::read_to_string(name).unwrap()); match &out_dir { None => print!("{result}"), Some(dir) => { let stem = Path::new(name).file_stem().unwrap().to_string_lossy(); fs::write(dir.join(format!("{stem}.trace")), result).unwrap(); } } } }