TestFile preamble comments apply to all functions.
Include the test file preamble comments when building a filecheck instance for every function in the file. This makes it possible to define common regex variables in the preamble and use these definitions for all the functions.
This commit is contained in:
@@ -150,6 +150,10 @@ use filecheck will extract comments associated with each function (or its
|
|||||||
entities) and scan them for filecheck directives. The test output for each
|
entities) and scan them for filecheck directives. The test output for each
|
||||||
function is then matched against the filecheck directives for that function.
|
function is then matched against the filecheck directives for that function.
|
||||||
|
|
||||||
|
Comments appearing before the first function in a file apply to every function.
|
||||||
|
This is useful for defining common regular expression variables with the
|
||||||
|
``regex:`` directive, for example.
|
||||||
|
|
||||||
Note that LLVM's file tests don't separate filecheck directives by their
|
Note that LLVM's file tests don't separate filecheck directives by their
|
||||||
associated function. It verifies the concatenated output against all filecheck
|
associated function. It verifies the concatenated output against all filecheck
|
||||||
directives in the test file. LLVM's :command:`FileCheck` command has a
|
directives in the test file. LLVM's :command:`FileCheck` command has a
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
test legalizer
|
test legalizer
|
||||||
isa riscv supports_m=1
|
isa riscv supports_m=1
|
||||||
|
|
||||||
|
; regex: V=v\d+
|
||||||
|
; regex: VX=vx\d+
|
||||||
|
|
||||||
function bitwise_and(i64, i64) -> i64 {
|
function bitwise_and(i64, i64) -> i64 {
|
||||||
ebb0(v1: i64, v2: i64):
|
ebb0(v1: i64, v2: i64):
|
||||||
v3 = band v1, v2
|
v3 = band v1, v2
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; regex: V=v\d+
|
|
||||||
; regex: VX=vx\d+
|
|
||||||
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
||||||
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
||||||
; check: [R#ec
|
; check: [R#ec
|
||||||
@@ -22,8 +23,6 @@ ebb0(v1: i64, v2: i64):
|
|||||||
v3 = bor v1, v2
|
v3 = bor v1, v2
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; regex: V=v\d+
|
|
||||||
; regex: VX=vx\d+
|
|
||||||
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
||||||
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
||||||
; check: [R#cc
|
; check: [R#cc
|
||||||
@@ -37,8 +36,6 @@ ebb0(v1: i64, v2: i64):
|
|||||||
v3 = bxor v1, v2
|
v3 = bxor v1, v2
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; regex: V=v\d+
|
|
||||||
; regex: VX=vx\d+
|
|
||||||
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
|
||||||
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
|
||||||
; check: [R#8c
|
; check: [R#8c
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ pub fn run(path: &Path) -> TestResult {
|
|||||||
|
|
||||||
for (func, details) in testfile.functions {
|
for (func, details) in testfile.functions {
|
||||||
let mut context = Context {
|
let mut context = Context {
|
||||||
|
preamble_comments: &testfile.preamble_comments,
|
||||||
details: details,
|
details: details,
|
||||||
verified: false,
|
verified: false,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
|||||||
@@ -5,13 +5,16 @@ use std::borrow::Cow;
|
|||||||
use cretonne::ir::Function;
|
use cretonne::ir::Function;
|
||||||
use cretonne::isa::TargetIsa;
|
use cretonne::isa::TargetIsa;
|
||||||
use cretonne::settings::Flags;
|
use cretonne::settings::Flags;
|
||||||
use cton_reader::Details;
|
use cton_reader::{Details, Comment};
|
||||||
use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
|
use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, String>;
|
pub type Result<T> = result::Result<T, String>;
|
||||||
|
|
||||||
/// Context for running a a test on a single function.
|
/// Context for running a a test on a single function.
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
|
/// Comments from the preamble f the test file. These apply to all functions.
|
||||||
|
pub preamble_comments: &'a [Comment<'a>],
|
||||||
|
|
||||||
/// Additional details about the function from the parser.
|
/// Additional details about the function from the parser.
|
||||||
pub details: Details<'a>,
|
pub details: Details<'a>,
|
||||||
|
|
||||||
@@ -69,7 +72,7 @@ impl<'a> filecheck::VariableMap for Context<'a> {
|
|||||||
|
|
||||||
/// Run filecheck on `text`, using directives extracted from `context`.
|
/// Run filecheck on `text`, using directives extracted from `context`.
|
||||||
pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
|
pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
|
||||||
let checker = try!(build_filechecker(&context.details));
|
let checker = try!(build_filechecker(context));
|
||||||
if try!(checker.check(&text, context).map_err(|e| format!("filecheck: {}", e))) {
|
if try!(checker.check(&text, context).map_err(|e| format!("filecheck: {}", e))) {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@@ -80,10 +83,14 @@ pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a filechecker using the directives in the function's comments.
|
/// Build a filechecker using the directives in the file preamble and the function's comments.
|
||||||
pub fn build_filechecker(details: &Details) -> Result<Checker> {
|
pub fn build_filechecker(context: &Context) -> Result<Checker> {
|
||||||
let mut builder = CheckerBuilder::new();
|
let mut builder = CheckerBuilder::new();
|
||||||
for comment in &details.comments {
|
// Preamble comments apply to all functions.
|
||||||
|
for comment in context.preamble_comments {
|
||||||
|
try!(builder.directive(comment.text).map_err(|e| format!("filecheck: {}", e)));
|
||||||
|
}
|
||||||
|
for comment in &context.details.comments {
|
||||||
try!(builder.directive(comment.text).map_err(|e| format!("filecheck: {}", e)));
|
try!(builder.directive(comment.text).map_err(|e| format!("filecheck: {}", e)));
|
||||||
}
|
}
|
||||||
let checker = builder.finish();
|
let checker = builder.finish();
|
||||||
|
|||||||
Reference in New Issue
Block a user