Skip to content

Commit 6c9b594

Browse files
authored
[MLIR] Fix generate-test-checks.py to not remove every blank lines (#166493)
The stripping of the notes was done on a line-by-line basis which was fragile and led to remove empty lines everywhere in the file. Instead we can strip it as a single block before splitting the input into multiple lines.
1 parent 5c8bcf7 commit 6c9b594

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,11 @@ def process_line(line_chunks, variable_namer, use_ssa_name=False, strict_name_re
230230

231231

232232
# Process the source file lines. The source file doesn't have to be .mlir.
233-
def process_source_lines(source_lines, note, args):
233+
def process_source_lines(source_lines, args):
234234
source_split_re = re.compile(args.source_delim_regex)
235235

236236
source_segments = [[]]
237237
for line in source_lines:
238-
# Remove previous note.
239-
if line in note:
240-
continue
241238
# Remove previous CHECK lines.
242239
if line.find(args.check_prefix) != -1:
243240
continue
@@ -359,9 +356,10 @@ def main():
359356

360357
source_segments = None
361358
if args.source:
362-
source_segments = process_source_lines(
363-
[l.rstrip() for l in open(args.source, "r")], autogenerated_note, args
364-
)
359+
with open(args.source, "r") as f:
360+
raw_source = f.read().replace(autogenerated_note, "")
361+
raw_source_lines = [l.rstrip() for l in raw_source.splitlines()]
362+
source_segments = process_source_lines(raw_source_lines, args)
365363

366364
if args.inplace:
367365
assert args.output is None

0 commit comments

Comments
 (0)