示例#1
0
文件: parseoptions.cpp 项目: olivo/BP
bool tan_parseoptionst::from_file(const std::string &filename)
{  
  std::ifstream infile(filename.c_str());

  if(!infile)
  {
    error(std::string("Error opening file `")+filename+"'.");
    return true;
  }  

  status(std::string("Loading `")+filename+"' ...");
  if(read_goto_binary(filename, context, goto_functions, get_message_handler()))
  {
    error(std::string("Error reading file `")+filename+"'.");
    return true;
  }
  
  if(cmdline.isset("show-program"))
  {
    goto_functions.output(namespacet(context), std::cout);
    return true;    
  }
  
  return false;
}
示例#2
0
void goto_fence_inserter_parse_optionst::get_goto_program(
  goto_functionst &goto_functions)
{
  status() << "Reading GOTO program from " << cmdline.args[0] << eom;

  if(read_goto_binary(cmdline.args[0],
    symbol_table, goto_functions, get_message_handler()))
    throw 0;

  config.set_from_symbol_table(symbol_table);
}
示例#3
0
文件: show.cpp 项目: AnnaTrost/2ls
void show_defs(
  const indext &index,
  const optionst &options,
  std::ostream &out,
  message_handlert &message_handler)
{
  for(indext::file_to_functiont::const_iterator
      file_it=index.file_to_function.begin();
      file_it!=index.file_to_function.end();
      file_it++)
  {
    // read the file
    goto_modelt model;
    read_goto_binary(index.full_path(file_it->first), model, message_handler);
    
    // add the properties
    goto_check(options, model);
    model.goto_functions.update();
    label_properties(model.goto_functions);

    const namespacet ns(model.symbol_table);
    const std::set<irep_idt> &functions=file_it->second;

    // now do all functions from model
    for(std::set<irep_idt>::const_iterator
        fkt_it=functions.begin();
        fkt_it!=functions.end();
        fkt_it++)
    {
      const irep_idt &id=*fkt_it;
      
      const goto_functionst::function_mapt::const_iterator m_it=
        model.goto_functions.function_map.find(id);
        
      assert(m_it!=model.goto_functions.function_map.end());
      
      const goto_functionst::goto_functiont *index_fkt=
        &m_it->second;
    
      out << ">>>> Function " << id << " in " << file_it->first
          << std::endl;
          
      show_defs(*index_fkt, ns, out);
      
      out << std::endl;
    }
  }
  
}
示例#4
0
文件: show.cpp 项目: AnnaTrost/2ls
void show_properties(
  const indext &index,
  const optionst &options,
  std::ostream &out,
  message_handlert &message_handler)
{
  for(indext::file_to_functiont::const_iterator
      file_it=index.file_to_function.begin();
      file_it!=index.file_to_function.end();
      file_it++)
  {
    // read the file
    goto_modelt model;
    read_goto_binary(index.full_path(file_it->first), model, message_handler);
    
    // add the properties
    goto_check(options, model);
    model.goto_functions.update();
    label_properties(model.goto_functions);
    
    show_properties(model, ui_message_handlert::PLAIN);
  }
  
}
示例#5
0
bool symex_parseoptionst::get_goto_program(
  const optionst &options,
  goto_functionst &goto_functions)
{
  if(cmdline.args.empty())
  {
    error() << "Please provide a program to verify" << eom;
    return true;
  }

  try
  {
    if(cmdline.args.size()==1 &&
       is_goto_binary(cmdline.args[0]))
    {
      status() << "Reading GOTO program from file" << eom;

      if(read_goto_binary(cmdline.args[0],
           symbol_table, goto_functions, get_message_handler()))
        return true;

      config.ansi_c.set_from_symbol_table(symbol_table);

      if(cmdline.isset("show-symbol-table"))
      {
        show_symbol_table();
        return true;
      }

      irep_idt entry_point=goto_functions.entry_point();

      if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end())
      {
        error() << "The goto binary has no entry point; please complete linking" << eom;
        return true;
      }
    }
    else if(cmdline.isset("show-parse-tree"))
    {
      if(cmdline.args.size()!=1)
      {
        error() << "Please give one source file only" << eom;
        return true;
      }

      std::string filename=cmdline.args[0];

      #ifdef _MSC_VER
      std::ifstream infile(widen(filename).c_str());
      #else
      std::ifstream infile(filename.c_str());
      #endif

      if(!infile)
      {
        error() << "failed to open input file `" << filename << "'" << eom;
        return true;
      }

      languaget *language=get_language_from_filename(filename);

      if(language==NULL)
      {
        error() << "failed to figure out type of file `" <<  filename << "'" << eom;
        return true;
      }

      status("Parsing", filename);

      if(language->parse(infile, filename, get_message_handler()))
      {
        error() << "PARSING ERROR" << eom;
        return true;
      }

      language->show_parse(std::cout);
      return true;
    }
    else
    {

      if(parse()) return true;
      if(typecheck()) return true;
      if(final()) return true;

      // we no longer need any parse trees or language files
      clear_parse();

      if(cmdline.isset("show-symbol-table"))
      {
        show_symbol_table();
        return true;
      }

      irep_idt entry_point=goto_functions.entry_point();

      if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end())
      {
        error() << "No entry point; please provide a main function" << eom;
        return true;
      }

      status() << "Generating GOTO Program" << eom;

      goto_convert(symbol_table, goto_functions, ui_message_handler);
    }

    // finally add the library
    status() << "Adding CPROVER library" << eom;
    link_to_library(symbol_table, goto_functions, ui_message_handler);

    if(process_goto_program(options, goto_functions))
      return true;
  }

  catch(const char *e)
  {
    error(e);
    return true;
  }

  catch(const std::string e)
  {
    error(e);
    return true;
  }

  catch(int)
  {
    return true;
  }

  catch(std::bad_alloc)
  {
    error() << "Out of memory" << eom;
    return true;
  }

  return false;
}
示例#6
0
文件: prepare.cpp 项目: olivo/BP
int preparet::doit()
{
  register_languages();

  try
  {
    // do we have a goto binary?
    if(cmdline.args.size()==1 &&
        is_goto_binary(cmdline.args[0]))
    {
      status("Reading GOTO program from file");

      if(read_goto_binary(cmdline.args[0],
            context, goto_functions,
            get_message_handler()))
        return 1;

      config.ansi_c.set_from_context(context);
    }
    else
    {
      //
      // parsing
      //

      if(parse()) return 1;

      //
      // type checking
      //

      if(typecheck()) return 1;

      //
      // final adjustments
      //

      if(final()) return 1;
    }

    {
      int return_value_get_sync_modules=get_sync_modules();
      if(return_value_get_sync_modules>=0)
        return return_value_get_sync_modules;
    }

    {
      int return_value_get_async_modules=get_async_modules();
      if(return_value_get_async_modules>=0)
        return return_value_get_async_modules;
    }

    if(cmdline.isset("show-claims"))
    {
      show_claims(ns, get_ui(), goto_functions);
      return 0;
    }

    // get the user provided predicates

    if(cmdline.isset("predicates"))
      get_predicates(
          cmdline.getval("predicates"),
          get_message_handler(),
          ns,
          user_provided_predicates);
  }

  catch(const char *e)
  {
    error(e);
    return 1;
  }

  catch(const std::string e)
  {
    error(e);
    return 1;
  }

  catch(int)
  {
    return 1;
  }

  return -1; // proceed!
}
bool cbmc_parseoptionst::get_goto_program(
  const optionst &options,
  bmct &bmc,
  goto_functionst &goto_functions)
{
  if(cmdline.args.size()==0)
  {
    error("Please provide a program to verify");
    return true;
  }

  try
  {
    if(cmdline.args.size()==1 &&
       is_goto_binary(cmdline.args[0]))
    {
      status("Reading GOTO program from file");

      if(read_goto_binary(cmdline.args[0],
           context, goto_functions, get_message_handler()))
        return true;
        
      config.ansi_c.set_from_context(context);

      if(cmdline.isset("show-symbol-table"))
      {
        show_symbol_table();
        return true;
      }
      
      if(context.symbols.find(ID_main)==context.symbols.end())
      {
        error("The goto binary has no entry point; please complete linking");
        return true;
      }
    }
    else
    {
      if(parse()) return true;
      if(typecheck()) return true;
      if(get_modules(bmc)) return true;    
      if(final()) return true;

      // we no longer need any parse trees or language files
      clear_parse();

      if(cmdline.isset("show-symbol-table"))
      {
        show_symbol_table();
        return true;
      }

      if(context.symbols.find(ID_main)==context.symbols.end())
      {
        error("No entry point; please provide a main function");
        return true;
      }

      status("Generating GOTO Program");

      goto_convert(
        context, options, goto_functions,
        ui_message_handler);
    }

    // finally add the library
    status("Adding CPROVER library");      
    link_to_library(
      context, goto_functions, options, ui_message_handler);

    if(process_goto_program(options, goto_functions))
      return true;
  }

  catch(const char *e)
  {
    error(e);
    return true;
  }

  catch(const std::string e)
  {
    error(e);
    return true;
  }
  
  catch(int)
  {
    return true;
  }
  
  catch(std::bad_alloc)
  {
    error("Out of memory");
    return true;
  }
  
  return false;
}