Skip to content

Commit eec39f4

Browse files
Use lazy_goto_modelt
Don't eagerly convert functions during initialisation of goto_modelt. Currently uses eager loading at a later stage. Allow post-processing functions run on a function-by-function basis
1 parent 27d27da commit eec39f4

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

src/driver/sec_driver_parse_options.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <json/json_parser.h>
1717

18+
#include <goto-programs/lazy_goto_model.h>
1819
#include <goto-programs/set_properties.h>
1920
#include <goto-programs/remove_function_pointers.h>
2021
#include <goto-programs/remove_virtual_functions.h>
@@ -140,10 +141,19 @@ int sec_driver_parse_optionst::doit()
140141
register_languages();
141142
register_evs_pretty_printer();
142143

143-
goto_model=initialize_goto_model(cmdline, get_message_handler());
144+
lazy_goto_modelt lazy_goto_model = lazy_goto_modelt::from_handler_object(
145+
*this, options, get_message_handler());
146+
lazy_goto_model.initialize(cmdline);
144147

145-
if(process_goto_program(options))
148+
status() << "Generating GOTO Program" << messaget::eom;
149+
lazy_goto_model.load_all_functions();
150+
151+
std::unique_ptr<goto_modelt> maybe_goto_model =
152+
lazy_goto_modelt::process_whole_model_and_freeze(
153+
std::move(lazy_goto_model));
154+
if(maybe_goto_model == nullptr)
146155
return 6;
156+
goto_modelt &goto_model = *maybe_goto_model;
147157

148158
if (cmdline.isset("security-scanner"))
149159
{
@@ -292,16 +302,45 @@ int sec_driver_parse_optionst::doit()
292302
return 6;
293303
}
294304

295-
bool sec_driver_parse_optionst::process_goto_program(
296-
const optionst &options)
305+
void sec_driver_parse_optionst::process_goto_function(
306+
goto_functionst::goto_functiont &function,
307+
symbol_tablet &symbol_table)
297308
{
298309
try
299310
{
300311
#if 0
301312
// Remove inline assembler; this needs to happen before
302313
// adding the library.
303-
remove_asm(goto_model);
314+
remove_asm(function.body, symbol_table);
315+
#endif
316+
}
317+
318+
catch(const char *e)
319+
{
320+
error() << e << eom;
321+
throw;
322+
}
323+
324+
catch(const std::string &e)
325+
{
326+
error() << e << eom;
327+
throw;
328+
}
329+
330+
catch(const std::bad_alloc &)
331+
{
332+
error() << "Out of memory" << eom;
333+
throw;
334+
}
335+
}
304336

337+
bool sec_driver_parse_optionst::process_goto_functions(
338+
goto_modelt &goto_model,
339+
const optionst &options)
340+
{
341+
try
342+
{
343+
#if 0
305344
// add the library
306345
status() << "Adding CPROVER library ("
307346
<< config.ansi_c.arch << ")" << eom;
@@ -340,9 +379,6 @@ bool sec_driver_parse_optionst::process_goto_program(
340379
// recalculate numbers, etc.
341380
goto_model.goto_functions.update();
342381

343-
// add loop ids
344-
goto_model.goto_functions.compute_loop_numbers();
345-
346382
// show it?
347383
if(cmdline.isset("show-goto-functions"))
348384
{

src/driver/sec_driver_parse_options.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#include <langapi/language_ui.h>
1313

14+
#include <goto-programs/goto_functions.h>
1415
#include <goto-programs/initialize_goto_model.h>
1516

1617
class bmct;
17-
class goto_functionst;
1818
class optionst;
1919

2020
#define SEC_DRIVER_OPTIONS \
@@ -55,16 +55,18 @@ class sec_driver_parse_optionst final:
5555

5656
sec_driver_parse_optionst(int argc, const char **argv);
5757

58+
void process_goto_function(
59+
goto_functionst::goto_functiont &function,
60+
symbol_tablet &symbol_table);
61+
bool process_goto_functions(goto_modelt &goto_model, const optionst &options);
62+
5863
private:
5964
ui_message_handlert ui_message_handler;
60-
goto_modelt goto_model;
6165

6266
void register_languages();
6367

6468
void get_command_line_options(optionst &options);
6569

66-
bool process_goto_program(const optionst &options);
67-
6870
void eval_verbosity();
6971
};
7072

0 commit comments

Comments
 (0)