Run verifier after legalizer and regalloc file tests.

Run the verify_contexti() function after invoking the legalize() and
regalloc() context functions. This will help catch bad code produced by
these passes.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-29 15:16:59 -07:00
parent 7a0092754d
commit 4c3e590bb9
4 changed files with 41 additions and 9 deletions

View File

@@ -1,8 +1,11 @@
//! Utility functions.
use std::path::Path;
use cretonne::ir::entities::AnyEntity;
use cretonne::{ir, verifier, write_function};
use std::fmt::Write;
use std::fs::File;
use std::io::{Result, Read};
use std::path::Path;
/// Read an entire file into a string.
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
@@ -29,6 +32,19 @@ pub fn match_directive<'a>(comment: &'a str, directive: &str) -> Option<&'a str>
}
}
/// Pretty-print a verifier error.
pub fn pretty_verifier_error(func: &ir::Function, err: verifier::Error) -> String {
let mut msg = err.to_string();
match err.location {
AnyEntity::Inst(inst) => {
write!(msg, "\n{}: {}\n\n", inst, func.dfg.display_inst(inst)).unwrap()
}
_ => {}
}
write_function(&mut msg, func, None).unwrap();
msg
}
#[test]
fn test_match_directive() {
assert_eq!(match_directive("; foo: bar ", "foo:"), Some("bar"));