improved property detection excluding state transitions

This commit is contained in:
Dominic Höglinger 2022-11-23 09:14:22 +01:00
parent ae412bc2d4
commit abd3b7660b
2 changed files with 11 additions and 7 deletions

View File

@ -190,7 +190,7 @@ if __name__ == "__main__":
reachable_states.append(s) reachable_states.append(s)
# find properties # find properties
for f in fsm_funcs: for f in fsm_funcs:
sccpv = SwitchCaseCodePropertyVisitor(n, pure_sa, prop_func_blacklist) sccpv = SwitchCaseCodePropertyVisitor(n, states, prop_func_blacklist)
sccpv.visit(f) sccpv.visit(f)
if len(sccpv.properties) > 0: if len(sccpv.properties) > 0:
props_by_state[n] = sccpv.properties props_by_state[n] = sccpv.properties

View File

@ -384,10 +384,10 @@ class SwitchCaseTranVisitor(c_ast.NodeVisitor):
self.tran_table.append((ft, self._asm_node.rvalue.name)) self.tran_table.append((ft, self._asm_node.rvalue.name))
class SwitchCasePropertyVisitor(c_ast.NodeVisitor): class SwitchCasePropertyVisitor(c_ast.NodeVisitor):
def __init__(self, state_asmts, func_blacklist = None): def __init__(self, states, func_blacklist = None):
super().__init__() super().__init__()
self._func_bl = func_blacklist self._func_bl = func_blacklist
self._sas = state_asmts self.states = states
self.properties = [] self.properties = []
def visit_FuncCall(self, node): def visit_FuncCall(self, node):
@ -398,7 +398,11 @@ class SwitchCasePropertyVisitor(c_ast.NodeVisitor):
self.properties.append(fcall) self.properties.append(fcall)
def visit_Assignment(self, node): 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 lvalue = None
rvalue = None rvalue = None
if isinstance(node.lvalue, c_ast.StructRef): if isinstance(node.lvalue, c_ast.StructRef):
@ -418,11 +422,11 @@ class SwitchCasePropertyVisitor(c_ast.NodeVisitor):
class SwitchCaseCodePropertyVisitor(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__() super().__init__()
self._func_bl = func_blacklist self._func_bl = func_blacklist
self._case = case self._case = case
self._sas = state_asmts self.states = states
self.properties = [] self.properties = []
def visit_Case(self, node): def visit_Case(self, node):
@ -431,7 +435,7 @@ class SwitchCaseCodePropertyVisitor(c_ast.NodeVisitor):
clev = CaseLabelExtractionVisitor() clev = CaseLabelExtractionVisitor()
clev.visit(label) clev.visit(label)
if clev.label == self._case: if clev.label == self._case:
scpv = SwitchCasePropertyVisitor(self._sas, self._func_bl) scpv = SwitchCasePropertyVisitor(self.states, self._func_bl)
scpv.visit(block) scpv.visit(block)
self.properties += scpv.properties self.properties += scpv.properties