[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 14:20:39 BST 2023


--- Comment #58 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Another option. We visit everything always, but now can filter based on another

def visit(node, handler, matcher=Matcher()):
    node.visit(handler=handler, matcher=matcher, depth=0)

class Database:
    def visit(self, handler, matcher, depth):
        if matcher(node=self, depth=depth):
            with handler(node=self, depth=depth):
                for record in self:
                    record.visit(depth=(depth + 1),
                        handler=handler, matcher=matcher)

Here's how instruction matching looks:

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.


You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-soc-bugs mailing list