diff --git a/filetests/parser/rewrite.cton b/filetests/parser/rewrite.cton index 969572bdbf..48ad84869c 100644 --- a/filetests/parser/rewrite.cton +++ b/filetests/parser/rewrite.cton @@ -16,9 +16,9 @@ ebb100(v20: i32): trap } ; sameln: function defs() { -; nextln: ebb0(vx0: i32): -; nextln: v0 = iconst.i32x8 5 -; nextln: v1 = f64const 0x1.0000000000000p2 +; nextln: $ebb100($v20: i32): +; nextln: $v1000 = iconst.i32x8 5 +; nextln: $vx200 = f64const 0x1.0000000000000p2 ; nextln: trap ; nextln: } diff --git a/src/tools/filetest/subtest.rs b/src/tools/filetest/subtest.rs index f87eda9b98..89a8b830e1 100644 --- a/src/tools/filetest/subtest.rs +++ b/src/tools/filetest/subtest.rs @@ -4,7 +4,7 @@ use std::result; use std::borrow::Cow; use cretonne::ir::Function; use cton_reader::{TestCommand, Details}; -use filecheck::{CheckerBuilder, Checker, NO_VARIABLES}; +use filecheck::{self, CheckerBuilder, Checker, Value as FCValue}; pub type Result = result::Result; @@ -51,14 +51,27 @@ pub trait SubTest { fn run(&self, func: Cow, context: &Context) -> Result<()>; } +/// Make the parser's source map available as filecheck variables. +/// +/// This means that the filecheck directives can refer to entities like `jump $ebb3`, where `$ebb3` +/// will expand to the EBB number that was assigned to `ebb3` in the input source. +/// +/// The expanded entity names are wrapped in word boundary regex guards so that 'inst1' doesn't +/// match 'inst10'. +impl<'a> filecheck::VariableMap for Context<'a> { + fn lookup(&self, varname: &str) -> Option { + self.details.map.lookup_str(varname).map(|e| FCValue::Regex(format!(r"\b{}\b", e).into())) + } +} + /// Run filecheck on `text`, using directives extracted from `context`. pub fn run_filecheck(text: &str, context: &Context) -> Result<()> { let checker = try!(build_filechecker(&context.details)); - if try!(checker.check(&text, NO_VARIABLES).map_err(|e| format!("filecheck: {}", e))) { + if try!(checker.check(&text, context).map_err(|e| format!("filecheck: {}", e))) { Ok(()) } else { // Filecheck mismatch. Emit an explanation as output. - let (_, explain) = try!(checker.explain(&text, NO_VARIABLES) + let (_, explain) = try!(checker.explain(&text, context) .map_err(|e| format!("explain: {}", e))); Err(format!("filecheck failed:\n{}{}", checker, explain)) }