OLD | NEW |
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 | 2 |
3 import argparse | 3 import argparse |
4 import itertools | 4 import itertools |
5 import re | 5 import re |
6 | 6 |
7 if __name__ == '__main__': | 7 if __name__ == '__main__': |
8 """Compares a LLVM file with a subzero file for differences. | 8 """Compares a LLVM file with a subzero file for differences. |
9 | 9 |
10 Before comparing, the LLVM file is massaged to remove comments, | 10 Before comparing, the LLVM file is massaged to remove comments, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 prev_line = line | 65 prev_line = line |
66 continue | 66 continue |
67 llc_out.append(line) | 67 llc_out.append(line) |
68 | 68 |
69 # Compare sz_out and llc_out line by line, but ignore pairs of | 69 # Compare sz_out and llc_out line by line, but ignore pairs of |
70 # lines where the llc line matches a certain pattern. | 70 # lines where the llc line matches a certain pattern. |
71 return_code = 0 | 71 return_code = 0 |
72 lines_total = 0 | 72 lines_total = 0 |
73 lines_diff = 0 | 73 lines_diff = 0 |
74 ignore_pattern = re.compile( | 74 ignore_pattern = re.compile( |
75 '|'.join([' -[0-9]', # negative constants | 75 '|'.join(['[ (](float|double) [-0-9]', # FP constants |
76 ' (float|double) [-0-9]', # FP constants | 76 '[ (](float|double) %\w+, [-0-9]', |
77 ' (float|double) %\w+, [-0-9]', | |
78 ' @llvm\..*i\d+\*', # intrinsic calls w/ pointer args | 77 ' @llvm\..*i\d+\*', # intrinsic calls w/ pointer args |
79 ' i\d+\* @llvm\.', # intrinsic calls w/ pointer ret | 78 ' i\d+\* @llvm\.', # intrinsic calls w/ pointer ret |
80 ' inttoptr ', # inttoptr pointer types | 79 ' inttoptr ', # inttoptr pointer types |
81 ' ptrtoint ', # ptrtoint pointer types | 80 ' ptrtoint ', # ptrtoint pointer types |
82 ' bitcast .*\* .* to .*\*' # bitcast pointer types | 81 ' bitcast .*\* .* to .*\*' # bitcast pointer types |
83 ])) | 82 ])) |
84 for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out): | 83 for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out): |
85 lines_total += 1 | 84 lines_total += 1 |
86 if sz_line == llc_line: | 85 if sz_line == llc_line: |
87 continue | 86 continue |
88 if llc_line and ignore_pattern.search(llc_line): | 87 if llc_line and ignore_pattern.search(llc_line): |
89 lines_diff += 1 | 88 lines_diff += 1 |
90 continue | 89 continue |
91 if sz_line: print 'SZ (%d)> %s' % (lines_total, sz_line) | 90 if sz_line: print 'SZ (%d)> %s' % (lines_total, sz_line) |
92 if llc_line: print 'LL (%d)> %s' % (lines_total, llc_line) | 91 if llc_line: print 'LL (%d)> %s' % (lines_total, llc_line) |
93 return_code = 1 | 92 return_code = 1 |
94 | 93 |
95 if return_code == 0: | 94 if return_code == 0: |
96 message = 'Success (ignored %d diffs out of %d lines)' | 95 message = 'Success (ignored %d diffs out of %d lines)' |
97 print message % (lines_diff, lines_total) | 96 print message % (lines_diff, lines_total) |
98 exit(return_code) | 97 exit(return_code) |
OLD | NEW |