CBMC
get_goto_model_from_c.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Get goto model
4 
5 Author: Daniel Poetzl
6 
7 \*******************************************************************/
8 
10 
11 #include <ansi-c/ansi_c_language.h>
12 
14 
15 #include <langapi/language_file.h>
16 #include <langapi/mode.h>
17 
18 #include <util/cmdline.h>
19 #include <util/config.h>
20 #include <util/exception_utils.h>
21 #include <util/invariant.h>
22 #include <util/message.h>
23 #include <util/symbol_table.h>
24 
25 #include <testing-utils/message.h>
26 
28 {
29  {
30  const bool has_language = get_language_from_mode(ID_C) != nullptr;
31 
32  if(!has_language)
33  {
35  }
36  }
37 
38  {
39  cmdlinet cmdline;
40 
41  config = configt{};
42  config.main = std::string("main");
43  config.set(cmdline);
44  }
45 
46  language_filest language_files;
47 
48  language_filet &language_file = language_files.add_file("");
49 
50  language_file.language = get_language_from_mode(ID_C);
51  CHECK_RETURN(language_file.language);
52 
53  languaget &language = *language_file.language;
54 
55  {
56  const bool error = language.parse(in, "", null_message_handler);
57 
58  if(error)
59  throw invalid_input_exceptiont("parsing failed");
60  }
61 
62  language_file.get_modules();
63 
64  goto_modelt goto_model;
65 
66  {
67  const bool error =
68  language_files.typecheck(goto_model.symbol_table, null_message_handler);
69 
70  if(error)
71  throw invalid_input_exceptiont("typechecking failed");
72  }
73 
74  {
75  const bool error = language_files.generate_support_functions(
77 
78  if(error)
79  throw invalid_input_exceptiont("support function generation failed");
80  }
81 
83  goto_model.symbol_table, goto_model.goto_functions, null_message_handler);
84 
85  return goto_model;
86 }
87 
88 goto_modelt get_goto_model_from_c(const std::string &code)
89 {
90  std::istringstream in(code);
91  return get_goto_model_from_c(in);
92 }
std::unique_ptr< languaget > new_ansi_c_language()
configt config
Definition: config.cpp:25
Globally accessible architectural configuration.
Definition: config.h:132
bool set(const cmdlinet &cmdline)
Definition: config.cpp:798
std::optional< std::string > main
Definition: config.h:356
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:31
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:34
Thrown when user-provided input cannot be processed.
language_filet & add_file(const std::string &filename)
Definition: language_file.h:77
bool typecheck(symbol_table_baset &symbol_table, const bool keep_file_local, message_handlert &message_handler)
bool generate_support_functions(symbol_table_baset &symbol_table, message_handlert &message_handler)
std::unique_ptr< languaget > language
Definition: language_file.h:46
virtual bool parse(std::istream &instream, const std::string &path, message_handlert &message_handler)=0
goto_modelt get_goto_model_from_c(std::istream &in)
void goto_convert(const codet &code, symbol_table_baset &symbol_table, goto_programt &dest, message_handlert &message_handler, const irep_idt &mode)
Goto Programs with Functions.
void register_language(language_factoryt factory)
Register a language Note: registering a language is required for using the functions in language_util...
Definition: mode.cpp:39
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Definition: mode.cpp:51
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
Author: Diffblue Ltd.
null_message_handlert null_message_handler
Definition: message.cpp:14