From 3e2ac62b7d54e37a8b55dfc2e9654a0eef2c6fd6 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Tue, 17 Sep 2019 13:59:12 -0700 Subject: [PATCH] Add a preprocess pass to remove sequences that are problematic with FileCheck Add a preprocess phase to rewrite parts of the input line that may be problematic with filecheck. This change adds preprocessing to escape '[[' bracket sequences, as these are used by FileCheck for variables. PiperOrigin-RevId: 269648490 --- mlir/utils/generate-test-checks.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py index eb2c1dd..e0115e5 100755 --- a/mlir/utils/generate-test-checks.py +++ b/mlir/utils/generate-test-checks.py @@ -98,6 +98,21 @@ def process_line(line_chunks, variable_namer): return output_line + '\n' +# Pre-process a line of input to remove any character sequences that will be +# problematic with FileCheck. +def preprocess_line(line): + # Replace any double brackets, '[[' with escaped replacements. '[[' + # corresponds to variable names in FileCheck. + output_line = line.replace('[[', '{{\\[\\[}}') + + # Replace any single brackets that are followed by an SSA identifier, the + # identifier will be replace by a variable; Creating the same situation as + # above. + output_line = output_line.replace('[%', '{{\\[}}%') + + return output_line + + def main(): from argparse import RawTextHelpFormatter parser = argparse.ArgumentParser( @@ -153,6 +168,10 @@ def main(): if input_line[-1] == '{': variable_namer.push_name_scope() + # Preprocess the input to remove any sequences that may be problematic with + # FileCheck. + input_line = preprocess_line(input_line) + # Split the line at the each SSA value name. ssa_split = input_line.split('%') -- 2.7.4