1import re 2from . import common 3import sys 4 5if sys.version_info[0] > 2: 6 class string: 7 expandtabs = str.expandtabs 8else: 9 import string 10 11# Support of isel debug checks 12# RegEx: this is where the magic happens. 13 14##### iSel parser 15 16# TODO: add function prefix 17ISEL_FUNCTION_DEFAULT_RE = re.compile( 18 r'Selected[\s]*selection[\s]*DAG:[\s]*%bb.0[\s]*\'(?P<func>.*?):[^\']*\'*\n' 19 r'(?P<body>.*?)\n' 20 r'Total[\s]*amount[\s]*of[\s]*phi[\s]*nodes[\s]*to[\s]*update:[\s]*[0-9]+', 21 flags=(re.M | re.S)) 22 23def scrub_isel_default(isel, args): 24 # Scrub runs of whitespace out of the iSel debug output, but leave the leading 25 # whitespace in place. 26 isel = common.SCRUB_WHITESPACE_RE.sub(r' ', isel) 27 # Expand the tabs used for indentation. 28 isel = string.expandtabs(isel, 2) 29 # Strip trailing whitespace. 30 isel = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', isel) 31 return isel 32 33def get_run_handler(triple): 34 target_handlers = { 35 } 36 handler = None 37 best_prefix = '' 38 for prefix, s in target_handlers.items(): 39 if triple.startswith(prefix) and len(prefix) > len(best_prefix): 40 handler = s 41 best_prefix = prefix 42 43 if handler is None: 44 common.debug('Using default handler.') 45 handler = (scrub_isel_default, ISEL_FUNCTION_DEFAULT_RE) 46 47 return handler 48 49##### Generator of iSel CHECK lines 50 51def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, is_filtered): 52 # Label format is based on iSel string. 53 check_label_format = '{} %s-LABEL: %s%s%s'.format(comment_marker) 54 global_vars_seen_dict = {} 55 common.add_checks(output_lines, comment_marker, prefix_list, func_dict, 56 func_name, check_label_format, True, False, 57 global_vars_seen_dict, is_filtered = is_filtered) 58