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
diff --git a/utils/generate-test-checks.py b/utils/generate-test-checks.py
index eb2c1dd..e0115e5 100755
--- a/utils/generate-test-checks.py
+++ b/utils/generate-test-checks.py
@@ -98,6 +98,21 @@
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 @@
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('%')