def verifyExpr(self, expr): self.funcproto.expr = expr counterexample = self.z3checker.check(str(self.funcproto), self.moreconstraint) def testDelete(): if len(self.moreconstraint) == 0: return None self.moreconstraint.pop(-1) counterexample = self.z3checker.check(str(self.funcproto), self.moreconstraint) if counterexample is None: return testDelete() return counterexample if counterexample is None: counterexample = testDelete() if counterexample is None: return None, None # counterexample = self.z3checker.check(str(self.funcproto), randomConstraint) symtab = {} for i in range(len(self.inputlist)): s = self.inputlist[i] if self.inputtylist[i] == 'Int': symtab[s] = int(str(counterexample.eval(z3.Int(s), True))) else: symtab[s] = int(str(counterexample.eval(z3.Bool(s), True))) innersymtab = self.semchecker.getSymtab(symtab) symtab = [symtab] * len(innersymtab) return innersymtab, symtab
def get_cons_enc(cons): """ Returns z3 instance for each string that declares a constant. """ res = list() for c in list(set(cons)): name, form = c.strip(')').split(' ')[1:] if form == 'Bool': res.append(z3.Bool(name)) elif form == 'Real': res.append(z3.Real(name)) return res
def new_from_sort(self, key): if isinstance(key, Bool): key = key.name val = z3.Bool(key) return val elif isinstance(key, Int): key = key.name val = z3.Int(key) return val elif isinstance(key, String): key = key.name val = z3.String(key) return val elif isinstance(key, BitVec): name = key.name size = key.size val = z3.BitVec(name, size) return val raise TypeError("%s not supported!" %type(key))
def translate(expr, xid): substitutions = dict() def raw(s): return '_'.join(s.split('_')[:-1]) for v in get_vars_non_recursive(expr): if v not in substitutions: v_name = raw(v.decl().name()) if v.sort_kind() == z3.Z3_INT_SORT: substitutions[v] = z3.Int('%s_%d' % (v_name, xid)) elif v.sort_kind() == z3.Z3_BOOL_SORT: substitutions[v] = z3.Bool('%s_%d' % (v_name, xid)) elif v.sort_kind() == z3.Z3_BV_SORT: substitutions[v] = z3.BitVec('%s_%d' % (v_name, xid), v.size()) elif v.sort_kind() == z3.Z3_ARRAY_SORT: substitutions[v] = z3.Array('%s_%d' % (v_name, xid), v.domain(), v.range()) else: raise Exception('CANNOT CONVERT %s (%d)' % (v, v.sort_kind())) subst = list(substitutions.items()) return z3.substitute(expr, subst)
def verifyExpr(self, expr): randomConstraint = [['constraint', ['>=', 'x', '5']], ['constraint', ['>=', 'y', '5']], ['constraint', ['>=', 'z', '5']], ['constraint', ['>=', 'w', '5']], ['constraint', ['true']]] self.funcproto.expr = expr counterexample = self.z3checker.check(str(self.funcproto), []) if counterexample is None: return None, None # counterexample = self.z3checker.check(str(self.funcproto), randomConstraint) symtab = {} for i in range(len(self.inputlist)): s = self.inputlist[i] if self.inputtylist[i] == 'Int': symtab[s] = int(str(counterexample.eval(z3.Int(s), True))) else: symtab[s] = int(str(counterexample.eval(z3.Bool(s), True))) innersymtab = self.semchecker.getSymtab(symtab) symtab = [symtab] * len(innersymtab) return innersymtab, symtab