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