[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Mon May 29 23:03:59 BST 2023


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

--- Comment #1 from Jacob Lifshay <programmerjake at gmail.com> ---
an idea i had for making it easier -- use with and contextmanager:

def visit(db, visitor):
    with visitor.db(db):
        for i, insn in enumerate(db):
            with visitor.insn(i, insn):
                for i, operand in enumerate(insn):
                    visitor.operand(i, operand)

class MyDemoVisitor:
    @contextmanager
    def db(self, db):
        print("before insns")
        yield
        print("after insns")

    @contextmanager
    def insn(self, insn_index, insn):
        print("before operands")
        yield
        print("after operands")

    def operand(self, operand_index, operand):
        print("operand")

generates output like:
before insns
before operands
operand
operand
after operands
before operands
operand
operand
operand
after operands
after insns

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


More information about the libre-soc-bugs mailing list