def investigate_funcall_pair(rep, m, l_n_vc, r_n_vc, verbose=False, verbose_imp=False, simplify=True): l_nm = "%s @ %s" % (rep.p.nodes[l_n_vc[0]].fname, rep.node_count_name(l_n_vc)) r_nm = "%s @ %s" % (rep.p.nodes[r_n_vc[0]].fname, rep.node_count_name(r_n_vc)) print "Attempt match %s -> %s" % (l_nm, r_nm) imp = rep.get_func_assert(l_n_vc, r_n_vc) if verbose_imp: imp2 = logic.weaken_assert(imp) imp2 = solver.smt_expr(imp2, {}, rep.solv) if simplify: imp2 = simplify_sexp(imp2, rep, m) print imp2 assert imp.is_op("Implies"), imp [pred, concl] = imp.vals pred = solver.smt_expr(pred, {}, rep.solv) pred = solver.parse_s_expression(pred) bits = solver.split_hyp_sexpr(pred, []) xs = [eval_model_bool(m, v) for v in bits] print " %s" % xs for (v, bit) in zip(xs, bits): if v != True or verbose: print " %s: %s" % (v, bit) if bit[0] == "word32-eq": vs = [model_sx_word(m, x) for x in bit[1:]] print " (%s = %s)" % tuple(vs)
def investigate_funcall_pair(rep, m, l_n_vc, r_n_vc, verbose=False, verbose_imp=False, simplify=True): l_nm = "%s @ %s" % (rep.p.nodes[l_n_vc[0]].fname, rep.node_count_name(l_n_vc)) r_nm = "%s @ %s" % (rep.p.nodes[r_n_vc[0]].fname, rep.node_count_name(r_n_vc)) print 'Attempt match %s -> %s' % (l_nm, r_nm) imp = rep.get_func_assert(l_n_vc, r_n_vc) imp = logic.weaken_assert(imp) if verbose_imp: imp2 = solver.smt_expr(imp, {}, rep.solv) if simplify: imp2 = simplify_sexp(imp2, rep, m) print imp2 assert imp.is_op('Implies'), imp [pred, concl] = imp.vals pred = solver.smt_expr(pred, {}, rep.solv) pred = solver.parse_s_expression(pred) bits = solver.split_hyp_sexpr(pred, []) xs = [eval_model_bool(m, v) for v in bits] print ' %s' % xs for (v, bit) in zip(xs, bits): if v != True or verbose: print ' %s: %s' % (v, bit) if bit[0] == 'word32-eq': vs = [model_sx_word(m, x) for x in bit[1:]] print ' (%s = %s)' % tuple(vs)
def investigate_cond(rep, m, cond, simplify=True, rec=True): cond_def = rep.solv.defs[cond] while rec and type(cond_def) == str and cond_def in rep.solv.defs: cond_def = rep.solv.defs[cond_def] bits = solver.split_hyp_sexpr(cond_def, []) for bit in bits: if bit == "true": continue valid = eval_model_bool(m, bit) if simplify: # looks a bit strange to do this now but some pointer # lookups have to be done with unmodified s-exprs bit = simplify_sexp(bit, rep, m, flatten=False) print " %s: %s" % (valid, solver.flat_s_expression(bit))
def func_assert_premise_strength(rep, m, l_n_vc, r_n_vc): imp = rep.get_func_assert(l_n_vc, r_n_vc) assert imp.is_op('Implies'), imp [pred, concl] = imp.vals pred = solver.smt_expr(pred, {}, rep.solv) pred = solver.parse_s_expression(pred) bits = solver.split_hyp_sexpr(pred, []) assert bits, bits scores = [] for bit in bits: try: res = eval_model_bool(m, bit) if res: scores.append(1.0) else: scores.append(0.0) except solver.EnvMiss, e: scores.append(0.5) except AssertionError, e: scores.append(0.5)
def investigate_cond(rep, m, cond, simplify=True, rec=True): cond_def = rep.solv.defs[cond] while rec and type(cond_def) == str and cond_def in rep.solv.defs: cond_def = rep.solv.defs[cond_def] def do_bit(bit): if bit == 'true': return True valid = eval_model_bool(m, bit) if simplify: # looks a bit strange to do this now but some pointer # lookups have to be done with unmodified s-exprs bit = simplify_sexp(bit, rep, m, flatten=False) print ' %s: %s' % (valid, solver.flat_s_expression(bit)) return valid while cond_def[0] == '=>': valid = do_bit(cond_def[1]) if not valid: break cond_def = cond_def[2] bits = solver.split_hyp_sexpr(cond_def, []) for bit in bits: do_bit(bit)