use crate::api::get_defs;
use crate::api::instrument::MAX_ERRORS;
use crate::common::error::ErrorGen;
use crate::common::instr;
use crate::parser;
use crate::wast::test_harness::setup_and_run_tests;
use log::debug;
use std::path::PathBuf;
use std::process::Command;
pub fn print_info(
rule: String,
defs_path: Option<String>,
print_vars: bool,
print_functions: bool,
) -> Result<(), Box<ErrorGen>> {
let mut err = ErrorGen::new("".to_string(), rule.clone(), MAX_ERRORS);
let def_yamls = get_defs(defs_path);
parser::whamm_parser::print_info(rule, &def_yamls, print_vars, print_functions, &mut err)?;
if err.has_errors {
Err(Box::new(err))
} else {
Ok(())
}
}
pub fn write_to_file(module: Vec<u8>, output_wasm_path: String) {
instr::write_to_file(module, output_wasm_path);
}
pub fn run_wast_harness() -> Result<(), std::io::Error> {
crate::wast::test_harness::clean();
let wast_tests = crate::wast::test_harness::find_wast_tests();
setup_and_run_tests(&wast_tests)?;
Ok(())
}
pub fn run_wast_tests_at(wast_tests: &Vec<PathBuf>) {
setup_and_run_tests(wast_tests).expect("WAST Test failed!");
println!("The wast test passed!");
}
pub fn wasm2wat_on_file(instrumented_wasm_path: &str) {
debug!("Running 'wasm-tools validate' on file: {instrumented_wasm_path}");
let res = Command::new("wasm-tools")
.arg("validate")
.arg(instrumented_wasm_path)
.output()
.expect("failed to execute process");
if !res.status.success() {
println!("wasm-tools validate failed on: {}", instrumented_wasm_path);
println!("STDOUT: {}", String::from_utf8(res.stdout).unwrap());
println!("STDERR: {}", String::from_utf8(res.stderr).unwrap());
}
assert!(res.status.success());
}