[llvm-dev] RFC: FileCheck Enhancements

Chris Lattner via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 12 23:22:14 PDT 2016


On Sep 12, 2016, at 6:04 PM, Vedant Kumar via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> That's a good example. While '{{REGEX}}' usually creates a new matching group,
> we could introduce some new syntax to make it possible to use pattern arguments
> inside of regexes. E.g for an argument named 'x', writing 'x' in a pattern
> definition preserves the current behavior, and writing '#x' concatenates the
> value of 'x' with any surrounding regexes (resulting in just one matching
> group).
> 
> So, to match one or more things you could write:
> 
>  CHECK-DEFINE-PATTERN: one_or_more(x): #x {{+}}
>  CHECK: [[@one_or_more("1")]]
> 
> Without the '#', you'd see a syntax error because '+' isn't a valid regex.
> 
> I like this approach because it doesn't require changing the definitions of
> REGEX or POSIX_REGEX. It'd be interesting to hear what other people think.
> 
> We should be able to hash this out in parallel to the work on D22403, since the
> plan is to defer work on pattern arguments until basic support for pattern
> definitions has landed.
> 
> Revised grammar (** proposal **):
> 
>  ACTION <- CHECK ':' MATCH '\n' ;
>  ACTION <- CHECK-DEFINE-PATTERN ':' IDENT PARAMLIST? ':' PATTERN_ELEMENT* '\n' ;
>  PARAMLIST <- '(' IDENT (',' IDENT)* ')' ;
>  PATTERN_ELEMENT <- '#'? IDENT ;
>  PATTERN_ELEMENT <- REGEX ;
>  MATCH <- (TEXT | REGEX | PATTERN_USE | VAR)* ;
>  REGEX <- '{{' POSIX_REGEX '}}' ;
>  PATTERN_USE <- '[[' '@' IDENT ARGLIST? ']]' ;
>  VAR <- '[[' IDENT ':' POSIX_REGEX ']]' ;
>  VAR <- '[[' IDENT '@' IDENT ARGLIST? ']]' ;
>  ARGLIST <- '(' ARG (',' ARG)* ')' ;
>  ARG <- "([^"]|\\")*” ;

This seems like a really complicated set of extensions to filecheck for marginal gain.  I’m not enthused by the idea that you’d have to actually utter this in every individual test that needs to use the feature, because that would lead to boilerplate.

Instead of doing this, has anyone considered baking “modes” into Filecheck to support the important clients (e.g. LLVM IR, MC, clang, etc)?  This would mean that a test could just add a “--mode=llvmir” flag to filecheck and get a bunch of baked in patterns, potentially with magic syntax.  Something like this would avoid having to redundantly enter "%[0-9]+” a kajillion times all over the place.

-Chris


More information about the llvm-dev mailing list