From 6a45430e83a845dc6274b1785d6816fd61897117 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 30 Apr 2025 15:04:26 -0600 Subject: measurestack: app_plugins.py: Scope regexes to the classes --- build-aux/measurestack/app_plugins.py | 91 +++++++++++++++++------------------ 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'build-aux/measurestack/app_plugins.py') diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py index ae2dba9..a7d4647 100644 --- a/build-aux/measurestack/app_plugins.py +++ b/build-aux/measurestack/app_plugins.py @@ -55,17 +55,16 @@ class CmdPlugin: return {} -re_comment = re.compile(r"/\*.*?\*/") -re_ws = re.compile(r"\s+") -re_lo_iface = re.compile(r"^\s*#\s*define\s+(?P\S+)_LO_IFACE") -re_lo_func = re.compile(r"LO_FUNC *\([^,]*, *(?P[^,) ]+) *[,)]") -re_lo_implementation = re.compile( - r"^LO_IMPLEMENTATION_[HC]\s*\(\s*(?P[^, ]+)\s*,\s*(?P[^,]+)\s*,\s*(?P[^, ]+)\s*[,)].*" -) -re_call_objcall = re.compile(r"LO_CALL\((?P[^,]+), (?P[^,)]+)[,)].*") - - class LibMiscPlugin: + re_comment = re.compile(r"/\*.*?\*/") + re_ws = re.compile(r"\s+") + re_lo_iface = re.compile(r"^\s*#\s*define\s+(?P\S+)_LO_IFACE") + re_lo_func = re.compile(r"LO_FUNC *\([^,]*, *(?P[^,) ]+) *[,)]") + re_lo_implementation = re.compile( + r"^LO_IMPLEMENTATION_[HC]\s*\(\s*(?P[^, ]+)\s*,\s*(?P[^,]+)\s*,\s*(?P[^, ]+)\s*[,)].*" + ) + re_call_objcall = re.compile(r"LO_CALL\((?P[^,]+), (?P[^,)]+)[,)].*") + objcalls: dict[str, set[QName]] # method_name => {method_impls} def __init__(self, arg_c_fnames: typing.Collection[str]) -> None: @@ -73,16 +72,16 @@ class LibMiscPlugin: for fname in arg_c_fnames: with open(fname, "r", encoding="utf-8") as fh: while line := fh.readline(): - if m := re_lo_iface.match(line): + if m := self.re_lo_iface.match(line): iface_name = m.group("name") if iface_name not in ifaces: ifaces[iface_name] = set() while line.endswith("\\\n"): line += fh.readline() line = line.replace("\\\n", " ") - line = re_comment.sub(" ", line) - line = re_ws.sub(" ", line) - for m2 in re_lo_func.finditer(line): + line = self.re_comment.sub(" ", line) + line = self.re_ws.sub(" ", line) + for m2 in self.re_lo_func.finditer(line): ifaces[iface_name].add(m2.group("name")) implementations: dict[str, set[str]] = {} # iface_name => {impl_names} @@ -92,7 +91,7 @@ class LibMiscPlugin: with open(fname, "r", encoding="utf-8") as fh: for line in fh: line = line.strip() - if m := re_lo_implementation.match(line): + if m := self.re_lo_implementation.match(line): implementations[m.group("iface")].add(m.group("impl_name")) objcalls: dict[str, set[QName]] = {} # method_name => {method_impls} @@ -121,7 +120,7 @@ class LibMiscPlugin: ) -> tuple[typing.Collection[QName], bool] | None: if "/3rd-party/" in loc: return None - if m := re_call_objcall.fullmatch(line): + if m := self.re_call_objcall.fullmatch(line): if m.group("meth") in self.objcalls: return self.objcalls[m.group("meth")], False return [ @@ -268,19 +267,18 @@ class LibCRIPCPlugin: return {} -re_tmessage_handler = re.compile( - r"^\s*\[LIB9P_TYP_T[^]]+\]\s*=\s*\(tmessage_handler\)\s*(?P\S+),\s*$" -) -re_lib9p_msg_entry = re.compile(r"^\s*_MSG_(?:[A-Z]+)\((?P\S+)\),$") -re_lib9p_caller = re.compile( - r"^lib9p_(?P[TR])msg_(?Pvalidate|unmarshal|marshal)$" -) -re_lib9p_callee = re.compile( - r"^(?Pvalidate|unmarshal|marshal)_(?P(?P[TR]).*)$" -) - - class Lib9PPlugin: + re_tmessage_handler = re.compile( + r"^\s*\[LIB9P_TYP_T[^]]+\]\s*=\s*\(tmessage_handler\)\s*(?P\S+),\s*$" + ) + re_lib9p_msg_entry = re.compile(r"^\s*_MSG_(?:[A-Z]+)\((?P\S+)\),$") + re_lib9p_caller = re.compile( + r"^lib9p_(?P[TR])msg_(?Pvalidate|unmarshal|marshal)$" + ) + re_lib9p_callee = re.compile( + r"^(?Pvalidate|unmarshal|marshal)_(?P(?P[TR]).*)$" + ) + tmessage_handlers: set[QName] | None lib9p_msgs: set[str] _CONFIG_9P_MAX_CONNS: int | None @@ -344,7 +342,7 @@ class Lib9PPlugin: with open(lib9p_srv_c_fname, "r", encoding="utf-8") as fh: for line in fh: line = line.rstrip() - if m := re_tmessage_handler.fullmatch(line): + if m := self.re_tmessage_handler.fullmatch(line): tmessage_handlers.add(QName(m.group("handler"))) self.tmessage_handlers = tmessage_handlers @@ -353,7 +351,7 @@ class Lib9PPlugin: with open(lib9p_generated_c_fname, "r", encoding="utf-8") as fh: for line in fh: line = line.rstrip() - if m := re_lib9p_msg_entry.fullmatch(line): + if m := self.re_lib9p_msg_entry.fullmatch(line): typ = m.group("typ") lib9p_msgs.add(typ) self.lib9p_msgs = lib9p_msgs @@ -421,10 +419,10 @@ class Lib9PPlugin: def _skipmodel__lib9p_validate_unmarshal_marshal( self, chain: typing.Sequence[QName], call: QName ) -> bool: - m_caller = re_lib9p_caller.fullmatch(str(chain[-2].base())) + m_caller = self.re_lib9p_caller.fullmatch(str(chain[-2].base())) assert m_caller - m_callee = re_lib9p_callee.fullmatch(str(call.base())) + m_callee = self.re_lib9p_callee.fullmatch(str(call.base())) if not m_callee: return False return m_caller.group("grp") != m_callee.group("grp") @@ -763,16 +761,17 @@ class PicoSDKPlugin: return ret -re_tud_class = re.compile( - r"^\s*#\s*define\s+(?PCFG_TUD_(?:\S{3}|AUDIO|VIDEO|MIDI|VENDOR|USBTMC|DFU_RUNTIME|ECM_RNDIS))\s+(?P\S+).*" -) -re_tud_entry = re.compile(r"^\s+\.(?P\S+)\s*=\s*(?P[a-zA-Z0-9_]+)(?:,.*)?") -re_tud_if1 = re.compile(r"^\s*#\s*if (\S+)\s*") -re_tud_if2 = re.compile(r"^\s*#\s*if (\S+)\s*\|\|\s*(\S+)\s*") -re_tud_endif = re.compile(r"^\s*#\s*endif\s*") - - class TinyUSBDevicePlugin: + re_tud_class = re.compile( + r"^\s*#\s*define\s+(?PCFG_TUD_(?:\S{3}|AUDIO|VIDEO|MIDI|VENDOR|USBTMC|DFU_RUNTIME|ECM_RNDIS))\s+(?P\S+).*" + ) + re_tud_entry = re.compile( + r"^\s+\.(?P\S+)\s*=\s*(?P[a-zA-Z0-9_]+)(?:,.*)?" + ) + re_tud_if1 = re.compile(r"^\s*#\s*if (\S+)\s*") + re_tud_if2 = re.compile(r"^\s*#\s*if (\S+)\s*\|\|\s*(\S+)\s*") + re_tud_endif = re.compile(r"^\s*#\s*endif\s*") + tud_drivers: dict[str, set[QName]] # method_name => {method_impls} def __init__(self, arg_c_fnames: typing.Collection[str]) -> None: @@ -794,7 +793,7 @@ class TinyUSBDevicePlugin: in_table = False for line in fh: line = line.rstrip() - if m := re_tud_class.fullmatch(line): + if m := self.re_tud_class.fullmatch(line): k = m.group("k") v = m.group("v") tusb_config[k] = bool(int(v)) @@ -806,13 +805,13 @@ class TinyUSBDevicePlugin: for line in fh: line = line.rstrip() if in_table: - if m := re_tud_if1.fullmatch(line): + if m := self.re_tud_if1.fullmatch(line): enabled = tusb_config[m.group(1)] - elif m := re_tud_if2.fullmatch(line): + elif m := self.re_tud_if2.fullmatch(line): enabled = tusb_config[m.group(1)] or tusb_config[m.group(2)] - elif re_tud_endif.fullmatch(line): + elif self.re_tud_endif.fullmatch(line): enabled = True - if m := re_tud_entry.fullmatch(line): + if m := self.re_tud_entry.fullmatch(line): meth = m.group("meth") impl = m.group("impl") if meth == "name" or not enabled: -- cgit v1.2.3-2-g168b From 6c755aadeb3ffff941667c70a93ef0e7cdd41a98 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 2 May 2025 01:38:12 -0600 Subject: measurestack: Fix+test printf measurement --- build-aux/measurestack/app_plugins.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'build-aux/measurestack/app_plugins.py') diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py index a7d4647..8eda36c 100644 --- a/build-aux/measurestack/app_plugins.py +++ b/build-aux/measurestack/app_plugins.py @@ -136,11 +136,11 @@ class LibMiscPlugin: } def _skipmodel___assert_msg_fail( - self, chain: typing.Sequence[QName], call: QName + self, chain: typing.Sequence[QName], node: Node, call: QName ) -> bool: if call.base() in [BaseName("__lm_printf"), BaseName("__lm_light_printf")]: return any( - c.base() == BaseName("__assert_msg_fail") for c in reversed(chain[:-1]) + c.base() == BaseName("__assert_msg_fail") for c in reversed(chain) ) return False @@ -399,15 +399,15 @@ class Lib9PPlugin: def skipmodels(self) -> dict[BaseName, analyze.SkipModel]: ret: dict[BaseName, analyze.SkipModel] = { BaseName("_lib9p_validate"): analyze.SkipModel( - 2, + 1, self._skipmodel__lib9p_validate_unmarshal_marshal, ), BaseName("_lib9p_unmarshal"): analyze.SkipModel( - 2, + 1, self._skipmodel__lib9p_validate_unmarshal_marshal, ), BaseName("_lib9p_marshal"): analyze.SkipModel( - 2, + 1, self._skipmodel__lib9p_validate_unmarshal_marshal, ), BaseName("_vfctprintf"): analyze.SkipModel( @@ -417,9 +417,9 @@ class Lib9PPlugin: return ret def _skipmodel__lib9p_validate_unmarshal_marshal( - self, chain: typing.Sequence[QName], call: QName + self, chain: typing.Sequence[QName], node: Node, call: QName ) -> bool: - m_caller = self.re_lib9p_caller.fullmatch(str(chain[-2].base())) + m_caller = self.re_lib9p_caller.fullmatch(str(chain[-1].base())) assert m_caller m_callee = self.re_lib9p_callee.fullmatch(str(call.base())) @@ -428,7 +428,7 @@ class Lib9PPlugin: return m_caller.group("grp") != m_callee.group("grp") def _skipmodel__vfctprintf( - self, chain: typing.Sequence[QName], call: QName + self, chain: typing.Sequence[QName], node: Node, call: QName ) -> bool: if call.base() == BaseName("libfmt_conv_formatter"): return any(c.base() in self.formatters for c in chain) @@ -510,7 +510,7 @@ class PicoFmtPlugin: return ret def _skipmodel_fmt_state_putchar( - self, chain: typing.Sequence[QName], call: QName + self, chain: typing.Sequence[QName], node: Node, call: QName ) -> bool: if call.base() in self.known_fct.values(): fct: BaseName | None = None -- cgit v1.2.3-2-g168b