Exemple #1
0
 def walk_bv_comp(self, formula, args, **kwargs):
     cond = z3.Z3_mk_eq(self.ctx.ref(), args[0], args[1])
     z3.Z3_inc_ref(self.ctx.ref(), cond)
     then_ = z3.Z3_mk_numeral(self.ctx.ref(), "1", self.z3BitVecSort(1).ast)
     z3.Z3_inc_ref(self.ctx.ref(), then_)
     else_ = z3.Z3_mk_numeral(self.ctx.ref(), "0", self.z3BitVecSort(1).ast)
     z3.Z3_inc_ref(self.ctx.ref(), else_)
     z3term = z3.Z3_mk_ite(self.ctx.ref(), cond, then_, else_)
     z3.Z3_inc_ref(self.ctx.ref(), z3term)
     # De-Ref since this is handled internally by Z3
     z3.Z3_dec_ref(self.ctx.ref(), cond)
     z3.Z3_dec_ref(self.ctx.ref(), then_)
     z3.Z3_dec_ref(self.ctx.ref(), else_)
     return z3term
Exemple #2
0
 def __del__(self):
     # Cleaning-up Z3Converter requires dec-ref'ing the terms in the cache
     if self.ctx.ref():
         # Check that there is still a context object
         # This might not be the case if we are using the global context
         # and the interpreter is shutting down
         for t in self.memoization.values():
             z3.Z3_dec_ref(self.ctx.ref(), t)
Exemple #3
0
    def walk_ite(self, formula, args, **kwargs):
        i = args[0]
        ni = self.walk_not(None, (i, ))
        t = args[1]
        e = args[2]

        if self._get_type(formula).is_bool_type():
            # Rewrite as (!i \/ t) & (i \/ e)
            _args, sz = self._to_ast_array((ni, t))
            or1 = z3.Z3_mk_or(self.ctx.ref(), sz, _args)
            z3.Z3_inc_ref(self.ctx.ref(), or1)
            _args, sz = self._to_ast_array((i, e))
            or2 = z3.Z3_mk_or(self.ctx.ref(), sz, _args)
            z3.Z3_inc_ref(self.ctx.ref(), or2)
            _args, sz = self._to_ast_array((or1, or2))
            z3term = z3.Z3_mk_and(self.ctx.ref(), sz, _args)
            z3.Z3_inc_ref(self.ctx.ref(), z3term)
            z3.Z3_dec_ref(self.ctx.ref(), or1)
            z3.Z3_dec_ref(self.ctx.ref(), or2)
            return z3term
        z3term = z3.Z3_mk_ite(self.ctx.ref(), i, t, e)
        z3.Z3_inc_ref(self.ctx.ref(), z3term)
        return z3term
Exemple #4
0
 def __del__(self):
     # Cleaning-up Z3Converter requires dec-ref'ing the terms in the cache
     for t in self.memoization.values():
         z3.Z3_dec_ref(self.ctx.ref(), t)