Skip to content

Commit bf114a4

Browse files
committed
[mlir] Add support for broader range of input files in generate-test-checks.py
1 parent e0c8fc7 commit bf114a4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,23 @@ def process_attribute_references(line, attribute_namer):
227227
components = ATTR_RE.split(line)
228228
for component in components:
229229
m = ATTR_RE.match(component)
230-
if m:
231-
output_line += '#[[' + attribute_namer.get_name(m.group(1)) + ']]'
232-
output_line += component[len(m.group()):]
230+
# Only use attribute alias if one exists.
231+
if m and attribute_namer.get_name(m.group(1)) != "?":
232+
output_line += "#[[" + attribute_namer.get_name(m.group(1)) + "]]"
233+
output_line += component[len(m.group()) :]
233234
else:
234235
output_line += component
235236
return output_line
236237

237238
# Pre-process a line of input to remove any character sequences that will be
238239
# problematic with FileCheck.
239240
def preprocess_line(line):
241+
# If input line has `{{` i.e. in a StrAttr with serialized proto.
242+
output_line = line.replace("{{", "{{\\{\\{}}")
243+
240244
# Replace any double brackets, '[[' with escaped replacements. '[['
241245
# corresponds to variable names in FileCheck.
242-
output_line = line.replace("[[", "{{\\[\\[}}")
246+
output_line = output_line.replace("[[", "{{\\[\\[}}")
243247

244248
# Replace any single brackets that are followed by an SSA identifier, the
245249
# identifier will be replace by a variable; Creating the same situation as
@@ -328,6 +332,11 @@ def main():
328332
if not input_line:
329333
continue
330334

335+
# When using `--starts_from_scope=0` to capture module lines, the file
336+
# split needs to be skipped, otherwise a `CHECK: // -----` is inserted.
337+
if input_line.startswith("// -----"):
338+
continue
339+
331340
# Check if this is an attribute definition and process it
332341
process_attribute_definition(input_line, attribute_namer, output)
333342

0 commit comments

Comments
 (0)