[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


https://bugs.libre-soc.org/show_bug.cgi?id=1094

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

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.

https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;h=84b7982235332e51ca157e8bbe500a3f1e51910e

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


More information about the libre-soc-bugs mailing list