From aaf0877baf437395f915b8a12457a72b77fc39ce Mon Sep 17 00:00:00 2001 From: Gereon Kremer Date: Thu, 4 Nov 2021 08:58:24 -0700 Subject: [PATCH] Add support for special tag collectors (#7562) This PR makes the collection of trace and debug tags more flexible by allowing for "special tag collectors". They can be used to inject tags that are not used as constant strings, but only assembled dynamically at runtime. One example is the set of assertions::pre-X and assertions::post-X tags. They are currently handled by Dump, and will be migrated to Trace. --- src/base/collect_tags.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/base/collect_tags.py b/src/base/collect_tags.py index 86cc94053..e2f840132 100644 --- a/src/base/collect_tags.py +++ b/src/base/collect_tags.py @@ -28,9 +28,21 @@ def parse_args(): ap.add_argument('basedir', help='where to look for source file') return ap.parse_args() +# Special collector functions for tags that may not occur in source files. This +# can be useful when we print information with a dynamically generated tag. +special_collectors = [ + { + 'patterns' : ['assertions::pre-{}', 'assertions::post-{}'], + 'collector' : lambda basedir: + re.findall('registerPassInfo\("([a-z-]+)"', + open(os.path.join(basedir, 'preprocessing', 'preprocessing_pass_registry.cpp')).read() + ) + } +] def collect_tags(basedir): - """Collect all tags used in filed within the given base directory. + """Collect all tags used in files within the given base directory and then + adds all tags generated by the special collectors specified above. Return them sorted lexicographically.""" tags = set() for ext in ['.cc', '.cpp', '.g', '.h']: @@ -38,6 +50,10 @@ def collect_tags(basedir): content = open(filename, 'rb').read().decode() for tag in RE_PAT.finditer(content): tags.add(tag.group(1)) + for sc in special_collectors: + for tag in sc['collector'](basedir): + for pat in sc['patterns']: + tags.add(pat.format(tag)) return sorted(tags) -- 2.30.2