1use std::fmt::{Display, Formatter};
6
7use base::instruction::Instruction;
8use base::prelude::{Address, SymbolicInstruction};
9
10#[derive(Debug, Clone)]
18pub struct CurrentInstructionDiagnostics {
19 pub current_instruction: Instruction,
22 pub instruction_address: Address,
26}
27
28impl Display for &CurrentInstructionDiagnostics {
29 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
30 if let Ok(symbolic) = SymbolicInstruction::try_from(&self.current_instruction) {
31 write!(f, "instruction {symbolic}")?;
32 } else {
33 write!(f, "instruction {:>012o}", self.current_instruction.bits(),)?;
34 };
35 write!(f, " at address {:>06o}", self.instruction_address)
36 }
37}
38
39pub trait DiagnosticFetcher {
41 fn diagnostics(self) -> CurrentInstructionDiagnostics;
42}
43
44impl DiagnosticFetcher for CurrentInstructionDiagnostics {
45 fn diagnostics(self) -> CurrentInstructionDiagnostics {
46 self
47 }
48}
49
50impl DiagnosticFetcher for &CurrentInstructionDiagnostics {
51 fn diagnostics(self) -> CurrentInstructionDiagnostics {
52 self.clone()
53 }
54}