diff options
Diffstat (limited to 'utils/update_mir_test_checks.py')
-rwxr-xr-x | utils/update_mir_test_checks.py | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/utils/update_mir_test_checks.py b/utils/update_mir_test_checks.py index 2934f09f6b37..3756af1b517d 100755 --- a/utils/update_mir_test_checks.py +++ b/utils/update_mir_test_checks.py @@ -33,16 +33,20 @@ TRIPLE_IR_RE = re.compile(r'^\s*target\s+triple\s*=\s*"([^"]+)"$') CHECK_PREFIX_RE = re.compile('--?check-prefix(?:es)?[= ](\S+)') CHECK_RE = re.compile(r'^\s*[;#]\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:') -FUNC_NAME_RE = re.compile(r' *name: *(?P<func>[A-Za-z0-9_.-]+)') -BODY_BEGIN_RE = re.compile(r' *body: *\|') -BASIC_BLOCK_RE = re.compile(r' *bb\.[0-9]+.*:$') +MIR_FUNC_NAME_RE = re.compile(r' *name: *(?P<func>[A-Za-z0-9_.-]+)') +MIR_BODY_BEGIN_RE = re.compile(r' *body: *\|') +MIR_BASIC_BLOCK_RE = re.compile(r' *bb\.[0-9]+.*:$') VREG_RE = re.compile(r'(%[0-9]+)(?::[a-z0-9_]+)?(?:\([<>a-z0-9 ]+\))?') VREG_DEF_RE = re.compile( r'^ *(?P<vregs>{0}(?:, {0})*) ' r'= (?P<opcode>[A-Zt][A-Za-z0-9_]+)'.format(VREG_RE.pattern)) -PREFIX_DATA_RE = re.compile(r'^ *(;|bb.[0-9].*: *$|[a-z]+:( |$)|$)') +MIR_PREFIX_DATA_RE = re.compile(r'^ *(;|bb.[0-9].*: *$|[a-z]+:( |$)|$)') VREG_CLASS_RE = re.compile(r'^ *- *{ id: ([0-9]+), class: ([a-z0-9_]+)', re.M) +IR_FUNC_NAME_RE = re.compile( + r'^\s*define\s+(?:internal\s+)?[^@]*@(?P<func>\w+)\s*\(') +IR_PREFIX_DATA_RE = re.compile(r'^ *(;|$)') + MIR_FUNC_RE = re.compile( r'^---$' r'\n' @@ -164,13 +168,13 @@ def find_functions_with_one_bb(lines, verbose=False): cur_func = None bbs = 0 for line in lines: - m = FUNC_NAME_RE.match(line) + m = MIR_FUNC_NAME_RE.match(line) if m: if bbs == 1: result.append(cur_func) cur_func = m.group('func') bbs = 0 - m = BASIC_BLOCK_RE.match(line) + m = MIR_BASIC_BLOCK_RE.match(line) if m: bbs += 1 if bbs == 1: @@ -340,8 +344,10 @@ def update_test_file(llc, test, remove_common_prefixes=False, warn('Ignoring common prefixes: {}'.format(common_prefixes), test_file=test) - autogenerated_note = ('# NOTE: Assertions have been autogenerated by ' - 'utils/{}'.format(os.path.basename(__file__))) + comment_char = '#' if test.endswith('.mir') else ';' + autogenerated_note = ('{} NOTE: Assertions have been autogenerated by ' + 'utils/{}'.format(comment_char, + os.path.basename(__file__))) output_lines = [] output_lines.append(autogenerated_note) @@ -350,48 +356,69 @@ def update_test_file(llc, test, remove_common_prefixes=False, continue if state == 'toplevel': + m = IR_FUNC_NAME_RE.match(input_line) + if m: + state = 'ir function prefix' + func_name = m.group('func') if input_line.strip() == '---': state = 'document' output_lines.append(input_line) elif state == 'document': - m = FUNC_NAME_RE.match(input_line) + m = MIR_FUNC_NAME_RE.match(input_line) if m: - state = 'function metadata' + state = 'mir function metadata' func_name = m.group('func') if input_line.strip() == '...': state = 'toplevel' func_name = None if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) - elif state == 'function metadata': + elif state == 'mir function metadata': if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) - m = BODY_BEGIN_RE.match(input_line) + m = MIR_BODY_BEGIN_RE.match(input_line) if m: if func_name in simple_functions: # If there's only one block, put the checks inside it - state = 'function prefix' + state = 'mir function prefix' continue - state = 'function body' + state = 'mir function body' add_checks_for_function(test, output_lines, run_list, func_dict, func_name, add_vreg_checks, single_bb=False, verbose=verbose) - elif state == 'function prefix': - m = PREFIX_DATA_RE.match(input_line) + elif state == 'mir function prefix': + m = MIR_PREFIX_DATA_RE.match(input_line) if not m: - state = 'function body' + state = 'mir function body' add_checks_for_function(test, output_lines, run_list, func_dict, func_name, add_vreg_checks, single_bb=True, verbose=verbose) if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) - elif state == 'function body': + elif state == 'mir function body': if input_line.strip() == '...': state = 'toplevel' func_name = None if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) + elif state == 'ir function prefix': + m = IR_PREFIX_DATA_RE.match(input_line) + if not m: + state = 'ir function body' + add_checks_for_function(test, output_lines, run_list, + func_dict, func_name, add_vreg_checks, + single_bb=False, verbose=verbose) + + if should_add_line_to_output(input_line, prefix_set): + output_lines.append(input_line) + elif state == 'ir function body': + if input_line.strip() == '}': + state = 'toplevel' + func_name = None + if should_add_line_to_output(input_line, prefix_set): + output_lines.append(input_line) + log('Writing {} lines to {}...'.format(len(output_lines), test), verbose) |