anthem-rs/src/commands/verify_program.rs

62 lines
1.7 KiB
Rust
Raw Normal View History

2020-05-22 18:14:56 +02:00
pub fn run<P>(program_path: P, specification_path: P,
proof_direction: crate::problem::ProofDirection, no_simplify: bool,
color_choice: crate::output::ColorChoice)
2020-05-06 21:30:27 +02:00
where
2020-05-11 03:46:20 +02:00
P: AsRef<std::path::Path>,
2020-05-06 21:30:27 +02:00
{
//let context = crate::translate::verify_properties::Context::new();
let mut problem = crate::Problem::new(color_choice);
2020-05-06 21:30:27 +02:00
log::info!("reading specification “{}”", specification_path.as_ref().display());
let specification_content = match std::fs::read_to_string(specification_path.as_ref())
{
Ok(specification_content) => specification_content,
Err(error) =>
{
log::error!("could not access specification file: {}", error);
std::process::exit(1)
},
};
// TODO: rename to read_specification
2020-05-28 05:00:56 +02:00
if let Err(error) = crate::input::parse_specification(&specification_content, &mut problem)
2020-05-06 21:30:27 +02:00
{
2020-05-28 05:00:56 +02:00
log::error!("could not read specification: {}", error);
std::process::exit(1)
2020-05-06 21:30:27 +02:00
}
log::info!("read specification “{}”", specification_path.as_ref().display());
log::info!("reading input program “{}”", program_path.as_ref().display());
// TODO: make consistent with specification call (path vs. content)
2020-05-28 05:00:56 +02:00
if let Err(error) = crate::translate::verify_properties::Translator::new(&mut problem)
.translate(program_path)
2020-05-06 21:30:27 +02:00
{
2020-05-28 05:00:56 +02:00
log::error!("could not translate input program: {}", error);
std::process::exit(1)
2020-05-06 21:30:27 +02:00
}
2020-05-28 05:00:56 +02:00
if let Err(error) = problem.check_consistency(proof_direction)
2020-05-13 07:41:01 +02:00
{
2020-05-28 05:00:56 +02:00
log::error!("{}", error);
std::process::exit(1)
2020-05-13 07:41:01 +02:00
}
2020-05-22 18:14:56 +02:00
if !no_simplify
{
2020-05-28 05:00:56 +02:00
if let Err(error) = problem.simplify()
2020-05-22 18:14:56 +02:00
{
2020-05-28 05:00:56 +02:00
log::error!("could not simplify translated program: {}", error);
std::process::exit(1)
2020-05-22 18:14:56 +02:00
}
}
2020-05-28 05:00:56 +02:00
if let Err(error) = problem.prove(proof_direction)
2020-05-06 21:30:27 +02:00
{
2020-05-28 05:00:56 +02:00
log::error!("could not verify program: {}", error);
std::process::exit(1)
2020-05-06 21:30:27 +02:00
}
}