Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python2 | |
| 2 | |
| 3 # Runs llvm2ice on an input .ll file, and compares the output against | |
| 4 # the input. | |
| 5 # | |
| 6 # Before comparing, the input file is massaged to remove comments, | |
| 7 # blank lines, global variable definitions, external function | |
| 8 # declarations, and possibly other patterns that llvm2ice does not | |
| 9 # handle. | |
| 10 # | |
| 11 # The output file and the massaged input file are compared line by | |
| 12 # line for differences. However, there is a regex defined such that | |
| 13 # if the regex matches a line in the input file, that line and the | |
| 14 # corresponding line in the output file are ignored. This lets us | |
| 15 # ignore minor differences such as inttoptr and ptrtoint, and printing | |
| 16 # of floating-point constants. | |
| 17 # | |
| 18 # On success, no output is produced. On failure, each mismatch is | |
| 19 # printed as two lines, one starting with "SZ" and one starting with | |
| 20 # "LL". | |
|
JF
2014/03/21 02:11:30
I'd expect this to be a triply-quoted string inste
Jim Stichnoth
2014/03/21 21:33:08
Done.
| |
| 21 | |
| 22 import argparse | |
| 23 import subprocess | |
| 24 import re | |
| 25 | |
| 26 if __name__ == '__main__': | |
| 27 argparser = argparse.ArgumentParser() | |
|
JF
2014/03/21 02:11:30
description='...'
Jim Stichnoth
2014/03/21 21:33:08
Done.
| |
| 28 argparser.add_argument('llfile') | |
|
JF
2014/03/21 02:11:30
type=argparse.FileType('r') would allow you to rea
Jim Stichnoth
2014/03/21 21:33:08
Done. (BTW 'type=string' is not valid, and the de
| |
| 29 argparser.add_argument('--llvm2ice') | |
|
JF
2014/03/21 02:11:30
Same as above, but with default='./llvm2ice' and r
Jim Stichnoth
2014/03/21 21:33:08
Done.
| |
| 30 args = argparser.parse_args() | |
| 31 | |
| 32 infile = args.llfile | |
| 33 llvm2ice = args.llvm2ice if args.llvm2ice else './llvm2ice' | |
|
JF
2014/03/21 02:11:30
This can be dropped with the above default=
Jim Stichnoth
2014/03/21 21:33:08
Done.
| |
| 34 command = [llvm2ice, '-verbose', 'inst', '-notranslate', infile] | |
| 35 p = subprocess.Popen(command, stdout=subprocess.PIPE) | |
| 36 sz_out, stderr = p.communicate() | |
| 37 sed_command = ['sed', '-e', 's/;.*//', '-e', 's/ *$//', infile] | |
| 38 grep1_command = ['grep', '-v', '^ *$'] | |
| 39 grep2_command = ['grep', '-v', '^declare'] | |
| 40 grep3_command = ['grep', '-v', '^@'] | |
| 41 sed = subprocess.Popen(sed_command, stdout=subprocess.PIPE) | |
| 42 grep1 = subprocess.Popen(grep1_command, stdin=sed.stdout, | |
| 43 stdout=subprocess.PIPE) | |
| 44 grep2 = subprocess.Popen(grep2_command, stdin=grep1.stdout, | |
| 45 stdout=subprocess.PIPE) | |
| 46 grep3 = subprocess.Popen(grep3_command, stdin=grep2.stdout, | |
| 47 stdout=subprocess.PIPE) | |
|
JF
2014/03/21 02:11:30
You know I sed, but in this case http://docs.pytho
Jim Stichnoth
2014/03/21 21:33:08
OK OK, fixed.
| |
| 48 llc_out = grep3.communicate()[0] | |
| 49 match = re.compile('|'.join([' -[0-9]+', # negative constants | |
| 50 'float [-0-9]', # FP constants | |
| 51 'inttoptr', # inttoptr pointer types | |
| 52 'ptrtoint' # ptrtoint pointer types | |
| 53 ])) | |
| 54 return_code = 0 | |
| 55 for (sz_line, llc_line) in zip(sz_out.splitlines(), llc_out.splitlines()): | |
| 56 if not match.search(llc_line) and sz_line != llc_line: | |
| 57 print 'SZ>' + sz_line | |
| 58 print 'LL>' + llc_line | |
| 59 return_code = 1 | |
| 60 if return_code == 0: print 'Success' | |
| 61 exit(return_code) | |
| OLD | NEW |