@@ -29,6 +29,32 @@ Author: Daniel Kroening, kroening@kroening.com
2929#include " goto_convert_functions.h"
3030#include " read_goto_binary.h"
3131
32+ // / Generate an entry point that calls a function with the given name, based on
33+ // / the functions language mode in the symbol table
34+ static bool generate_entry_point_for_function (
35+ const irep_idt &entry_function_name,
36+ const optionst &options,
37+ goto_modelt &goto_model,
38+ message_handlert &message_handler)
39+ {
40+ auto const entry_function_sym =
41+ goto_model.symbol_table .lookup (entry_function_name);
42+ if (entry_function_sym == nullptr )
43+ {
44+ throw invalid_command_line_argument_exceptiont{
45+ // NOLINTNEXTLINE(whitespace/braces)
46+ std::string{" couldn't find function with name `" } +
47+ id2string (entry_function_name) + " ' in symbol table" ,
48+ " --function" };
49+ }
50+ PRECONDITION (!entry_function_sym->mode .empty ());
51+ auto const entry_language = get_language_from_mode (entry_function_sym->mode );
52+ CHECK_RETURN (entry_language != nullptr );
53+ entry_language->set_message_handler (message_handler);
54+ entry_language->set_language_options (options);
55+ return entry_language->generate_support_functions (goto_model.symbol_table );
56+ }
57+
3258goto_modelt initialize_goto_model (
3359 const std::vector<std::string> &files,
3460 message_handlert &message_handler,
@@ -133,10 +159,20 @@ goto_modelt initialize_goto_model(
133159 }
134160 else if (!binaries_provided_start)
135161 {
136- // Allow all language front-ends to try to provide the user-specified
137- // (--function) entry-point, or some language-specific default:
138- entry_point_generation_failed=
139- language_files.generate_support_functions (goto_model.symbol_table );
162+ if (options.is_set (" function" ))
163+ {
164+ // no entry point is present; Use the mode of the specified entry function
165+ // to generate one
166+ entry_point_generation_failed = generate_entry_point_for_function (
167+ options.get_option (" function" ), options, goto_model, message_handler);
168+ }
169+ if (entry_point_generation_failed || !options.is_set (" function" ))
170+ {
171+ // Allow all language front-ends to try to provide the user-specified
172+ // (--function) entry-point, or some language-specific default:
173+ entry_point_generation_failed =
174+ language_files.generate_support_functions (goto_model.symbol_table );
175+ }
140176 }
141177
142178 if (entry_point_generation_failed)
0 commit comments