[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / utils / chunk-print-before-all.py
blobce17c68c742a2555449633f9ac62a3787c519583
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.
8 import sys
10 basename = "chunk-"
11 chunk_id = 0
13 def print_chunk(lines):
14 global chunk_id
15 global basename
16 fname = basename + str(chunk_id) + ".ll"
17 chunk_id = chunk_id + 1
18 print "writing chunk " + fname + " (" + str(len(lines)) + " lines)"
19 with open(fname, "w") as f:
20 f.writelines(lines)
22 is_dump = False
23 cur = []
24 for line in sys.stdin:
25 if line.startswith("*** IR Dump Before ") and len(cur) != 0:
26 print_chunk(cur);
27 cur = []
28 cur.append("; " + line)
29 elif line.startswith("Stack dump:"):
30 print_chunk(cur);
31 cur = []
32 cur.append(line)
33 is_dump = True
34 else:
35 cur.append(line)
37 if is_dump:
38 print "writing crashinfo.txt (" + str(len(cur)) + " lines)"
39 with open("crashinfo.txt", "w") as f:
40 f.writelines(cur)
41 else:
42 print_chunk(cur);