[llvm-dev] RFC: FileCheck Enhancements
Vedant Kumar via llvm-dev
llvm-dev at lists.llvm.org
Tue Sep 13 11:16:03 PDT 2016
> On Sep 12, 2016, at 11:22 PM, Chris Lattner <clattner at apple.com> wrote:
>
> 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.
I hadn't considered adding modes to FileCheck. That seems like it could work
pretty well.
Even if that's the route we're going to take, I'd prefer that the FileCheck
modes simply expose pre-defined patterns instead of introducing magic syntax.
It would be a shame to have to hack FileCheck to use check patterns for clients
that aren't LLVM IR, clang, etc.
Having check patterns available would let me simplify some of my tests, making
them easier to update. I hope that we can find a minimal/unintrusive way of
adding at least a basic version of this feature. But, you're right that we
shouldn't do it unless it's generally useful.
vedant
> -Chris
More information about the llvm-dev
mailing list