use camino::{Utf8Path, Utf8PathBuf};
use clap::{ArgGroup, Args};
use log::{debug, info};
use machine_check_common::ExecResult;
use serde::{Deserialize, Serialize};
use crate::CheckError;
#[derive(Debug, Clone, Args)]
#[clap(group(ArgGroup::new("property-group")
.required(true)
.multiple(true)
.args(&["property", "inherent", "gui"]),
))]
pub struct Cli {
#[arg(short, long, conflicts_with("property"), conflicts_with("inherent"))]
pub gui: bool,
#[arg(long)]
pub property: Option<String>,
#[arg(long)]
pub inherent: bool,
#[arg(long)]
pub machine_path: Option<Utf8PathBuf>,
#[arg(long)]
pub preparation_path: Option<Utf8PathBuf>,
pub system_path: Utf8PathBuf,
#[arg(long)]
pub use_decay: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VerifyResult {
pub exec: Option<ExecResult>,
pub stats: VerifyStats,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VerifyStats {
pub transcription_time: Option<f64>,
pub build_time: Option<f64>,
pub execution_time: Option<f64>,
pub prepared: Option<bool>,
}
pub(crate) fn run(args: super::Cli, verify_args: Cli) -> Result<(), CheckError> {
let abstract_machine = process_machine(&verify_args.system_path)?;
let config = machine_check_compile::VerifyConfig {
abstract_machine,
machine_path: verify_args.machine_path,
preparation_path: verify_args.preparation_path,
batch: args.batch,
gui: verify_args.gui,
property: verify_args.property,
verbose: args.verbose,
use_decay: verify_args.use_decay,
};
let verify_result = machine_check_compile::verify(config);
if let Err(machine_check_compile::Error::Gui) = verify_result {
return Ok(());
}
let exec_result = verify_result?;
info!(
"Used {} states and {} refinements.",
exec_result.stats.num_final_states, exec_result.stats.num_refinements
);
let conclusion = exec_result.result.map_err(CheckError::ExecError)?;
info!("Reached conclusion: {}", conclusion);
Ok(())
}
fn process_machine(system_path: &Utf8Path) -> Result<syn::File, CheckError> {
debug!("Constructing machine from path {:?}.", &system_path);
let machine_file = super::translate::translate(system_path)?;
Ok(machine_file)
}