From 20fffeabddb5754e1c26bb099229df4507265fda Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 10 Dec 2024 13:50:02 -0700 Subject: stack.c.gen: Better handling of dynamic nodes --- build-aux/stack.c.gen | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'build-aux') diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen index 2ce874d..7af8bc4 100755 --- a/build-aux/stack.c.gen +++ b/build-aux/stack.c.gen @@ -95,6 +95,8 @@ def parse_vcg(reader: typing.TextIO) -> typing.Iterator[VCGElem]: ################################################################################ # Main analysis +UsageKind: typing.TypeAlias = typing.Literal["static", "dynamic", "dynamic,bounded"] + class Node: # from .title (`static` and `__weak` functions are prefixed with @@ -103,6 +105,7 @@ class Node: funcname: str # .label is "{funcname}\n{location}\n{nstatic} bytes (static}\n{ndynamic} dynamic objects" location: str + usage_kind: UsageKind nstatic: int ndynamic: int @@ -116,6 +119,7 @@ def synthetic_node(name: str, nstatic: int, calls: set[str] = set()) -> Node: n.funcname = name n.location = "" + n.usage_kind = "static" n.nstatic = nstatic n.ndynamic = 0 @@ -163,9 +167,10 @@ def analyze( raise ValueError( f"unexpected label value {repr(v)}" ) - if m.group("usage_kind") == "dynamic": - print(f"// warning: can't handle dynamic stack usage: {repr(elem.attrs.get("title", ""))}") node.location = m.group("location") + node.usage_kind = typing.cast( + UsageKind, m.group("usage_kind") + ) node.nstatic = int(m.group("nstatic")) node.ndynamic = int(m.group("ndynamic")) case "shape": @@ -219,8 +224,7 @@ def analyze( graph[node.funcname] = node missing: set[str] = set() - - print("/*") + dynamic: set[str] = set() dbg = False @@ -258,10 +262,14 @@ def analyze( node = graph[funcname] if dbg: print(f"//dbg: {funcname}\t{node.nstatic}") + if node.usage_kind == "dynamic" or node.ndynamic > 0: + dynamic.add(funcname) return node.nstatic + max( [0, *[nstatic(call, chain + [funcname]) for call in node.calls]] ) + print("/*") + for grp_name, grp_filter in app_func_filters.items(): # Gather the data. nmax = 0 @@ -292,6 +300,8 @@ def analyze( for funcname in sorted(missing): print(f"warning: missing: {funcname}") + for funcname in sorted(dynamic): + print(f"warning: dynamic: {funcname}") print("*/") -- cgit v1.2.3-2-g168b