aboutsummaryrefslogtreecommitdiffstats
path: root/tools/make-dissector-reg.py
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2012-09-17 21:30:24 +0000
committerJeff Morriss <jeff.morriss.ws@gmail.com>2012-09-17 21:30:24 +0000
commit211f791c6cea1e8495788b853b97a10da77478fa (patch)
treef43c8a825833278b882fe90aa1a3a97367ff7248 /tools/make-dissector-reg.py
parenteb08c40b09c8b33a0b0ee0a35e5e057761d24a4f (diff)
Rather than reading the dissectors line by line and searching for the
registration and handoff routines in each line, read the whole file into memory and then do one findall() search. Store the matches in sets to avoid duplication. (This also simplifies the number of regexps we're looking for.) This speeds up the generation of register.c (when there is no cache) significantly (on my system the time taken drops from ~32 seconds to ~5 seconds). svn path=/trunk/; revision=44954
Diffstat (limited to 'tools/make-dissector-reg.py')
-rwxr-xr-xtools/make-dissector-reg.py65
1 files changed, 30 insertions, 35 deletions
diff --git a/tools/make-dissector-reg.py b/tools/make-dissector-reg.py
index 6f1efabcfa..a29626bf32 100755
--- a/tools/make-dissector-reg.py
+++ b/tools/make-dissector-reg.py
@@ -83,32 +83,26 @@ if len(filenames) < 1:
# Look through all files, applying the regex to each line.
# If the pattern matches, save the "symbol" section to the
-# appropriate array.
+# appropriate set.
regs = {
- 'proto_reg': [],
- 'handoff_reg': [],
- 'wtap_register': [],
+ 'proto_reg': set(),
+ 'handoff_reg': set(),
+ 'wtap_register': set(),
}
# For those that don't know Python, r"" indicates a raw string,
# devoid of Python escapes.
-proto_regex0 = r"^(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
-proto_regex1 = r"void\s+(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+proto_regex = r"(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\(\s*void\s*\)"
-handoff_regex0 = r"^(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
-handoff_regex1 = r"void\s+(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+handoff_regex = r"(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\(\s*void\s*\)"
-wtap_reg_regex0 = r"^(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
-wtap_reg_regex1 = r"void\s+(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+wtap_reg_regex = r"(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
# This table drives the pattern-matching and symbol-harvesting
patterns = [
- ( 'proto_reg', re.compile(proto_regex0) ),
- ( 'proto_reg', re.compile(proto_regex1) ),
- ( 'handoff_reg', re.compile(handoff_regex0) ),
- ( 'handoff_reg', re.compile(handoff_regex1) ),
- ( 'wtap_register', re.compile(wtap_reg_regex0) ),
- ( 'wtap_register', re.compile(wtap_reg_regex1) ),
+ ( 'proto_reg', re.compile(proto_regex, re.MULTILINE) ),
+ ( 'handoff_reg', re.compile(handoff_regex, re.MULTILINE) ),
+ ( 'wtap_register', re.compile(wtap_reg_regex, re.MULTILINE) ),
]
# Open our registration symbol cache
@@ -136,9 +130,9 @@ for filename in filenames:
if cur_mtime == cdict['mtime']:
cache_hits += 1
# print "Pulling %s from cache" % (filename)
- regs['proto_reg'].extend(cdict['proto_reg'])
- regs['handoff_reg'].extend(cdict['handoff_reg'])
- regs['wtap_register'].extend(cdict['wtap_register'])
+ regs['proto_reg'] |= set(cdict['proto_reg'])
+ regs['handoff_reg'] |= set(cdict['handoff_reg'])
+ regs['wtap_register'] |= set(cdict['wtap_register'])
file.close()
continue
# We don't have a cache entry
@@ -151,17 +145,19 @@ for filename in filenames:
'wtap_register': [],
}
# print "Searching %s" % (filename)
- for line in file.readlines():
- for action in patterns:
- regex = action[1]
- match = regex.search(line)
- if match:
- symbol = match.group("symbol")
- sym_type = action[0]
- regs[sym_type].append(symbol)
- if cache is not None:
-# print "Caching %s for %s: %s" % (sym_type, filename, symbol)
- cache[filename][sym_type].append(symbol)
+ # Read the whole file into memory
+ contents = file.read()
+ for action in patterns:
+ regex = action[1]
+ for match in regex.finditer(contents):
+ symbol = match.group("symbol")
+ sym_type = action[0]
+ regs[sym_type].add(symbol)
+ if cache is not None:
+# print "Caching %s for %s: %s" % (sym_type, filename, symbol)
+ cache[filename][sym_type].append(symbol)
+ # We're done with the file contents
+ contets = ""
file.close()
@@ -176,11 +172,10 @@ if len(regs['proto_reg']) < 1:
print("No protocol registrations found")
sys.exit(1)
-# Sort the lists to make them pretty
-# Unique-ify the lists to avoid double registrations
-regs['proto_reg'] = sorted(set(regs['proto_reg']))
-regs['handoff_reg'] = sorted(set(regs['handoff_reg']))
-regs['wtap_register'] = sorted(set(regs['wtap_register']))
+# Convert the sets into sorted lists to make the output pretty
+regs['proto_reg'] = sorted(regs['proto_reg'])
+regs['handoff_reg'] = sorted(regs['handoff_reg'])
+regs['wtap_register'] = sorted(regs['wtap_register'])
reg_code = open(tmp_filename, "w")