llvm-project
58 строк · 1.8 Кб
1#!/usr/bin/env python
2
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.
8
9import sys10import re11
12chunk_id = 013
14# This function gets the pass name from the following line:
15# *** IR Dump Before/After PASS_NAME... ***
16def get_pass_name(line, prefix):17short_line = line[line.find(prefix) + len(prefix) + 1 :]18return re.split(" |<", short_line)[0]19
20
21def print_chunk(lines, prefix, pass_name):22global chunk_id23fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"24chunk_id = chunk_id + 125print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")26with open(fname, "w") as f:27f.writelines(lines)28
29
30is_dump = False31cur = []32for line in sys.stdin:33if "*** IR Dump Before " in line:34if len(cur) != 0:35print_chunk(cur, "before", pass_name)36cur = []37cur.append("; " + line)38pass_name = get_pass_name(line, "Before")39elif "*** IR Dump After " in line:40if len(cur) != 0:41print_chunk(cur, "after", pass_name)42cur = []43cur.append("; " + line)44pass_name = get_pass_name(line, "After")45elif line.startswith("Stack dump:"):46print_chunk(cur, "crash", pass_name)47cur = []48cur.append(line)49is_dump = True50else:51cur.append(line)52
53if is_dump:54print("writing crashinfo.txt (" + str(len(cur)) + " lines)")55with open("crashinfo.txt", "w") as f:56f.writelines(cur)57else:58print_chunk(cur, "last", pass_name)59