From e56eb6238d0bd8e8eba113e1fa3987a3f9c09a37 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Tue, 22 Jun 2021 11:16:12 +0800 Subject: [PATCH] board_inspector: return from method call invocation on DefReturn The current implementation of the AML interpreter continues interpreting a method after meeting a DefReturn object, which is incorrect. This patch fixes this issue by raising a dedicated exception on return and catching that exception on the caller side. Tracked-On: #6298 Signed-off-by: Junjie Mao --- .../board_inspector/acpiparser/aml/interpreter.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py index 57eaf6b2b..72e1be5bb 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py @@ -7,6 +7,11 @@ from .context import * from .datatypes import * from .tree import Tree, Interpreter +class MethodReturn(Exception): + """ A pseudo exception to return from a method""" + def __init__(self): + pass + class ConcreteInterpreter(Interpreter): class Argument(Object): def __init__(self, frame, index): @@ -188,7 +193,10 @@ class ConcreteInterpreter(Interpreter): # Evaluate the statements of the callee self.stack.append(self.StackFrame(realpath, args)) logging.debug(f"Calling {realpath} with args {args}") - self.interpret(value.body) + try: + self.interpret(value.body) + except MethodReturn: + pass frame = self.stack.pop() self.context.pop_scope() @@ -335,6 +343,7 @@ class ConcreteInterpreter(Interpreter): if isinstance(obj, (self.Argument, self.LocalVariable)): obj = obj.get_obj() self.stack[-1].return_value = obj + raise MethodReturn() return None def DefSignal(self, tree):