[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 21:02:01 BST 2023
https://bugs.libre-soc.org/show_bug.cgi?id=1094
--- Comment #60 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Decoupled visitors from walking:
https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;h=7de83fc89028c55a36af2210b80c426e24e6b5b9
The record filtering is now implemented in terms of concrete visitor. That's
the whole code:
class Visitor:
def __call__(self, node):
method = node.__class__.__name__
method = getattr(self, method, self.Node)
return method(node=node)
@_contextlib.contextmanager
def Node(self, node):
for subnode in node.subnodes:
with self(subnode):
pass
yield node
class Record(Node):
@property
def subnodes(self):
for (name, fields) in self.extras.items():
yield Extra(name=name, **fields)
class Database(Node):
@property
def subnodes(self):
yield from self
Obviously there's more in Record and Database to be visited, just a practical
example. FWIW, here's how the filtering now looks:
class RecordNameVisitor(Visitor):
def __init__(self, name):
self.__name = name
self.__records = set()
return super().__init__()
@contextlib.contextmanager
def Record(self, node):
if node.name == self.__name:
self.__records.add(node)
yield node
def __iter__(self):
yield from self.__records
match = RecordNameVisitor(name=args["insn"])
with match(node=db):
nodes = frozenset(match)
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list