Browse Source

Run the verifier in the Context methods when it is enabled.

The test drivers can stop calling comp_ctx.verify because legalize() and
regalloc() do it themselves now.

This also makes it possible for those two passes to return other
CtonError codes in the future, not just verifier errors.
pull/3/head
Jakob Stoklund Olesen 8 years ago
parent
commit
225ed39fbd
  1. 16
      lib/cretonne/src/context.rs
  2. 7
      src/filetest/legalizer.rs
  3. 10
      src/filetest/regalloc.rs
  4. 10
      src/utils.rs

16
lib/cretonne/src/context.rs

@ -15,6 +15,7 @@ use ir::Function;
use isa::TargetIsa; use isa::TargetIsa;
use legalize_function; use legalize_function;
use regalloc; use regalloc;
use result::CtonResult;
use verifier; use verifier;
/// Persistent data structures and compilation pipeline. /// Persistent data structures and compilation pipeline.
@ -56,9 +57,19 @@ impl Context {
verifier::verify_context(self) verifier::verify_context(self)
} }
/// Run the verifier only if the `enable_verifier` setting is true.
pub fn verify_if(&self, isa: &TargetIsa) -> CtonResult {
if isa.flags().enable_verifier() {
self.verify(isa).map_err(Into::into)
} else {
Ok(())
}
}
/// Run the legalizer for `isa` on the function. /// Run the legalizer for `isa` on the function.
pub fn legalize(&mut self, isa: &TargetIsa) { pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult {
legalize_function(&mut self.func, &mut self.cfg, isa); legalize_function(&mut self.func, &mut self.cfg, isa);
self.verify_if(isa)
} }
/// Recompute the control flow graph and dominator tree. /// Recompute the control flow graph and dominator tree.
@ -68,8 +79,9 @@ impl Context {
} }
/// Run the register allocator. /// Run the register allocator.
pub fn regalloc(&mut self, isa: &TargetIsa) { pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult {
self.regalloc self.regalloc
.run(isa, &mut self.func, &self.cfg, &self.domtree); .run(isa, &mut self.func, &self.cfg, &self.domtree);
self.verify_if(isa)
} }
} }

7
src/filetest/legalizer.rs

@ -8,7 +8,7 @@ use cretonne::{self, write_function};
use cretonne::ir::Function; use cretonne::ir::Function;
use cton_reader::TestCommand; use cton_reader::TestCommand;
use filetest::subtest::{SubTest, Context, Result, run_filecheck}; use filetest::subtest::{SubTest, Context, Result, run_filecheck};
use utils::pretty_verifier_error; use utils::pretty_error;
struct TestLegalizer; struct TestLegalizer;
@ -40,9 +40,8 @@ impl SubTest for TestLegalizer {
let isa = context.isa.expect("legalizer needs an ISA"); let isa = context.isa.expect("legalizer needs an ISA");
comp_ctx.flowgraph(); comp_ctx.flowgraph();
comp_ctx.legalize(isa); comp_ctx.legalize(isa)
comp_ctx.verify(isa) .map_err(|e| pretty_error(&comp_ctx.func, e))?;
.map_err(|e| pretty_verifier_error(&comp_ctx.func, e))?;
let mut text = String::new(); let mut text = String::new();
write_function(&mut text, &comp_ctx.func, Some(isa)).map_err(|e| e.to_string())?; write_function(&mut text, &comp_ctx.func, Some(isa)).map_err(|e| e.to_string())?;

10
src/filetest/regalloc.rs

@ -10,7 +10,7 @@ use cretonne::{self, write_function};
use cton_reader::TestCommand; use cton_reader::TestCommand;
use filetest::subtest::{SubTest, Context, Result, run_filecheck}; use filetest::subtest::{SubTest, Context, Result, run_filecheck};
use std::borrow::Cow; use std::borrow::Cow;
use utils::pretty_verifier_error; use utils::pretty_error;
struct TestRegalloc; struct TestRegalloc;
@ -45,10 +45,10 @@ impl SubTest for TestRegalloc {
comp_ctx.flowgraph(); comp_ctx.flowgraph();
// TODO: Should we have an option to skip legalization? // TODO: Should we have an option to skip legalization?
comp_ctx.legalize(isa); comp_ctx.legalize(isa)
comp_ctx.regalloc(isa); .map_err(|e| pretty_error(&comp_ctx.func, e))?;
comp_ctx.verify(isa) comp_ctx.regalloc(isa)
.map_err(|e| pretty_verifier_error(&comp_ctx.func, e))?; .map_err(|e| pretty_error(&comp_ctx.func, e))?;
let mut text = String::new(); let mut text = String::new();
write_function(&mut text, &comp_ctx.func, Some(isa)).map_err(|e| e.to_string())?; write_function(&mut text, &comp_ctx.func, Some(isa)).map_err(|e| e.to_string())?;

10
src/utils.rs

@ -2,6 +2,7 @@
use cretonne::ir::entities::AnyEntity; use cretonne::ir::entities::AnyEntity;
use cretonne::{ir, verifier, write_function}; use cretonne::{ir, verifier, write_function};
use cretonne::result::CtonError;
use std::fmt::Write; use std::fmt::Write;
use std::fs::File; use std::fs::File;
use std::io::{Result, Read}; use std::io::{Result, Read};
@ -45,6 +46,15 @@ pub fn pretty_verifier_error(func: &ir::Function, err: verifier::Error) -> Strin
msg msg
} }
/// Pretty-print a Cretonne error.
pub fn pretty_error(func: &ir::Function, err: CtonError) -> String {
if let CtonError::Verifier(e) = err {
pretty_verifier_error(func, e)
} else {
err.to_string()
}
}
#[test] #[test]
fn test_match_directive() { fn test_match_directive() {
assert_eq!(match_directive("; foo: bar ", "foo:"), Some("bar")); assert_eq!(match_directive("; foo: bar ", "foo:"), Some("bar"));

Loading…
Cancel
Save