| 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 24 matching lines...) Expand all Loading... |
| 35 help='Subzero bitcode file [default stdin]') | 35 help='Subzero bitcode file [default stdin]') |
| 36 args = argparser.parse_args() | 36 args = argparser.parse_args() |
| 37 bitcode = args.llfile[0].readlines() | 37 bitcode = args.llfile[0].readlines() |
| 38 sz_out = [ line.rstrip() for line in args.szfile.readlines()] | 38 sz_out = [ line.rstrip() for line in args.szfile.readlines()] |
| 39 | 39 |
| 40 # Filter certain lines and patterns from the input, and collect | 40 # Filter certain lines and patterns from the input, and collect |
| 41 # the remainder into llc_out. | 41 # the remainder into llc_out. |
| 42 llc_out = [] | 42 llc_out = [] |
| 43 tail_call = re.compile(' tail call '); | 43 tail_call = re.compile(' tail call '); |
| 44 trailing_comment = re.compile(';.*') | 44 trailing_comment = re.compile(';.*') |
| 45 ignore_pattern = re.compile('^ *$|^declare|^@') | 45 ignore_pattern = re.compile('|'.join([ |
| 46 '^ *$', # all-whitespace lines |
| 47 '^declare', # declarations without definitions |
| 48 '^@.*\]$' # PNaCl global declarations like: |
| 49 # @v = external global [4 x i8] |
| 50 ])) |
| 46 prev_line = None | 51 prev_line = None |
| 47 for line in bitcode: | 52 for line in bitcode: |
| 48 if prev_line: | 53 if prev_line: |
| 49 line = prev_line + line | 54 line = prev_line + line |
| 50 prev_line = None | 55 prev_line = None |
| 51 # Convert tail call into regular (non-tail) call. | 56 # Convert tail call into regular (non-tail) call. |
| 52 line = tail_call.sub(' call ', line) | 57 line = tail_call.sub(' call ', line) |
| 53 # Remove trailing comments and spaces. | 58 # Remove trailing comments and spaces. |
| 54 line = trailing_comment.sub('', line).rstrip() | 59 line = trailing_comment.sub('', line).rstrip() |
| 55 # Ignore blanks lines, forward declarations, and variable definitions. | 60 # Ignore blanks lines, forward declarations, and variable definitions. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 84 lines_diff += 1 | 89 lines_diff += 1 |
| 85 continue | 90 continue |
| 86 if sz_line: print 'SZ (%d)> %s' % (lines_total, sz_line) | 91 if sz_line: print 'SZ (%d)> %s' % (lines_total, sz_line) |
| 87 if llc_line: print 'LL (%d)> %s' % (lines_total, llc_line) | 92 if llc_line: print 'LL (%d)> %s' % (lines_total, llc_line) |
| 88 return_code = 1 | 93 return_code = 1 |
| 89 | 94 |
| 90 if return_code == 0: | 95 if return_code == 0: |
| 91 message = 'Success (ignored %d diffs out of %d lines)' | 96 message = 'Success (ignored %d diffs out of %d lines)' |
| 92 print message % (lines_diff, lines_total) | 97 print message % (lines_diff, lines_total) |
| 93 exit(return_code) | 98 exit(return_code) |
| OLD | NEW |