Commit 074777c0 authored by Paul Fiterau Brostean's avatar Paul Fiterau Brostean
Browse files

Commit before model change

parent d1eaf4a3
...@@ -58,7 +58,7 @@ sut_m2 = RaTestScenario("store_1_true_then_remember", [ ...@@ -58,7 +58,7 @@ sut_m2 = RaTestScenario("store_1_true_then_remember", [
# This is a check for Rick, ignore the traces below # This is a check for Rick, ignore the traces below
# ([act(1), act(1), act(2), act(1), act(1)], False), # ([act(1), act(1), act(2), act(1), act(1)], False),
# ([act(1), act(1), act(2), act(1), act(2)], True) # ([act(1), act(1), act(2), act(1), act(2)], True)
], 5, 1) ], 4, 1)
# check for unique valuedness (non-UV 4 LOC, UV 5 LOC) # check for unique valuedness (non-UV 4 LOC, UV 5 LOC)
sut_m3 = RaTestScenario ("store_2_select_either_UV", [ sut_m3 = RaTestScenario ("store_2_select_either_UV", [
...@@ -86,7 +86,7 @@ sut_m3 = RaTestScenario ("store_2_select_either_UV", [ ...@@ -86,7 +86,7 @@ sut_m3 = RaTestScenario ("store_2_select_either_UV", [
([act(1), act(2), act(2), act(1)], True), ([act(1), act(2), act(2), act(1)], True),
([act(1), act(2), act(3), act(4), act(1)], True), ([act(1), act(2), act(3), act(4), act(1)], True),
([act(1), act(2), act(2), act(2), act(3)], True) ([act(1), act(2), act(2), act(2), act(3)], True)
], 4, 2) ], 5, 2)
# check for non-shifting property (3 LOC NS, 4 LOC non-NS) # check for non-shifting property (3 LOC NS, 4 LOC non-NS)
# expect this system to require one additional location than if our constraints allowed value shifting between registers # expect this system to require one additional location than if our constraints allowed value shifting between registers
......
...@@ -6,7 +6,7 @@ from z3gi.define.ra import RegisterAutomaton ...@@ -6,7 +6,7 @@ from z3gi.define.ra import RegisterAutomaton
import model.ra import model.ra
import z3 import z3
num_exp = 4 num_exp = 1
class RaLearnerTest(unittest.TestCase): class RaLearnerTest(unittest.TestCase):
......
...@@ -106,7 +106,7 @@ class RegisterAutomatonBuilder(object): ...@@ -106,7 +106,7 @@ class RegisterAutomatonBuilder(object):
for (z3end_state, z3guards) in z3end_state_to_guards.items(): for (z3end_state, z3guards) in z3end_state_to_guards.items():
# a transition which makes an assignment is never merged # a transition which makes an assignment is never merged
if self.ra.fresh in z3guards and update is not self.ra.fresh: if self.ra.fresh in z3guards and not translator.z3_to_bool(model.eval(update == self.ra.fresh)):
self._add_transition(translator, mut_ra, z3state, z3label, self._add_transition(translator, mut_ra, z3state, z3label,
[self.ra.fresh], update, z3end_state, used_z3regs) [self.ra.fresh], update, z3end_state, used_z3regs)
z3guards.remove(self.ra.fresh) z3guards.remove(self.ra.fresh)
...@@ -179,7 +179,7 @@ class IORegisterAutomatonBuilder(object): ...@@ -179,7 +179,7 @@ class IORegisterAutomatonBuilder(object):
print("For {0} we have the transitions \n {1}".format(z3state, z3end_state_to_guards)) print("For {0} we have the transitions \n {1}".format(z3state, z3end_state_to_guards))
for (z3out_state, z3guards) in z3end_state_to_guards.items(): for (z3out_state, z3guards) in z3end_state_to_guards.items():
# a transition which makes an assignment is never merged # a transition which makes an assignment is never merged
if self.ra.fresh in z3guards and update is not self.ra.fresh: if self.ra.fresh in z3guards and not translator.z3_to_bool(model.eval(update == self.ra.fresh)):
self._add_transition(model, translator, mut_ra, z3state, z3label, self._add_transition(model, translator, mut_ra, z3state, z3label,
[self.ra.fresh], update, z3out_state, [self.ra.fresh], update, z3out_state,
z3output_labels, used_z3regs) z3output_labels, used_z3regs)
......
...@@ -32,9 +32,6 @@ class RALearner(Learner): ...@@ -32,9 +32,6 @@ class RALearner(Learner):
return ra_def.export(m) return ra_def.export(m)
return None return None
def print_tree(self):
self.encoder.print_tree()
def _learn_model(self, min_locations=1, max_locations=20, max_registers=10): def _learn_model(self, min_locations=1, max_locations=20, max_registers=10):
"""generates the definition and model for an ra whose traces include the traces added so far""" """generates the definition and model for an ra whose traces include the traces added so far"""
num_values = len(self.encoder.values) num_values = len(self.encoder.values)
......
...@@ -70,7 +70,7 @@ class IORATransition(RATransition): ...@@ -70,7 +70,7 @@ class IORATransition(RATransition):
def output(self, valuation, values): def output(self, valuation, values):
if type(self.output_mapping) == Fresh: if type(self.output_mapping) == Fresh:
return Action(self.output_label, max(values) + 1) return Action(self.output_label, max(values) + 1 if len(values) > 0 else 0)
else: else:
return Action(self.output_label, valuation[self.output_mapping]) return Action(self.output_label, valuation[self.output_mapping])
...@@ -101,6 +101,7 @@ class RegisterMachine(): ...@@ -101,6 +101,7 @@ class RegisterMachine():
raise MultipleTransitionsFired raise MultipleTransitionsFired
return fired_transitions[0] return fired_transitions[0]
class RegisterAutomaton(Acceptor, RegisterMachine): class RegisterAutomaton(Acceptor, RegisterMachine):
def __init__(self, locations, loc_to_acc, loc_to_trans, registers): def __init__(self, locations, loc_to_acc, loc_to_trans, registers):
super().__init__(locations, loc_to_trans, loc_to_acc) super().__init__(locations, loc_to_trans, loc_to_acc)
...@@ -165,6 +166,7 @@ class IORegisterAutomaton(Transducer, RegisterMachine): ...@@ -165,6 +166,7 @@ class IORegisterAutomaton(Transducer, RegisterMachine):
output_action = fired_transition.output(reg_val, values) output_action = fired_transition.output(reg_val, values)
# based on this output, the transition should update the set of registers # based on this output, the transition should update the set of registers
reg_val = fired_transition.output_update(reg_val, output_action) reg_val = fired_transition.output_update(reg_val, output_action)
values.add(output_action.value)
crt_state = fired_transition.end_state crt_state = fired_transition.end_state
return (crt_state, reg_val, values) return (crt_state, reg_val, values)
...@@ -177,9 +179,19 @@ class IORegisterAutomaton(Transducer, RegisterMachine): ...@@ -177,9 +179,19 @@ class IORegisterAutomaton(Transducer, RegisterMachine):
action = trace[-1] action = trace[-1]
transitions = super().transitions(reached_state, action.label) transitions = super().transitions(reached_state, action.label)
fired_transition = super()._fired_transition(transitions, valuation, action) fired_transition = super()._fired_transition(transitions, valuation, action)
values.add(action.value)
output = fired_transition.output(valuation, values) output = fired_transition.output(valuation, values)
return output return output
def compress(self):
mutable_ra = MutableIORegisterAutomaton()
[mutable_ra.add_state(state) for state in self.states()]
for state in self.states():
transitions = self.transitions()
class MutableRegisterAutomaton(RegisterAutomaton, MutableAcceptorMixin): class MutableRegisterAutomaton(RegisterAutomaton, MutableAcceptorMixin):
def __init__(self): def __init__(self):
super().__init__([], dict(), dict(), []) super().__init__([], dict(), dict(), [])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment