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
This commit is contained in:
River Riddle 2019-09-17 13:59:12 -07:00 committed by A. Unique TensorFlower
parent b991e8b1e4
commit 3e2ac62b7d

View File

@ -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('%')