/*******************************************************************\

Module: Symbolic Execution of ANSI-C

Author: Daniel Kroening, kroening@cs.cmu.edu

\*******************************************************************/

#include <fstream>

#include <propdec/smt_dec.h>

#include "bmc.h"

/*******************************************************************\

Function: bmc_baset::smt

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

bool bmc_baset::smt()
{
  const std::string &filename=options.get_option("outfile");
  
  if(filename=="")
  {
    smt_dect smt_dec;
    return run_decision_procedure(smt_dec);
  }
  else if(filename=="-")
    return smt_conv(std::cout);
  else
  {
    std::ofstream out(filename.c_str());
    if(!out)
    {
      std::cerr << "failed to open " << filename << std::endl;
      return false;
    }
    
    return smt_conv(out);
  }
}

/*******************************************************************\

Function: bmc_baset::smt_conv

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

bool bmc_baset::smt_conv(std::ostream &out)
{
  out << "%%%\n";
  out << "%%% Generated by CBMC\n";
  out << "%%%\n\n";

  smt_convt smt_conv(out);
  smt_conv.set_message_handler(message_handler);
  
  do_unwind_module(smt_conv);  
  do_cbmc(smt_conv);

  smt_conv.dec_solve();
  
  return false;
}
