brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 855bc50 Raw
80 lines · python
1import re2from . import common3import sys4 5if sys.version_info[0] > 2:6 7    class string:8        expandtabs = str.expandtabs9 10else:11    import string12 13# Support of isel debug checks14# RegEx: this is where the magic happens.15 16##### iSel parser17 18# TODO: add function prefix19ISEL_FUNCTION_DEFAULT_RE = re.compile(20    r"Selected[\s]*selection[\s]*DAG:[\s]*%bb.0[\s]*\'(?P<func>.*?):[^\']*\'*\n"21    r"(?P<body>.*?)\n"22    r"Total[\s]*amount[\s]*of[\s]*phi[\s]*nodes[\s]*to[\s]*update:[\s]*[0-9]+",23    flags=(re.M | re.S),24)25 26 27def scrub_isel_default(isel, args):28    # Scrub runs of whitespace out of the iSel debug output, but leave the leading29    # whitespace in place.30    isel = common.SCRUB_WHITESPACE_RE.sub(r" ", isel)31    # Expand the tabs used for indentation.32    isel = string.expandtabs(isel, 2)33    # Strip trailing whitespace.34    isel = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", isel)35    return isel36 37 38def get_run_handler(triple):39    target_handlers = {}40    handler = None41    best_prefix = ""42    for prefix, s in target_handlers.items():43        if triple.startswith(prefix) and len(prefix) > len(best_prefix):44            handler = s45            best_prefix = prefix46 47    if handler is None:48        common.debug("Using default handler.")49        handler = (scrub_isel_default, ISEL_FUNCTION_DEFAULT_RE)50 51    return handler52 53 54##### Generator of iSel CHECK lines55 56 57def add_checks(58    output_lines,59    comment_marker,60    prefix_list,61    func_dict,62    func_name,63    ginfo: common.GeneralizerInfo,64    global_vars_seen_dict,65    is_filtered,66):67    # Label format is based on iSel string.68    check_label_format = "{} %s-LABEL: %s%s%s%s".format(comment_marker)69    return common.add_checks(70        output_lines,71        comment_marker,72        prefix_list,73        func_dict,74        func_name,75        check_label_format,76        ginfo,77        global_vars_seen_dict,78        is_filtered=is_filtered,79    )80