|
29 | 29 | #include "goto_convert_functions.h"
|
30 | 30 | #include "read_goto_binary.h"
|
31 | 31 |
|
| 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 | + |
32 | 58 | goto_modelt initialize_goto_model(
|
33 | 59 | const std::vector<std::string> &files,
|
34 | 60 | message_handlert &message_handler,
|
@@ -133,10 +159,20 @@ goto_modelt initialize_goto_model(
|
133 | 159 | }
|
134 | 160 | else if(!binaries_provided_start)
|
135 | 161 | {
|
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 | + } |
140 | 176 | }
|
141 | 177 |
|
142 | 178 | if(entry_point_generation_failed)
|
|
0 commit comments