2019-06-19 17:25:05 +00:00
|
|
|
import sys
|
|
|
|
|
2019-06-13 14:43:11 +00:00
|
|
|
from z3 import *
|
|
|
|
|
|
|
|
class Rule:
|
|
|
|
def __init__(self):
|
|
|
|
self.requirements = []
|
|
|
|
self.constraints = []
|
|
|
|
self.solver = Solver()
|
|
|
|
self.setTimeout(60000)
|
|
|
|
|
|
|
|
def setTimeout(self, _t):
|
|
|
|
self.solver.set("timeout", _t)
|
|
|
|
|
|
|
|
def __lshift__(self, _c):
|
|
|
|
self.constraints.append(_c)
|
|
|
|
|
|
|
|
def require(self, _r):
|
|
|
|
self.requirements.append(_r)
|
|
|
|
|
|
|
|
def check(self, _nonopt, _opt):
|
|
|
|
self.solver.add(self.requirements)
|
|
|
|
result = self.solver.check()
|
|
|
|
|
|
|
|
if result == unknown:
|
2019-06-19 17:25:05 +00:00
|
|
|
self.error('Unable to satisfy requirements.')
|
2019-06-13 14:43:11 +00:00
|
|
|
elif result == unsat:
|
2019-06-19 17:25:05 +00:00
|
|
|
self.error('Requirements are unsatisfiable.')
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
self.solver.push()
|
|
|
|
self.solver.add(self.constraints)
|
|
|
|
self.solver.add(_nonopt != _opt)
|
|
|
|
|
|
|
|
result = self.solver.check()
|
|
|
|
if result == unknown:
|
2019-06-19 17:25:05 +00:00
|
|
|
self.error('Unable to prove rule.')
|
2019-06-13 14:43:11 +00:00
|
|
|
elif result == sat:
|
|
|
|
m = self.solver.model()
|
2019-06-19 17:25:05 +00:00
|
|
|
self.error('Rule is incorrect.\nModel: ' + str(m))
|
2019-06-13 14:43:11 +00:00
|
|
|
self.solver.pop()
|
2019-06-19 17:25:05 +00:00
|
|
|
|
|
|
|
def error(self, msg):
|
|
|
|
print(msg)
|
|
|
|
sys.exit(1)
|