brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 2860dd4 Raw
89 lines · python
1#!/usr/bin/env python32import re, sys3 4 5def fix_string(s):6    TYPE = re.compile(7        '\s*(i[0-9]+|float|double|x86_fp80|fp128|ppc_fp128|\[\[.*?\]\]|\[2 x \[\[[A-Z_0-9]+\]\]\]|<.*?>|{.*?}|\[[0-9]+ x .*?\]|%["a-z:A-Z0-9._]+({{.*?}})?|%{{.*?}}|{{.*?}}|\[\[.*?\]\])(\s*(\*|addrspace\(.*?\)|dereferenceable\(.*?\)|byval\(.*?\)|sret|zeroext|inreg|returned|signext|nocapture|align \d+|swiftself|swifterror|readonly|noalias|inalloca|nocapture))*\s*'8    )9 10    counter = 011    if "i32{{.*}}" in s:12        counter = 113 14    at_pos = s.find("@")15    if at_pos == -1:16        at_pos = 017 18    annoying_pos = s.find("{{[^(]+}}")19    if annoying_pos != -1:20        at_pos = annoying_pos + 921 22    paren_pos = s.find("(", at_pos)23    if paren_pos == -1:24        return s25 26    res = s[: paren_pos + 1]27    s = s[paren_pos + 1 :]28 29    m = TYPE.match(s)30    while m:31        res += m.group()32        s = s[m.end() :]33        if s.startswith(",") or s.startswith(")"):34            res += f" %{counter}"35            counter += 136 37        next_arg = s.find(",")38        if next_arg == -1:39            break40 41        res += s[: next_arg + 1]42        s = s[next_arg + 1 :]43        m = TYPE.match(s)44 45    return res + s46 47 48def process_file(contents):49    PREFIX = re.compile(r"check-prefix(es)?(=|\s+)([a-zA-Z0-9,]+)")50    check_prefixes = ["CHECK"]51    result = ""52    for line in contents.split("\n"):53        if "FileCheck" in line:54            m = PREFIX.search(line)55            if m:56                check_prefixes.extend(m.group(3).split(","))57 58        found_check = False59        for prefix in check_prefixes:60            if prefix in line:61                found_check = True62                break63 64        if not found_check or "define" not in line:65            result += line + "\n"66            continue67 68        # We have a check for a function definition. Number the args.69        line = fix_string(line)70        result += line + "\n"71    return result72 73 74def main():75    print(f"Processing {sys.argv[1]}")76    f = open(sys.argv[1])77    content = f.read()78    f.close()79 80    content = process_file(content)81 82    f = open(sys.argv[1], "w")83    f.write(content)84    f.close()85 86 87if __name__ == "__main__":88    main()89