Exemple #1
0
void show_ssa(
  const goto_functionst::goto_functiont &goto_function,
  const namespacet &ns,
  std::ostream &out)
{
  local_SSAt local_SSA(goto_function, ns);
  local_SSA.output(out);
}
Exemple #2
0
void show_fixed_point(
  const goto_functionst::goto_functiont &goto_function,
  const namespacet &ns,
  std::ostream &out)
{
  local_SSAt local_SSA(goto_function, ns);
  ssa_fixed_pointt ssa_fixed_point(local_SSA, ns);
  ssa_fixed_point.output(out);
}
Exemple #3
0
void horn_encodingt::translate(
  const goto_functionst::function_mapt::const_iterator f_it)
{
  if(f_it->second.body.empty())
    return;

  out << "\n"
         ";\n"
         "; Function " << f_it->first << "\n"
         ";\n";

  // compute SSA
  ssa_heap_analysist heap_analysis(ns);
  local_SSAt local_SSA(f_it->second, ns, heap_analysis, "");

  const goto_programt &body=f_it->second.body;

  // first generate the predicates for all locations
  for(goto_programt::instructionst::const_iterator
      loc=body.instructions.begin();
      loc!=body.instructions.end();
      loc++)
  {
    out << "(declare-fun h-" << f_it->first << "-"
        << loc->location_number << " (";

    for(ssa_objectst::objectst::const_iterator
        o_it=local_SSA.ssa_objects.objects.begin();
        o_it!=local_SSA.ssa_objects.objects.end();
        o_it++)
    {
      if(o_it!=local_SSA.ssa_objects.objects.begin())
        out << ' ';
      out << '(';
      smt2_conv.convert_expr(o_it->symbol_expr());
      out << ' ';
      smt2_conv.convert_type(o_it->type());
      out << ')';
    }

    out << ") Bool)\n";
  }

  out << '\n';

  // now encode transitions
  for(goto_programt::instructionst::const_iterator
      loc=body.instructions.begin();
      loc!=body.instructions.end();
      loc++)
  {
#if 0
    const local_SSAt::nodet &node=*local_SSA.find_node(loc);
#endif
    out << "; PC " << loc->location_number
        << " " << loc->source_location << '\n';

    out << "(assert (forall (";

    for(ssa_objectst::objectst::const_iterator
        o_it=local_SSA.ssa_objects.objects.begin();
        o_it!=local_SSA.ssa_objects.objects.end();
        o_it++)
    {
      if(o_it!=local_SSA.ssa_objects.objects.begin())
        out << ' ';
      out << '(';
      smt2_conv.convert_expr(o_it->symbol_expr());
      out << ' ';
      smt2_conv.convert_type(o_it->type());
      out << ')';
    }

    out << ")\n";
    out << "  (=> (h-" << f_it->first << '-'
        << loc->location_number;

    for(ssa_objectst::objectst::const_iterator
        o_it=local_SSA.ssa_objects.objects.begin();
        o_it!=local_SSA.ssa_objects.objects.end();
        o_it++)
    {
      out << ' ';
      smt2_conv.convert_expr(o_it->symbol_expr());
    }

    out << ")\n      ";

    if(loc->is_goto())
    {
      if(loc->guard.is_true())
      {
        out << "(h-" << f_it->first << '-'
            << loc->get_target()->location_number;

        for(ssa_objectst::objectst::const_iterator
            o_it=local_SSA.ssa_objects.objects.begin();
            o_it!=local_SSA.ssa_objects.objects.end();
            o_it++)
        {
          out << ' ';
          smt2_conv.convert_expr(o_it->symbol_expr());
        }

        out << ')';
      }

      if(!loc->guard.is_true())
      {
        goto_programt::instructionst::const_iterator next=loc;
        next++;

        out << "(h-" << f_it->first << '-'
            << loc->get_target()->location_number;

        for(ssa_objectst::objectst::const_iterator
            o_it=local_SSA.ssa_objects.objects.begin();
            o_it!=local_SSA.ssa_objects.objects.end();
            o_it++)
        {
          out << ' ';
          smt2_conv.convert_expr(o_it->symbol_expr());
        }

        out << ')';
      }
    }
    else if(loc->is_function_call())
    {
    }
    else
    {
      #if 0
      for(local_SSAt::nodet::constraintst::const_iterator
          it=node.constraints.begin();
          it!=node.constraints.end();
          it++)
      {
        smt2_conv.set_to(*it, true);
      }
      #endif

      #if 0
      for(local_SSAt::nodet::equalitiest::const_iterator
          it=node.equalities.begin();
          it!=node.equalities.end();
          it++)
      {
        smt2_conv.set_to(*it, true);
      }
      #endif
    }

    out << ")))"; // =>, forall, assert

    out << '\n';
  }
}