Skip to content

Commit 3e2ac62

Browse files
River707tensorflower-gardener
authored andcommitted
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
1 parent b991e8b commit 3e2ac62

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ def process_line(line_chunks, variable_namer):
9898
return output_line + '\n'
9999

100100

101+
# Pre-process a line of input to remove any character sequences that will be
102+
# problematic with FileCheck.
103+
def preprocess_line(line):
104+
# Replace any double brackets, '[[' with escaped replacements. '[['
105+
# corresponds to variable names in FileCheck.
106+
output_line = line.replace('[[', '{{\\[\\[}}')
107+
108+
# Replace any single brackets that are followed by an SSA identifier, the
109+
# identifier will be replace by a variable; Creating the same situation as
110+
# above.
111+
output_line = output_line.replace('[%', '{{\\[}}%')
112+
113+
return output_line
114+
115+
101116
def main():
102117
from argparse import RawTextHelpFormatter
103118
parser = argparse.ArgumentParser(
@@ -153,6 +168,10 @@ def main():
153168
if input_line[-1] == '{':
154169
variable_namer.push_name_scope()
155170

171+
# Preprocess the input to remove any sequences that may be problematic with
172+
# FileCheck.
173+
input_line = preprocess_line(input_line)
174+
156175
# Split the line at the each SSA value name.
157176
ssa_split = input_line.split('%')
158177

0 commit comments

Comments
 (0)