From abd3b7660bd410253f7df95b55327f0c4aeffcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Wed, 23 Nov 2022 09:14:22 +0100 Subject: [PATCH] improved property detection excluding state transitions --- analyze.py | 2 +- astvisitors.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/analyze.py b/analyze.py index 5ce9873..4d6be99 100644 --- a/analyze.py +++ b/analyze.py @@ -190,7 +190,7 @@ if __name__ == "__main__": reachable_states.append(s) # find properties for f in fsm_funcs: - sccpv = SwitchCaseCodePropertyVisitor(n, pure_sa, prop_func_blacklist) + sccpv = SwitchCaseCodePropertyVisitor(n, states, prop_func_blacklist) sccpv.visit(f) if len(sccpv.properties) > 0: props_by_state[n] = sccpv.properties diff --git a/astvisitors.py b/astvisitors.py index 53a9ed4..a6a75d3 100644 --- a/astvisitors.py +++ b/astvisitors.py @@ -384,10 +384,10 @@ class SwitchCaseTranVisitor(c_ast.NodeVisitor): self.tran_table.append((ft, self._asm_node.rvalue.name)) class SwitchCasePropertyVisitor(c_ast.NodeVisitor): - def __init__(self, state_asmts, func_blacklist = None): + def __init__(self, states, func_blacklist = None): super().__init__() self._func_bl = func_blacklist - self._sas = state_asmts + self.states = states self.properties = [] def visit_FuncCall(self, node): @@ -398,7 +398,11 @@ class SwitchCasePropertyVisitor(c_ast.NodeVisitor): self.properties.append(fcall) def visit_Assignment(self, node): - if not(node in self._sas): + #if not(node in self._sas): + cg = c_generator.CGenerator() + rvalue = cg.visit(node.rvalue) + print("NODE RVAL", rvalue) + if not(rvalue in self.states): lvalue = None rvalue = None if isinstance(node.lvalue, c_ast.StructRef): @@ -418,11 +422,11 @@ class SwitchCasePropertyVisitor(c_ast.NodeVisitor): class SwitchCaseCodePropertyVisitor(c_ast.NodeVisitor): - def __init__(self, case, state_asmts, func_blacklist): + def __init__(self, case, states, func_blacklist): super().__init__() self._func_bl = func_blacklist self._case = case - self._sas = state_asmts + self.states = states self.properties = [] def visit_Case(self, node): @@ -431,7 +435,7 @@ class SwitchCaseCodePropertyVisitor(c_ast.NodeVisitor): clev = CaseLabelExtractionVisitor() clev.visit(label) if clev.label == self._case: - scpv = SwitchCasePropertyVisitor(self._sas, self._func_bl) + scpv = SwitchCasePropertyVisitor(self.states, self._func_bl) scpv.visit(block) self.properties += scpv.properties