[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Wed Jun 7 18:18:57 BST 2023
https://bugs.libre-soc.org/show_bug.cgi?id=1094
--- Comment #59 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Dmitry Selyutin from comment #58)
> Another option. We visit everything always, but now can filter based on
> another visitor:
i initially went "ah ha!" but then realised that the idea
is missing the fundamental, and it's that the "walking" is
still not separate from the "action".
until the *act of walking* is separated from the "action taken on the walk"
there will be serious issues later.
here is how it is separated in ast.py:
https://github.com/python/cpython/blob/2.7/Lib/ast.py#L203
there are three functions involved: walk, iter_child_nodes, and iter_fields.
by creating a Base Class from which all aspects of insndb derive,
it will be possible to replace "if isinstance(field, AST):" (at line
179 and others) with "if isinstance(field, InsnDB_BaseClass)"
and it will be possible to lift that recursive-walk code from ast.py
pretty much as-is.
> def visit(node, handler, matcher=Matcher()):
> node.visit(handler=handler, matcher=matcher, depth=0)
(btw the depth argument needs to be removed. it
is the Visitor instance that must keep its *own*
track of "depth")
> class InstructionMatcher(Matcher):
> def Record(self, node, depth):
> return (node.name == self["insn"])
>
> The trick is that we have two different visitors, one calls the check and
> another calls the corresponding context manager. Both resort to `return
> True` and `yield node` respectively.
unfortunately whilst on the face of it i thought "ah ha! excellent"
i realised this just moves the problem of recursive-iteration from
the Visitor into the Matcher.
> https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;
> h=84b7982235332e51ca157e8bbe500a3f1e51910e
yep it's increasing code-size rather than decreasing it.
the fundamental code *really* should be no greater than around
100 lines, this is the "litmus test".
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list