41static inline bool failed(
bool error_indicator)
43 return error_indicator;
47 const std::vector<std::string> &symtab_filenames,
48 const std::string &gb_filename,
49 const std::string &goto_functions_filename_or_empty,
50 const std::string &cmdline_verbosity)
54 std::ofstream out_file{gb_filename, std::ios::binary};
55 if(!out_file.is_open())
59 std::vector<std::ifstream> symtab_files;
60 for(
auto const &symtab_filename : symtab_filenames)
62 std::ifstream symtab_file{symtab_filename};
63 if(!symtab_file.is_open())
68 symtab_files.emplace_back(std::move(symtab_file));
72 std::optional<std::ifstream> goto_functions_file;
73 if(!goto_functions_filename_or_empty.empty())
75 goto_functions_file = std::ifstream{goto_functions_filename_or_empty};
76 if(!goto_functions_file->is_open())
79 "couldn't open goto functions file '" +
80 goto_functions_filename_or_empty +
"'"};
92 for(std::size_t ix = 0; ix < symtab_files.size(); ++ix)
94 auto const &symtab_filename = symtab_filenames[ix];
95 auto &symtab_file = symtab_files[ix];
97 symtab_language->parse(symtab_file, symtab_filename, message_handler)))
100 source_location.
set_file(symtab_filename);
102 "failed to parse symbol table", source_location};
105 if(
failed(symtab_language->typecheck(symtab,
"<unused>", message_handler)))
108 source_location.
set_file(symtab_filename);
110 "failed to typecheck symbol table", source_location};
112 config.set_from_symbol_table(symtab);
114 if(
failed(
linking(linked_symbol_table, symtab, message_handler)))
117 "failed to link `" + symtab_filename +
"'"};
125 if(goto_functions_file.has_value())
129 *goto_functions_file,
130 goto_functions_filename_or_empty,
135 source_location.
set_file(goto_functions_filename_or_empty);
137 "failed to parse JSON", source_location};
170 "expect at least one input file",
"<json-symtab-file>"};
172 std::vector<std::string> symtab_filenames =
cmdline.args;
173 std::string gb_filename =
"a.out";
179 std::string goto_functions_filename_or_empty =
187 goto_functions_filename_or_empty,
188 cmdline.get_value(
"verbosity"));
202 "Usage: \tPurpose:\n"
204 " {bsymtab2gb} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
205 " {bsymtab2gb} [options] {ujson-symtab-file...} \t compile CBMC symbol"
206 " table(s) in JSON format to a single goto-binary\n"
209 " {y--out} {uoutfile} \t specify the filename of the resulting binary"
210 " (default: a.out)\n"
211 " {y--goto-functions} {ufile} \t specify a file containing JSON-encoded"
213 " {y--verbosity} {u#} \t verbosity level\n");
std::unique_ptr< languaget > new_ansi_c_language()
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
Thrown when we can't handle something in an input source file.
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
parse_options_baset(const std::string &optstring, int argc, const char **argv, const std::string &program)
void set_file(const irep_idt &file)
void swap(symbol_tablet &other)
Swap symbol maps between two symbol tables.
symtab2gb_parse_optionst(int argc, const char *argv[])
void register_languages() override
Thrown when some external system fails unexpectedly.
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
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 goto_functions_from_json(const jsont &json, goto_functionst &goto_functions)
Deserialize goto_functionst from JSON.
JSON goto_functions deserialization.
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
std::unique_ptr< languaget > new_json_symtab_language()
bool linking(symbol_table_baset &dest_symbol_table, const symbol_table_baset &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
void register_language(language_factoryt factory)
Register a language Note: registering a language is required for using the functions in language_util...
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
std::string banner_string(const std::string &front_end, const std::string &version)
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
static void run_symtab2gb(const std::vector< std::string > &symtab_filenames, const std::string &gb_filename, const std::string &goto_functions_filename_or_empty, const std::string &cmdline_verbosity)
static bool failed(bool error_indicator)
#define SYMTAB2GB_OPTIONS
#define SYMTAB2GB_OUT_FILE_OPT
#define SYMTAB2GB_GOTO_FUNCTIONS_OPT
const char * CBMC_VERSION
static void write_goto_binary(std::ostream &out, const symbol_table_baset &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.