2929bool initialize_goto_model (
3030 goto_modelt &goto_model,
3131 const cmdlinet &cmdline,
32- bool generate_start_function,
3332 message_handlert &message_handler)
3433{
3534 messaget msg (message_handler);
@@ -54,12 +53,11 @@ bool initialize_goto_model(
5453 sources.push_back (file);
5554 }
5655
56+ language_filest language_files;
57+ language_files.set_message_handler (message_handler);
58+
5759 if (!sources.empty ())
5860 {
59- language_filest language_files;
60-
61- language_files.set_message_handler (message_handler);
62-
6361 for (const auto &filename : sources)
6462 {
6563 #ifdef _MSC_VER
@@ -115,17 +113,6 @@ bool initialize_goto_model(
115113 msg.error () << " CONVERSION ERROR" << messaget::eom;
116114 return true ;
117115 }
118-
119- if (binaries.empty ())
120- {
121- if (language_files.final (
122- goto_model.symbol_table ,
123- generate_start_function))
124- {
125- msg.error () << " CONVERSION ERROR" << messaget::eom;
126- return true ;
127- }
128- }
129116 }
130117
131118 for (const auto &file : binaries)
@@ -136,18 +123,39 @@ bool initialize_goto_model(
136123 return true ;
137124 }
138125
139- if (cmdline.isset (" function" ))
126+ bool binaries_provided_start=
127+ goto_model.symbol_table .has_symbol (goto_functionst::entry_point ());
128+
129+ bool entry_point_generation_failed=false ;
130+
131+ if (binaries_provided_start && cmdline.isset (" function" ))
140132 {
141- const std::string &function_id=cmdline.get_value (" function" );
142- rebuild_goto_start_functiont start_function_rebuilder (
133+ // Rebuild the entry-point, using the language annotation of the
134+ // existing __CPROVER_start function:
135+ rebuild_goto_start_functiont rebuild_existing_start (
143136 msg.get_message_handler (),
144137 goto_model.symbol_table ,
145138 goto_model.goto_functions );
139+ entry_point_generation_failed=rebuild_existing_start ();
140+ }
141+ else if (!binaries_provided_start)
142+ {
143+ // Allow all language front-ends to try to provide the user-specified
144+ // (--function) entry-point, or some language-specific default:
145+ entry_point_generation_failed=
146+ language_files.generate_support_functions (goto_model.symbol_table );
147+ }
146148
147- if (start_function_rebuilder (function_id))
148- {
149- return 6 ;
150- }
149+ if (entry_point_generation_failed)
150+ {
151+ msg.error () << " SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
152+ return true ;
153+ }
154+
155+ if (language_files.final (goto_model.symbol_table ))
156+ {
157+ msg.error () << " FINAL STAGE CONVERSION ERROR" << messaget::eom;
158+ return true ;
151159 }
152160
153161 msg.status () << " Generating GOTO Program" << messaget::eom;
0 commit comments