#[machine_check::machine_description]
mod machine_module {
use ::machine_check::{Ext, Signed, Unsigned};
use ::std::{
clone::Clone,
cmp::{Eq, PartialEq},
convert::Into,
fmt::Debug,
hash::Hash,
};
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct Input {
dividend: Unsigned<4>,
divisor: Unsigned<4>,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct Param {
unspecified: Signed<1>,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct State {
specified_value: Unsigned<4>,
impl_value: Unsigned<4>,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct System {
pub division_by_zero_result: Unsigned<4>,
}
impl ::machine_check::Machine for System {
type Input = Input;
type State = State;
type Param = Param;
fn init(&self, input: &Input, param: &Param) -> State {
let specified_value;
let impl_value;
if input.divisor != Unsigned::<4>::new(0) {
specified_value = input.dividend / input.divisor;
impl_value = input.dividend / input.divisor;
} else {
specified_value = Into::<Unsigned<4>>::into(Ext::<4>::ext(param.unspecified));
impl_value = self.division_by_zero_result;
}
State {
specified_value,
impl_value,
}
}
fn next(&self, state: &State, _input: &Input, _param: &Param) -> State {
State {
specified_value: state.specified_value,
impl_value: state.impl_value,
}
}
}
}
use clap::Args;
use machine_check::Unsigned;
#[derive(Args)]
struct SystemArgs {
#[arg(long = "system-wrong-div-by-zero")]
wrong_div_by_zero: bool,
}
fn main() {
let (run_args, system_args) = machine_check::parse_args::<SystemArgs>(std::env::args());
let division_by_zero_result = Unsigned::<4>::new(system_args.wrong_div_by_zero as u64);
machine_check::execute(
machine_module::System {
division_by_zero_result,
},
run_args,
);
}