llvm-project

Форк
0
/
chunk-print-before-all.py 
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

9
import sys
10
import re
11

12
chunk_id = 0
13

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):
22
    global chunk_id
23
    fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"
24
    chunk_id = chunk_id + 1
25
    print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
26
    with open(fname, "w") as f:
27
        f.writelines(lines)
28

29

30
is_dump = False
31
cur = []
32
for line in sys.stdin:
33
    if "*** IR Dump Before " in line:
34
        if len(cur) != 0:
35
            print_chunk(cur, "before", pass_name)
36
            cur = []
37
        cur.append("; " + line)
38
        pass_name = get_pass_name(line, "Before")
39
    elif "*** IR Dump After " in line:
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")
45
    elif line.startswith("Stack dump:"):
46
        print_chunk(cur, "crash", pass_name)
47
        cur = []
48
        cur.append(line)
49
        is_dump = True
50
    else:
51
        cur.append(line)
52

53
if is_dump:
54
    print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
55
    with open("crashinfo.txt", "w") as f:
56
        f.writelines(cur)
57
else:
58
    print_chunk(cur, "last", pass_name)
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.