diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2019-12-02 10:50:23 +0000 |
---|---|---|
committer | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2019-12-02 11:06:30 +0000 |
commit | d9542db49e90457de62af3bfe395aaf4c47b68a5 (patch) | |
tree | 377ec48c0c1ddcf014f94a3a472e29e3f6b1f80f /llvm/utils/UpdateTestChecks/common.py | |
parent | 160a5045c699ac523eac3c7a1984705c3e86720e (diff) | |
download | bcm5719-llvm-d9542db49e90457de62af3bfe395aaf4c47b68a5.tar.gz bcm5719-llvm-d9542db49e90457de62af3bfe395aaf4c47b68a5.zip |
[UpdateTestChecks] Share the code to parse RUN: lines between all scripts
Summary:
This commit also introduces a common.debug() function to avoid many
`if args.verbose:` statements. Depends on D70428.
Reviewers: xbolva00, MaskRay, jdoerfert
Reviewed By: MaskRay
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70432
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index f0646051090..dfb3b16ae6b 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -14,12 +14,17 @@ else: ##### Common utilities for update_*test_checks.py +_verbose = False + def parse_commandline_args(parser): parser.add_argument('-v', '--verbose', action='store_true', help='Show verbose output') parser.add_argument('-u', '--update-only', action='store_true', help='Only update test if it was already autogened') - return parser.parse_args() + args = parser.parse_args() + global _verbose + _verbose = args.verbose + return args def should_add_line_to_output(input_line, prefix_set): # Skip any blank comment lines in the IR. @@ -53,7 +58,7 @@ def invoke_tool(exe, cmd_args, ir): ##### LLVM IR parser -RUN_LINE_RE = re.compile(r'^\s*[;#]\s*RUN:\s*(.*)$') +RUN_LINE_RE = re.compile(r'^\s*(?://|[;#])\s*RUN:\s*(.*)$') CHECK_PREFIX_RE = re.compile(r'--?check-prefix(?:es)?[= ](\S+)') PREFIX_RE = re.compile('^[a-zA-Z0-9_-]+$') CHECK_RE = re.compile(r'^\s*[;#]\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL|-SAME)?:') @@ -91,6 +96,28 @@ def warn(msg, test_file=None): msg = '{}: {}'.format(msg, test_file) print('WARNING: {}'.format(msg), file=sys.stderr) +def debug(*args, **kwargs): + # Python2 does not allow def debug(*args, file=sys.stderr, **kwargs): + if 'file' not in kwargs: + kwargs['file'] = sys.stderr + if _verbose: + print(*args, **kwargs) + +def find_run_lines(test, lines): + debug('Scanning for RUN lines in test file:', test) + raw_lines = [m.group(1) + for m in [RUN_LINE_RE.match(l) for l in lines] if m] + run_lines = [raw_lines[0]] if len(raw_lines) > 0 else [] + for l in raw_lines[1:]: + if run_lines[-1].endswith('\\'): + run_lines[-1] = run_lines[-1].rstrip('\\' + ' ' + l) + else: + run_lines.append(l) + debug('Found {} RUN lines in {}:'.format(len(run_lines), test)) + for l in run_lines: + debug(' RUN: {}'.format(l)) + return run_lines + def scrub_body(body): # Scrub runs of whitespace out of the assembly, but leave the leading # whitespace in place. |