Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: szdiff.py

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Use non-anonymous structs so that array_lengthof works Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/llvm2ice.cpp ('k') | tests_lit/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python2
2
3 import argparse
4 import itertools
5 import subprocess
6 import re
7
8 if __name__ == '__main__':
9 """Runs llvm2ice on an input .ll file, and compares the output
10 against the input.
11
12 Before comparing, the input file is massaged to remove comments,
13 blank lines, global variable definitions, external function
14 declarations, and possibly other patterns that llvm2ice does not
15 handle.
16
17 The output file and the massaged input file are compared line by
18 line for differences. However, there is a regex defined such that
19 if the regex matches a line in the input file, that line and the
20 corresponding line in the output file are ignored. This lets us
21 ignore minor differences such as inttoptr and ptrtoint, and
22 printing of floating-point constants.
23
24 On success, no output is produced. On failure, each mismatch is
25 printed as two lines, one starting with 'SZ' and one starting with
26 'LL'.
27 """
28 desc = 'Compare llvm2ice output against bitcode input.'
29 argparser = argparse.ArgumentParser(description=desc)
30 argparser.add_argument(
31 'llfile', nargs='?', default='-',
32 type=argparse.FileType('r'), metavar='FILE',
33 help='Textual bitcode file [default stdin]')
34 argparser.add_argument(
35 '--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE',
36 help='Path to llvm2ice driver program [default ./llvm2ice]')
37 args = argparser.parse_args()
38 bitcode = args.llfile.readlines()
39
40 # Run llvm2ice and collect its output lines into sz_out.
41 command = [args.llvm2ice, '-verbose', 'inst', '-notranslate', '-']
42 p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
43 sz_out = p.communicate(input=''.join(bitcode))[0].splitlines()
44
45 # Filter certain lines and patterns from the input, and collect
46 # the remainder into llc_out.
47 llc_out = []
48 tail_call = re.compile(' tail call ');
49 trailing_comment = re.compile(';.*')
50 ignore_pattern = re.compile('^ *$|^declare|^@')
51 for line in bitcode:
52 # Convert tail call into regular (non-tail) call.
53 line = tail_call.sub(' call ', line)
54 # Remove trailing comments and spaces.
55 line = trailing_comment.sub('', line).rstrip()
56 # Ignore blanks lines, forward declarations, and variable definitions.
57 if not ignore_pattern.search(line):
58 llc_out.append(line)
59
60 # Compare sz_out and llc_out line by line, but ignore pairs of
61 # lines where the llc line matches a certain pattern.
62 return_code = 0
63 lines_total = 0
64 lines_diff = 0
65 ignore_pattern = re.compile(
66 '|'.join([' -[0-9]', # negative constants
67 ' (float|double) [-0-9]', # FP constants
68 ' (float|double) %\w+, [-0-9]',
69 ' inttoptr ', # inttoptr pointer types
70 ' ptrtoint ' # ptrtoint pointer types
71 ]))
72 for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out):
73 lines_total += 1
74 if sz_line == llc_line:
75 continue
76 if llc_line and ignore_pattern.search(llc_line):
77 lines_diff += 1
78 continue
79 if sz_line: print 'SZ>' + sz_line
80 if llc_line: print 'LL>' + llc_line
81 return_code = 1
82
83 if return_code == 0:
84 message = 'Success (ignored %d diffs out of %d lines)'
85 print message % (lines_diff, lines_total)
86 exit(return_code)
OLDNEW
« no previous file with comments | « src/llvm2ice.cpp ('k') | tests_lit/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698