diff options
author | Giorgis Georgakoudis <georgakoudis1@llnl.gov> | 2021-02-19 20:22:14 -0800 |
---|---|---|
committer | Giorgis Georgakoudis <georgakoudis1@llnl.gov> | 2021-03-12 17:37:09 -0800 |
commit | 1ce846be04f8ce7f899e37424772c0bef1851f76 (patch) | |
tree | dcde80304533d6ae2293696abe7b77632fd54863 /llvm/utils/UpdateTestChecks/common.py | |
parent | 22e9753271b71e2c067aadd5b877eef8198cadd2 (diff) | |
download | llvm-1ce846be04f8ce7f899e37424772c0bef1851f76.zip llvm-1ce846be04f8ce7f899e37424772c0bef1851f76.tar.gz llvm-1ce846be04f8ce7f899e37424772c0bef1851f76.tar.bz2 |
Replace func name with regex for update test scripts
The patch adds an argument to update test scripts, such as update_cc_test_checks, for replacing a function name matching a regex. This functionality is needed to match generated function signatures that include file hashes. Example:
The function signature for the following function:
`__omp_offloading_50_b84c41e__Z9ftemplateIiET_i_l30_worker`
with `--replace-function-regex "__omp_offloading_[0-9]+_[a-z0-9]+_(.*)"` will become:
`CHECK-LABEL: @{{__omp_offloading_[0-9]+_[a-z0-9]+__Z9ftemplateIiET_i_l30_worker}}(`
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D97107
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index 5cf5090..b3ca33f 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -30,6 +30,8 @@ def parse_commandline_args(parser): help='Activate CHECK line generation from this point forward') parser.add_argument('--disable', action='store_false', dest='enabled', help='Deactivate CHECK line generation from this point forward') + parser.add_argument('--replace-function-regex', nargs='+', default=[], + help='List of regular expressions to replace matching function names') args = parser.parse_args() global _verbose _verbose = args.verbose @@ -275,6 +277,8 @@ class FunctionTestBuilder: self._record_args = flags.function_signature self._check_attributes = flags.check_attributes self._scrubber_args = scrubber_args + # Strip double-quotes if input was read by UTC_ARGS + self._replace_function_regex = list(map(lambda x: x.strip('"'), flags.replace_function_regex)) self._func_dict = {} self._func_order = {} self._global_var_dict = {} @@ -348,6 +352,30 @@ class FunctionTestBuilder: self._func_dict[prefix][func] = None continue + # Replace function names matching the regex. + for regex in self._replace_function_regex: + # Pattern that matches capture groups in the regex in leftmost order. + group_regex = re.compile('\(.*?\)') + # Replace function name with regex. + match = re.match(regex, func) + if match: + func_repl = regex + # Replace any capture groups with their matched strings. + for g in match.groups(): + func_repl = group_regex.sub(g, func_repl, count=1) + func = '{{' + func_repl + '}}' + + # Replace all calls to regex matching functions. + matches = re.finditer(regex, scrubbed_body) + for match in matches: + func_repl = regex + # Replace any capture groups with their matched strings. + for g in match.groups(): + func_repl = group_regex.sub(g, func_repl, count=1) + # Substitute function call names that match the regex with the same + # capture groups set. + scrubbed_body = re.sub(func_repl, '{{' + func_repl + '}}', scrubbed_body) + self._func_dict[prefix][func] = function_body( scrubbed_body, scrubbed_extra, args_and_sig, attrs) self._func_order[prefix].append(func) @@ -794,6 +822,8 @@ def get_autogennote_suffix(parser, args): continue # Don't add default values autogenerated_note_args += action.option_strings[0] + ' ' if action.const is None: # action takes a parameter + if action.nargs == '+': + value = ' '.join(map(lambda v: '"' + v.strip('"') + '"', value)) autogenerated_note_args += '%s ' % value if autogenerated_note_args: autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1]) |