From: Dmitry Selyutin Date: Mon, 8 Jan 2024 13:19:38 +0000 (+0300) Subject: oppc: swap declaration X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b2a66320fa9fdd92521b930e3449ac3f46184f5d;p=openpower-isa.git oppc: swap declaration --- diff --git a/src/openpower/oppc/pc_util.py b/src/openpower/oppc/pc_util.py index 183f6feb..e3e184ed 100644 --- a/src/openpower/oppc/pc_util.py +++ b/src/openpower/oppc/pc_util.py @@ -9,6 +9,19 @@ import mdis.walker import openpower.oppc.pc_ast as pc_ast +class Hook(mdis.dispatcher.Hook): + def __call__(self, call): + hook = super().__call__(call) + + class ConcreteHook(hook.__class__): + @functools.wraps(hook.__call__) + @contextlib.contextmanager + def __call__(self, dispatcher, node, *args, **kwargs): + return hook(dispatcher, node, *args, **kwargs) + + return ConcreteHook(*tuple(self)) + + class Code(list): def __init__(self): self.__level = 0 @@ -37,19 +50,6 @@ class Code(list): self.append(item) -class Hook(mdis.dispatcher.Hook): - def __call__(self, call): - hook = super().__call__(call) - - class ConcreteHook(hook.__class__): - @functools.wraps(hook.__call__) - @contextlib.contextmanager - def __call__(self, dispatcher, node, *args, **kwargs): - return hook(dispatcher, node, *args, **kwargs) - - return ConcreteHook(*tuple(self)) - - class PseudocodeVisitor(mdis.visitor.ContextVisitor): def __init__(self, root): self.__root = root