예제 #1
0
void symex_dereference_statet::get_value_set(
  const exprt &expr,
  value_setst::valuest &value_set)
{
  renaming_nst renaming_ns(goto_symex.ns, state);

  state.value_set.get_value_set(expr, value_set, renaming_ns);
  
  #if 0
  std::cout << "**************************\n";
  state.value_set.output(renaming_ns, std::cout);
  std::cout << "**************************\n";
  #endif
  
  #if 0
  std::cout << "E: " << from_expr(renaming_ns, "", expr) << std::endl;
  #endif
  
  #if 0
  std::cout << "**************************\n";
  for(value_setst::valuest::const_iterator it=value_set.begin();
      it!=value_set.end();
      it++)
    std::cout << from_expr(renaming_ns, "", *it) << std::endl;
  std::cout << "**************************\n";
  #endif
}
예제 #2
0
void equality_domaint::output_value(
  std::ostream &out,
  const valuet &value,
  const namespacet &ns) const
{
  const equ_valuet &_v=static_cast<const equ_valuet &>(value);
  equ_valuet v=_v;

  for(unsigned index=0; index<templ.size(); index++)
  {
    const var_pairt &vv=templ[index].var_pair;
    if(v.equs.same_set(vv.first, vv.second))
    {
      out << from_expr(ns, "", vv.first) << "=="
          << from_expr(ns, "", vv.second) << std::endl;
    }
  }

  for(index_sett::const_iterator it=v.disequs.begin();
      it!=v.disequs.end(); it++)
  {
    const var_pairt &vv=templ[*it].var_pair;
    out << from_expr(ns, "", vv.first) << "!="
        << from_expr(ns, "", vv.second) << std::endl;
  }
}
예제 #3
0
exprt local_SSAt::read_rhs(const exprt &expr, locationt loc) const
{
  exprt tmp1=expr;
  adjust_float_expressions(tmp1, ns);
  
  unsigned counter=0;
  replace_side_effects_rec(tmp1, loc, counter);

  #ifdef DEBUG
  std::cout << "read_rhs tmp1: " << from_expr(ns, "", tmp1) << '\n';
  #endif
  
  exprt tmp2=dereference(tmp1, loc);

  #ifdef DEBUG
  std::cout << "read_rhs tmp2: " << from_expr(ns, "", tmp2) << '\n';
  #endif
  
  exprt result=read_rhs_rec(tmp2, loc);
  
  #ifdef DEBUG
  std::cout << "read_rhs result: " << from_expr(ns, "", result) << '\n';
  #endif
  
  return result;
}
예제 #4
0
void show_properties(
  const namespacet &ns,
  const irep_idt &identifier,
  ui_message_handlert::uit ui,
  const goto_programt &goto_program)
{
  for(const auto &ins : goto_program.instructions)
  {
    if(!ins.is_assert())
      continue;

    const source_locationt &source_location=ins.source_location;

    const irep_idt &comment=source_location.get_comment();
    const irep_idt &property_class=source_location.get_property_class();
    const irep_idt description=
      (comment==""?"assertion":comment);

    irep_idt property_id=source_location.get_property_id();

    switch(ui)
    {
    case ui_message_handlert::uit::XML_UI:
      {
        // use me instead
        xmlt xml_property("property");
        xml_property.set_attribute("name", id2string(property_id));
        xml_property.set_attribute("class", id2string(property_class));

        xmlt &property_l=xml_property.new_element();
        property_l=xml(source_location);

        xml_property.new_element("description").data=id2string(description);
        xml_property.new_element("expression").data=
          from_expr(ns, identifier, ins.guard);

        std::cout << xml_property << '\n';
      }
      break;

    case ui_message_handlert::uit::JSON_UI:
      UNREACHABLE;
      break;

    case ui_message_handlert::uit::PLAIN:
      std::cout << "Property " << property_id << ":\n";

      std::cout << "  " << ins.source_location << '\n'
                << "  " << description << '\n'
                << "  " << from_expr(ns, identifier, ins.guard)
                        << '\n';

      std::cout << '\n';
      break;

    default:
      UNREACHABLE;
    }
  }
}
예제 #5
0
void predabs_domaint::output_value(
  std::ostream &out,
  const valuet &value,
  const namespacet &ns) const
{
  const templ_valuet &v=static_cast<const templ_valuet &>(value);
  for(std::size_t row=0; row<templ.size(); ++row)
  {
    const template_rowt &templ_row=templ[row];
    switch(templ_row.kind)
    {
    case LOOP:
      out << "(LOOP) [ " << from_expr(ns, "", templ_row.pre_guard) << " | ";
      out << from_expr(ns, "", templ_row.post_guard) << " | ";
      out << from_expr(ns, "", templ_row.aux_expr)
          << " ]===> " << std::endl << "       ";
      break;
    case IN: out << "(IN)   "; break;
    case OUT: case OUTL: out << "(OUT)  "; break;
    default: assert(false);
    }
    out << "( " << from_expr(ns, "", v[row]) << "==> " <<
       from_expr(ns, "", templ_row.expr) << " )" << std::endl;
  }
}
예제 #6
0
void termination_baset::show_loop_trace(
  const goto_tracet &goto_trace,
  goto_tracet::stepst::const_iterator &loop_begin)
{
  if(verbosity<9) return;
  std::string output;

  output = "--- LOOP TRACE START\n";
  for(goto_tracet::stepst::const_iterator step=loop_begin;
      step!=goto_trace.steps.end();
      step++)
  {
    switch(step->type)
    {
      case goto_trace_stept::ASSIGNMENT:
        output+=from_expr(ns, "", step->pc->code) + "\n";
        break;

      case goto_trace_stept::ASSUME:
        output+=from_expr(ns, "", step->pc->guard) + " [" +
                (step->cond_value?"":"!") + from_expr(ns, "", step->cond_expr) + "]\n";
        break;

      default:
        break;
    }
  }
  output+="--- LOOP TRACE END\n";

  debug(output);
}
예제 #7
0
파일: path_search.cpp 프로젝트: Dthird/CBMC
void path_searcht::do_show_vcc(
  statet &state,
  const namespacet &ns)
{
  // keep statistics
  number_of_VCCs++;
  
  const goto_programt::instructiont &instruction=
    *state.get_instruction();
    
  mstreamt &out=result();

  if(instruction.location.is_not_nil())
    out << instruction.location << "\n";
  
  if(instruction.location.get_comment()!="")
    out << instruction.location.get_comment() << "\n";
    
  unsigned count=1;
  
  std::vector<path_symex_step_reft> steps;
  state.history.build_history(steps);

  for(std::vector<path_symex_step_reft>::const_iterator
      s_it=steps.begin();
      s_it!=steps.end();
      s_it++)
  {      
    if((*s_it)->guard.is_not_nil())
    {
      std::string string_value=from_expr(ns, "", (*s_it)->guard);
      out << "{-" << count << "} " << string_value << "\n";
      count++;
    }

    if((*s_it)->ssa_rhs.is_not_nil())
    {
      equal_exprt equality((*s_it)->ssa_lhs, (*s_it)->ssa_rhs);
      std::string string_value=from_expr(ns, "", equality);
      out << "{-" << count << "} " << string_value << "\n";
      count++;
    }
  }

  out << "|--------------------------" << "\n";
  
  exprt assertion=state.read(instruction.guard);

  out << "{" << 1 << "} "
      << from_expr(ns, "", assertion) << "\n";

  if(!assertion.is_true())
    number_of_VCCs_after_simplification++;
  
  out << eom;
}
예제 #8
0
std::set<symbol_exprt> concurrency_aware_abstractort::targets_of_lvalue(const exprt& lvalue, goto_programt::const_targett program_location)
{

	std::set<symbol_exprt> result;
	if(lvalue.id() == ID_index)
	{
		exprt array_name = lvalue.op0();
		if(array_name.id() == ID_symbol)
		{
			result.insert(to_symbol_expr(array_name));
		} else {
			return targets_of_lvalue(array_name, program_location);
		}
	} else if(lvalue.id() == ID_member) {
		assert(lvalue.operands().size() == 1);
		return targets_of_lvalue(lvalue.op0(), program_location);
	} else if(lvalue.id() == ID_symbol) {
		result.insert(to_symbol_expr(lvalue));
	} else if(lvalue.id() == ID_dereference) {
		// We would like to add anything the pointer can point to,
		// but not the pointer itself

		value_setst::valuest value_set;
		pointer_info.get_values(program_location, lvalue.op0(), value_set);
		for(value_setst::valuest::iterator it = value_set.begin(); it != value_set.end(); it++)
		{
			if(it->id() != ID_object_descriptor)
			{
				// TODO: We may need to deal with this situation more carefully
				continue;
			}
			object_descriptor_exprt& object_descriptor = to_object_descriptor_expr(*it);
			if(object_descriptor.offset() != from_integer(0, index_type()))
			{
				std::cout << "Pointer " << from_expr(lvalue.op0()) << " can point to " << from_expr(*it) << " at line " <<
						program_location->location.get_line() << ", we cannot handle this" << std::endl;
				  exit(1);
			  }

			  if(object_descriptor.object().id() != ID_symbol)
			  {
				  std::cout << "Pointer " << from_expr(lvalue.op0()) << " can point to " << from_expr(*it) << " at line " <<
					  program_location->location.get_line() << ", we cannot handle this" << std::endl;
				  exit(1);
			  }

			  result.insert(to_symbol_expr(object_descriptor.object()));
		}

	} else {
		std::cout << "Cannot currently handle lvalue: " << from_expr(lvalue) << std::endl;
		assert(false);
	}
	return result;
}
예제 #9
0
void symex_target_equationt::SSA_stept::output(
  const namespacet &ns,
  std::ostream &out) const
{
  if(source.is_set)
  {
    out << "Thread " << source.thread_nr;

    if(source.pc->location.is_not_nil())
      out << " " << source.pc->location << std::endl;
    else
      out << std::endl;
  }

  switch(type)
  {
  case goto_trace_stept::ASSERT: out << "ASSERT" << std::endl; break;
  case goto_trace_stept::ASSUME: out << "ASSUME" << std::endl; break;
  case goto_trace_stept::LOCATION: out << "LOCATION" << std::endl; break;
  case goto_trace_stept::INPUT: out << "INPUT" << std::endl; break;
  case goto_trace_stept::OUTPUT: out << "OUTPUT" << std::endl; break;

  case goto_trace_stept::DECL:
    out << "DECL" << std::endl;
    out << from_expr(ns, "", ssa_lhs) << std::endl;
    break;

  case goto_trace_stept::ASSIGNMENT:
    out << "ASSIGNMENT (";
    switch(assignment_type)
    {
    case HIDDEN: out << "HIDDEN"; break;
    case STATE: out << "STATE"; break;
    default:;
    }

    out << ")" << std::endl;
    break;
    
  case goto_trace_stept::DEAD: out << "DEAD" << std::endl; break;
  case goto_trace_stept::FUNCTION_CALL: out << "FUNCTION_CALL" << std::endl; break;
  case goto_trace_stept::FUNCTION_RETURN: out << "FUNCTION_RETURN" << std::endl; break;

  default: assert(false);
  }

  if(is_assert() || is_assume() || is_assignment())
    out << from_expr(ns, "", cond_expr) << std::endl;
  
  if(is_assert())
    out << comment << std::endl;

  out << "Guard: " << from_expr(ns, "", guard_expr) << std::endl;
}
예제 #10
0
void path_searcht::do_show_vcc(statet &state)
{
  // keep statistics
  number_of_VCCs++;

  const goto_programt::instructiont &instruction=
    *state.get_instruction();

  mstreamt &out=result();

  if(instruction.source_location.is_not_nil())
    out << instruction.source_location << '\n';

  if(instruction.source_location.get_comment()!="")
    out << instruction.source_location.get_comment() << '\n';

  unsigned count=1;

  std::vector<path_symex_step_reft> steps;
  state.history.build_history(steps);

  for(const auto &step_ref : steps)
  {
    if(step_ref->guard.is_not_nil())
    {
      std::string string_value=from_expr(ns, "", step_ref->guard);
      out << "{-" << count << "} " << string_value << '\n';
      count++;
    }

    if(step_ref->ssa_rhs.is_not_nil())
    {
      equal_exprt equality(step_ref->ssa_lhs, step_ref->ssa_rhs);
      std::string string_value=from_expr(ns, "", equality);
      out << "{-" << count << "} " << string_value << '\n';
      count++;
    }
  }

  out << "|--------------------------" << '\n';

  exprt assertion=state.read(instruction.guard);

  out << "{" << 1 << "} "
      << from_expr(ns, "", assertion) << '\n';

  if(!assertion.is_true())
    number_of_VCCs_after_simplification++;

  out << eom;
}
예제 #11
0
파일: abstractor_wp.cpp 프로젝트: olivo/BP
void abstractor_wpt::pred_abstract_block(
  goto_programt::const_targett target,
  const predicatest &predicates,
  abstract_transition_relationt &
  abstract_transition_relation)
{
  std::vector<exprt> predicates_wp;

  std::list<exprt> constraints;
  
  build_equation(
    concrete_model.ns,
    predicates,
    target,
    constraints,
    predicates_wp);

  #if 0
  std::cout << target->location << std::endl;
  std::cout << equation;
  #endif

  // find unchanged predicates
  // find predicates with value
  
  for(unsigned i=0; i<predicates.size(); i++)
  {
    if(predicates_wp[i]==predicates[i])
    {
      abstract_transition_relation.values.erase(i);
      #if 0
      std::cout << "UNCHANGED: P" << i << std::endl;
      #endif
    }
    else
    {
      #if 0
      std::cout << "DIFFERENT: P" << i << std::endl;
      std::cout << "WP: " << from_expr(concrete_model.ns, "", predicates_wp[i]) << std::endl;
      std::cout << "P:  " << from_expr(concrete_model.ns, "", predicates[i]) << std::endl;
      #endif
      
      abstract_transition_relation.values[i]=
        get_value(i, predicates, predicates_wp[i], concrete_model.ns, target);
        
      // if it changes, it's output
      abstract_transition_relation.to_predicates.insert(i);
    }
  }
}
예제 #12
0
파일: ranking_sat.cpp 프로젝트: olivo/BP
void ranking_synthesis_satt::show_coefficients(c_valuest &c_values)
{
  if(verbosity<9) return;
  
  std::string t("Coefficients: ");
  for(c_valuest::const_iterator it=c_values.begin();
      it!=c_values.end();
      it++)
  {
    if(it!=c_values.begin()) t+=", ";
    t+=from_expr(ns, "", it->first) +"=" +
      from_expr(ns, "", from_integer(it->second, it->first.type()));
  }
  
  debug(t);
}
예제 #13
0
void show_properties_json(
  json_arrayt &json_properties,
  const namespacet &ns,
  const irep_idt &identifier,
  const goto_programt &goto_program)
{
  for(const auto &ins : goto_program.instructions)
  {
    if(!ins.is_assert())
      continue;

    const source_locationt &source_location=ins.source_location;

    const irep_idt &comment=source_location.get_comment();
    // const irep_idt &function=location.get_function();
    const irep_idt &property_class=source_location.get_property_class();
    const irep_idt description=
      (comment==""?"assertion":comment);

    irep_idt property_id=source_location.get_property_id();

    json_objectt &json_property=
      json_properties.push_back(jsont()).make_object();
    json_property["name"]=json_stringt(id2string(property_id));
    json_property["class"]=json_stringt(id2string(property_class));
    json_property["sourceLocation"]=json(source_location);
    json_property["description"]=json_stringt(id2string(description));
    json_property["expression"]=
      json_stringt(from_expr(ns, identifier, ins.guard));
  }
}
예제 #14
0
bool ranking_synthesis_seneschalt::write_constraints(
  std::ostream &f,
  replace_mapt &rmap,
  exprt e)
{
  expr2seneschalt expr2seneschal(ns);
  f << " \\transition {" << std::endl;

  bool first=true;
  forall_operands(it, e)
  {
    exprt t = *it;
    replace_expr(rmap, t);

    {
      if(!first) f << " & " << std::endl;

      try {
        f << "  " << expr2seneschal(t, false, true);
      }
      catch (const expr2seneschalt::UnhandledException &ex)
      {
        status("Seneschal unsuitable: " + ex.reason.id_string());
        status("In: " + from_expr(ns, "", t));
        return false;
      }

      first=false;
    }
  }
예제 #15
0
파일: predicate.cpp 프로젝트: AnnaTrost/2ls
void predicatet::output(std::ostream &out) const
{
  // print equalities in pretty way
  
  out << "State vars:";
  for(unsigned v=0; v<state_vars.size(); v++)
    out << " " << from_expr(state_vars[v]);
  out << "\n";
  
  std::map<unsigned, unsigned> eq_count;
  
  for(unsigned v=0; v<state_vars.size(); v++)
    eq_count[uuf.find(v)]++;

  for(std::map<unsigned, unsigned>::const_iterator
      e_it=eq_count.begin(); e_it!=eq_count.end(); e_it++)
  {
    if(e_it->second>=2)
    {
      for(unsigned v=0; v<state_vars.size(); v++)
        if(e_it->first==uuf.find(v))
          out << "Equal: " << from_expr(state_vars[v]) << "\n";
      out << "\n";
    }
  }
  
  // print intervals
  #if 0
  for(integer_intervalst::const_iterator
      i_it=integer_intervals.begin(); i_it!=integer_intervals.end(); i_it++)
  {
    if(i_it->lower_is_set || i_it->upper_is_set)
    {
      if(i_it->lower_is_set)
        out << from_expr(i_it->lower) << " <= ";
        
      out << from_expr(vars[i_it-intervals.begin()]);
        
      if(i_it->upper_is_set)
        out << " <= " << from_expr(i_it->lower);
        
      out << "\n";
    }
  }
  #endif
}
예제 #16
0
/*******************************************************************\

Function: acdl_conflict_grapht::print_output

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/
void acdl_conflict_grapht::dump_dec_trail(const local_SSAt &SSA)
{
  std::cout << "Dump the decision trail" << std::endl;
  for(unsigned i=0;i<dec_trail.size();i++) {
    std::cout << "decision trail element:" << from_expr(SSA.ns, "", dec_trail[i]) << std::endl;
    // std::cout << "Val trail:" << from_expr(SSA.ns, "", numbering[val_trail[i]]) << std::endl;
  }
}
예제 #17
0
std::string bv_refinementt::approximationt::as_string() const
{
  #if 0
  return from_expr(expr);
  #else
  return i2string(id_nr)+"/"+id2string(expr.id());
  #endif
}
예제 #18
0
std::set<symbol_exprt> locations_of_expression(const predicatet& phi, const goto_programt::const_targett program_location, value_set_analysist& pointer_info, const namespacet& ns)
{
#ifdef DEBUG
	std::cout << "Computing locations of " << from_expr(ns, "", phi) << std::endl;
#endif
	return locations_of_expression_rec(phi, program_location, pointer_info, ns);

}
예제 #19
0
void equality_domaint::output_domain(
  std::ostream &out,
  const namespacet &ns) const
{
  for(unsigned index=0; index<templ.size(); index++)
  {
    const template_rowt &templ_row=templ[index];
    switch(templ_row.kind)
    {
    case LOOP:
      out << "(LOOP) [ " << from_expr(ns, "", templ_row.pre_guard) << " | ";
      out << from_expr(ns, "", templ_row.post_guard) << " | ";
      out << from_expr(ns, "", templ_row.aux_expr)
          << " ]===> " << std::endl << "      ";
      break;
    case IN:
      out << "(IN)   ";
      out << from_expr(ns, "", templ_row.pre_guard) << "===> "
          << std::endl << "      ";
      break;
    case OUT: case OUTL:
      out << "(OUT)  ";
      out << from_expr(ns, "", templ_row.post_guard) << "===> "
          << std::endl << "      ";
      break;
    default: assert(false);
    }
    const var_pairt &vv=templ_row.var_pair;
    out << from_expr(ns, "", vv.first) << "=!= "
        << from_expr(ns, "", vv.second) << std::endl;
  }
}
예제 #20
0
void path_symex_stept::output(std::ostream &out) const
{
  out << "PCs:";

/*
    for(pc_vectort::const_iterator p_it=s_it->pc_vector.begin();
        p_it!=pc_vector.end();
        p_it++)
      out << " " << *p_it;
 */     
  out << "\n";
  
  out << "Guard: " << from_expr(guard) << "\n";
  out << "Full LHS: " << from_expr(full_lhs) << "\n";
  out << "SSA LHS: " << from_expr(ssa_lhs) << "\n";
  out << "SSA RHS: " << from_expr(ssa_rhs) << "\n";
  out << "\n";
}
예제 #21
0
void acdl_analyze_conflict_baset::get_conflict_clause
(const local_SSAt &SSA, acdl_conflict_grapht &graph, acdl_domaint::valuet &conf_clause)
{
  // PROPOSITIONAL proof
  if(last_proof==PROPOSITIONAL) {
    assert(conflicting_clause!=-1);
    conf_clause=learned_clauses[conflicting_clause];
#ifdef DEBUG
    std::cout << "Conflict is purely Propositional" << std::endl;
#endif
  }
  // conflict is caused by Abstract Interpretation proof
  else if(last_proof==ABSINT) {
    acdl_domaint::valuet reason;
    get_ai_reason(SSA, graph, reason);
    // print the reason
#ifdef DEBUG
    std::cout << "Reason: " << from_expr(SSA.ns, "", disjunction(reason)) << std::endl;
#endif

    for(acdl_domaint::valuet::iterator it=reason.begin();
        it!=reason.end(); it++)
    {
      negate(*it, conf_clause);
    }
#ifdef DEBUG
    std::cout << "Conflict is purely from Abstract Interpretation Proof" << std::endl;
#endif
  }

#ifdef DEBUG
  std::cout << "Conflict at decision level is " << graph.current_level  <<std::endl;
#endif
  if(conf_clause.size()==0)
    backtrack_level=-1;
  else
    find_uip(SSA, graph, conf_clause, graph.current_level);

  // print the conflict clause
#ifdef DEBUG
  std::cout << "learnt clause: " << from_expr(SSA.ns, "", disjunction(conf_clause)) << std::endl;
#endif
}
예제 #22
0
std::string inv_object_storet::build_string(const exprt &expr) const
{
  // we ignore some casts
  if(expr.id()==ID_typecast)
  {
    assert(expr.operands().size()==1);

    if(expr.type().id()==ID_signedbv ||
       expr.type().id()==ID_unsignedbv)
    {
      if(expr.op0().type().id()==ID_signedbv ||
         expr.op0().type().id()==ID_unsignedbv)
      {
        if(to_bitvector_type(expr.type()).get_width()>=
           to_bitvector_type(expr.op0().type()).get_width())
          return build_string(expr.op0());
      }
      else if(expr.op0().type().id()==ID_bool)
      {
        return build_string(expr.op0());
      }
    }
  }

  // we always track constants, but make sure they are uniquely
  // represented
  if(expr.is_constant())
  {
    // NULL?
    if(expr.type().id()==ID_pointer)
      if(expr.get(ID_value)==ID_NULL)
        return "0";

    mp_integer i;

    if(!to_integer(expr, i))
      return integer2string(i);
  }

  // we also like "address_of" and "reference_to"
  // if the object is constant
  if(is_constant_address(expr))
    return from_expr(ns, "", expr);

  if(expr.id()==ID_member)
  {
    assert(expr.operands().size()==1);
    return build_string(expr.op0())+"."+expr.get_string(ID_component_name);
  }

  if(expr.id()==ID_symbol)
    return expr.get_string(ID_identifier);

  return "";
}
예제 #23
0
void constant_propagator_domaint::assign_rec(
  valuest &values,
  const exprt &lhs, const exprt &rhs,
  const namespacet &ns)
{
  const typet & lhs_type = ns.follow(lhs.type());
  const typet & rhs_type = ns.follow(rhs.type());

#ifdef DEBUG
  std::cout << "assign: " << from_expr(ns, "", lhs)
            << " := " << from_type(ns, "", rhs_type) << '\n';
#endif

  if(lhs.id()==ID_symbol && rhs.id()==ID_if)
  {
	exprt cond=rhs.op0();
	assert(cond.operands().size()==2);
	if(values.is_constant(cond.op0())
			&& values.is_constant(cond.op1()))
	{
      if(cond.op0().id()==ID_index)
      {
    	exprt index=cond.op0();
        exprt new_expr=concatenate_array_id(index.op0(), index.op1(), index.type());
        values.replace_const(new_expr);
        cond.op0()=new_expr;
        cond = simplify_expr(cond,ns);
      }
      else
        assert(0);

      assign(values, to_symbol_expr(lhs), cond, ns);
	}
  }
  else if(lhs.id()==ID_symbol && rhs_type.id()!=ID_array
                         && rhs_type.id()!=ID_struct
                         && rhs_type.id()!=ID_union)
  {
    if(values.is_constant(rhs))
      assign(values, to_symbol_expr(lhs), rhs, ns);
    else
      values.set_to_top(to_symbol_expr(lhs));
  }
  else if(lhs.id()==ID_symbol && lhs_type.id()==ID_array
		                       && rhs_type.id()==ID_array)
  {
	exprt new_expr;
	mp_integer idx=0;
    forall_operands(it, rhs)
	{
  	  new_expr=concatenate_array_id(lhs, idx, it->type());
  	  assign(values, to_symbol_expr(new_expr), *it, ns);
  	  idx = idx +1;
	}
예제 #24
0
void invariant_sett::strengthen_rec(const exprt &expr)
{
  if(expr.type().id()!=ID_bool)
    throw "non-Boolean argument to strengthen()";

  #if 0
  std::cout << "S: " << from_expr(*ns, "", expr) << '\n';
  #endif

  if(is_false)
  {
    // we can't get any stronger
    return;
  }

  if(expr.is_true())
  {
    // do nothing, it's useless
  }
  else if(expr.is_false())
  {
    // wow, that's strong
    make_false();
  }
  else if(expr.id()==ID_not)
  {
    // give up, we expect NNF
  }
  else if(expr.id()==ID_and)
  {
    forall_operands(it, expr)
      strengthen_rec(*it);
  }
  else if(expr.id()==ID_le ||
          expr.id()==ID_lt)
  {
    assert(expr.operands().size()==2);

    // special rule: x <= (a & b)
    // implies:      x<=a && x<=b

    if(expr.op1().id()==ID_bitand)
    {
      const exprt &bitand_op=expr.op1();

      forall_operands(it, bitand_op)
      {
        exprt tmp(expr);
        tmp.op1()=*it;
        strengthen_rec(tmp);
      }

      return;
    }
예제 #25
0
/*******************************************************************\

Function: abstr_dpll_searcht::chronological_backtrack

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/
bool acdl_analyze_conflict_baset::chronological_backtrack(const local_SSAt &SSA, acdl_conflict_grapht &graph)
{
#ifdef DEBUG
  std::cout << "inside backtrack" << std::endl;
#endif
  if(graph.current_level==0) {
    backtrack_level=-1; // no further backtrack possible
    return false;
  }

  unsigned first_idx=graph.control_trail.back();

#ifdef DEBUG
  std::cout << "val_trail size is: " << graph.val_trail.size() << "control_trail.back is: "  << first_idx << std::endl;
#endif
  assert(graph.val_trail.size() >= first_idx+1);
  exprt dec_exp=graph.prop_trail[first_idx];

  // check val_trail and prop_trail are of equal size
  assert(graph.prop_trail.size()==graph.val_trail.size());

#ifdef DEBUG
  std::cout << "The decision to be flipped is " << from_expr(SSA.ns, "", dec_exp);
  std::cout << "The trail before  backtracking is" << std::endl;
#endif
  graph.dump_trail(SSA);

  // backtrack one level
  cancel_once(SSA, graph);

  // flip the expression
  exprt exp=flip(dec_exp);

  graph.assign_to_trail(exp);

#ifdef DEBUG
  std::cout << "The trail after backtracking and assigning negation of previous decision is" << std::endl;
#endif
  graph.dump_trail(SSA);

  // check val_trail and prop_trail are of
  // equal size after backtracking
  assert(graph.prop_trail.size()==graph.val_trail.size());

  // update the backtrack level
  backtrack_level=graph.current_level;

  just_backtracked=true;

  graph.check_consistency();

  return true;
}
예제 #26
0
파일: ranking_sat.cpp 프로젝트: olivo/BP
bool ranking_synthesis_satt::generate_functions(void)
{
  exprt templ = instantiate();

  if(body.variable_map.size()==0 || templ.is_false())
    return false;

  // some coefficient values
  c_valuest c_values;

  debug("Template:" + from_expr(ns, "", templ));

  satcheckt::resultt result=satcheckt::P_SATISFIABLE;

  while(result==satcheckt::P_SATISFIABLE)
  {
    if(c_values.size()==0)
      initialize_coefficients(c_values);
    else
    {
      if(increase_coefficients(c_values))
        break;
    }

    result=check_for_counterexample(templ, c_values,
                                    conversion_time, solver_time);
  }

  if(result==satcheckt::P_ERROR)
    throw ("Solver error.");
  else if(result==satcheckt::P_UNSATISFIABLE) // no counter-example
  {
    debug("Found ranking functions");

    // put the coefficient values in the rank relation
    replace_mapt replace_map;

    for(c_valuest::const_iterator it=c_values.begin();
        it!=c_values.end();
        it++)
    {
      replace_map[it->first] = from_integer(it->second, it->first.type());
    }

    replace_expr(replace_map, rank_relation);
    simplify(rank_relation, ns);

    return true;
  }
  else
    return false;
}
예제 #27
0
파일: predicates.cpp 프로젝트: olivo/BP
std::ostream& operator<< (std::ostream& out,
                          const predicatest &predicates)
{
  for(unsigned i=0; i<predicates.size(); i++)
  {
    contextt context;
    namespacet ns(context);
    out << "b" << i << " <=> "
        << from_expr(ns, "", predicates[i]) << std::endl;
  }

  return out;
}
예제 #28
0
void summarizer_fwt::compute_summary_rec(const function_namet &function_name,
				      const exprt &precondition,
				      bool context_sensitive)
{
  local_SSAt &SSA = ssa_db.get(function_name); //TODO: make const
  
  // recursively compute summaries for function calls
  inline_summaries(function_name,SSA,precondition,context_sensitive); 

  status() << "Analyzing function "  << function_name << eom;

#if 0
  {
    std::ostringstream out;
    out << "Function body for " << function_name << 
      " to be analyzed: " << std::endl;
    for(local_SSAt::nodest::iterator n = SSA.nodes.begin(); 
        n!=SSA.nodes.end(); n++)
    {
      if(!n->empty()) n->output(out,SSA.ns);
    }
    out << "(enable) " << from_expr(SSA.ns, "", SSA.get_enabling_exprs()) 
	<< "\n";
    debug() << out.str() << eom;
  }
#endif

  // create summary
  summaryt summary;
  summary.params = SSA.params;
  summary.globals_in = SSA.globals_in;
  summary.globals_out = SSA.globals_out;
  summary.fw_precondition = precondition;

  if(!options.get_bool_option("havoc"))
  {
    do_summary(function_name,SSA,summary,true_exprt(),context_sensitive);
  }

  if(!options.get_bool_option("competition-mode"))
  {
    std::ostringstream out;
    out << std::endl << "Summary for function " << function_name << std::endl;
    summary.output(out,SSA.ns);   
    status() << out.str() << eom;
  }

  // store summary in db
  summary_db.put(function_name,summary);
}
예제 #29
0
파일: ranking_sat.cpp 프로젝트: olivo/BP
void ranking_synthesis_satt::show_counterexample(boolbvt &converter)
{  
  if(verbosity<9) return;
  std::string output=" ... NO: ";
  
  for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin();
      it!=body.variable_map.end();
      it++)
  {
    if(used_variables.find(it->first)==used_variables.end())
      continue;
    
    if(it!=body.variable_map.begin()) output += ", ";

    exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type);
    exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type);
    
    exprt post=converter.get(postsym);
    
    if(post.id()!="nil")
    {
     output += from_expr(ns, "", postsym) + "=" + from_expr(ns, "", post) + " (";
    }
    else
     output += "? (";

    exprt pre=converter.get(presym);
    if(pre.id()!="nil")
      output += from_expr(ns, "", pre);
    else
      output += "?";

    output += ")";
  }

  debug(output);
}
예제 #30
0
exprt dereference(
 const exprt &src,
 const ssa_value_domaint &ssa_value_domain, 
 const std::string &nondet_prefix,
 const namespacet &ns)
{
  #ifdef DEBUG
  std::cout << "dereference src: " << from_expr(ns, "", src) << '\n';
  #endif

  exprt tmp1=dereference_rec(src, ssa_value_domain, nondet_prefix, ns);

  #ifdef DEBUG
  std::cout << "dereference tmp1: " << from_expr(ns, "", tmp1) << '\n';
  #endif

  exprt tmp2=simplify_expr(tmp1, ns);

  #ifdef DEBUG
  std::cout << "dereference tmp2: " << from_expr(ns, "", tmp2) << '\n';
  #endif

  return tmp2;
}