Allow filecheck directives with "test compile".

Things like inserted prologues and epilogues in #201 can be tested this
way.
This commit is contained in:
Jakob Stoklund Olesen
2017-12-04 09:18:30 -08:00
parent 919de82e9c
commit 04f6ccabe5
2 changed files with 19 additions and 3 deletions

View File

@@ -352,3 +352,14 @@ Test the simple GVN pass.
The simple GVN pass is run on each function, and then results are run The simple GVN pass is run on each function, and then results are run
through filecheck. through filecheck.
`test compile`
--------------
Test the whole code generation pipeline.
Each function is passed through the full ``Context::compile()`` function
which is normally used to compile code. This type of test often depends
on assertions or verifier errors, but it is also possible to use
filecheck directives which will be matched against the final form of the
Cretonne IL right before binary machine code emission.

View File

@@ -6,8 +6,9 @@ use cretonne::binemit;
use cretonne::ir; use cretonne::ir;
use cretonne; use cretonne;
use cton_reader::TestCommand; use cton_reader::TestCommand;
use filetest::subtest::{SubTest, Context, Result}; use filetest::subtest::{SubTest, Context, Result, run_filecheck};
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::Write;
use utils::pretty_error; use utils::pretty_error;
struct TestCompile; struct TestCompile;
@@ -51,7 +52,7 @@ impl SubTest for TestCompile {
comp_ctx.func.display(isa) comp_ctx.func.display(isa)
); );
// Finally verify that the returned code size matches the emitted bytes. // Verify that the returned code size matches the emitted bytes.
let mut sink = SizeSink { offset: 0 }; let mut sink = SizeSink { offset: 0 };
binemit::emit_function( binemit::emit_function(
&comp_ctx.func, &comp_ctx.func,
@@ -67,7 +68,11 @@ impl SubTest for TestCompile {
)); ));
} }
Ok(()) // Run final code through filecheck.
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa)))
.map_err(|e| e.to_string())?;
run_filecheck(&text, context)
} }
} }