150
|
1 #!/usr/bin/env python
|
|
2
|
252
|
3 # Given a -print-before-all and/or -print-after-all -print-module-scope log from
|
|
4 # an opt invocation, chunk it into a series of individual IR files, one for each
|
|
5 # pass invocation. If the log ends with an obvious stack trace, try to split off
|
|
6 # a separate "crashinfo.txt" file leaving only the valid input IR in the last
|
|
7 # chunk. Files are written to current working directory.
|
173
|
8
|
150
|
9 import sys
|
252
|
10 import re
|
150
|
11
|
|
12 chunk_id = 0
|
|
13
|
252
|
14 # This function gets the pass name from the following line:
|
|
15 # *** IR Dump Before/After PASS_NAME... ***
|
|
16 def get_pass_name(line, prefix):
|
|
17 short_line = line[line.find(prefix) + len(prefix) + 1 :]
|
|
18 return re.split(" |<", short_line)[0]
|
|
19
|
|
20
|
|
21 def print_chunk(lines, prefix, pass_name):
|
150
|
22 global chunk_id
|
252
|
23 fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"
|
150
|
24 chunk_id = chunk_id + 1
|
173
|
25 print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
|
150
|
26 with open(fname, "w") as f:
|
|
27 f.writelines(lines)
|
|
28
|
252
|
29
|
150
|
30 is_dump = False
|
|
31 cur = []
|
|
32 for line in sys.stdin:
|
173
|
33 if line.startswith("*** IR Dump Before "):
|
|
34 if len(cur) != 0:
|
252
|
35 print_chunk(cur, "before", pass_name)
|
173
|
36 cur = []
|
150
|
37 cur.append("; " + line)
|
252
|
38 pass_name = get_pass_name(line, "Before")
|
|
39 elif line.startswith("*** IR Dump After "):
|
|
40 if len(cur) != 0:
|
|
41 print_chunk(cur, "after", pass_name)
|
|
42 cur = []
|
|
43 cur.append("; " + line)
|
|
44 pass_name = get_pass_name(line, "After")
|
150
|
45 elif line.startswith("Stack dump:"):
|
252
|
46 print_chunk(cur, "crash", pass_name)
|
150
|
47 cur = []
|
|
48 cur.append(line)
|
|
49 is_dump = True
|
|
50 else:
|
|
51 cur.append(line)
|
|
52
|
|
53 if is_dump:
|
173
|
54 print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
|
150
|
55 with open("crashinfo.txt", "w") as f:
|
|
56 f.writelines(cur)
|
|
57 else:
|
252
|
58 print_chunk(cur, "last", pass_name)
|