|
9 | 9 | Example usage: |
10 | 10 | $ generate-test-checks.py foo.mlir |
11 | 11 | $ mlir-opt foo.mlir -transformation | generate-test-checks.py |
| 12 | +$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir |
| 13 | +$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i |
| 14 | +$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i --source_delim_regex='gpu.func @' |
12 | 15 |
|
13 | | -The script will heuristically insert CHECK/CHECK-LABEL commands for each line |
| 16 | +The script will heuristically generate CHECK/CHECK-LABEL commands for each line |
14 | 17 | within the file. By default this script will also try to insert string |
15 | | -substitution blocks for all SSA value names. The script is designed to make |
16 | | -adding checks to a test case fast, it is *not* designed to be authoritative |
17 | | -about what constitutes a good test! |
| 18 | +substitution blocks for all SSA value names. If --source file is specified, the |
| 19 | +script will attempt to insert the generated CHECKs to the source file by looking |
| 20 | +for line positions matched by --source_delim_regex. |
| 21 | +
|
| 22 | +The script is designed to make adding checks to a test case fast, it is *not* |
| 23 | +designed to be authoritative about what constitutes a good test! |
18 | 24 | """ |
19 | 25 |
|
20 | 26 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
@@ -56,9 +62,11 @@ def push_name_scope(self): |
56 | 62 | def pop_name_scope(self): |
57 | 63 | self.scopes.pop() |
58 | 64 |
|
| 65 | + # Return the level of nesting (number of pushed scopes). |
59 | 66 | def num_scopes(self): |
60 | 67 | return len(self.scopes) |
61 | 68 |
|
| 69 | + # Reset the counter. |
62 | 70 | def clear_counter(self): |
63 | 71 | self.name_counter = 0 |
64 | 72 |
|
@@ -93,15 +101,19 @@ def process_line(line_chunks, variable_namer): |
93 | 101 | return output_line.rstrip() + '\n' |
94 | 102 |
|
95 | 103 |
|
| 104 | +# Process the source file lines. The source file doesn't have to be .mlir. |
96 | 105 | def process_source_lines(source_lines, note, args): |
97 | 106 | source_split_re = re.compile(args.source_delim_regex) |
98 | 107 |
|
99 | 108 | source_segments = [[]] |
100 | 109 | for line in source_lines: |
| 110 | + # Remove previous note. |
101 | 111 | if line == note: |
102 | 112 | continue |
| 113 | + # Remove previous CHECK lines. |
103 | 114 | if line.find(args.check_prefix) != -1: |
104 | 115 | continue |
| 116 | + # Segment the file based on --source_delim_regex. |
105 | 117 | if source_split_re.search(line): |
106 | 118 | source_segments.append([]) |
107 | 119 |
|
|
0 commit comments