Skip to content

Commit 06a7802

Browse files
Merge pull request diffblue#185 from diffblue/nathan/feature/lazy-function-loading
SEC-20: Lazy function loading
2 parents cbd6688 + b02e833 commit 06a7802

File tree

3 files changed

+71
-33
lines changed

3 files changed

+71
-33
lines changed

src/driver/sec_driver_parse_options.cpp

+62-25
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>
@@ -32,9 +33,9 @@
3233
#include <goto-programs/class_hierarchy.h>
3334
#include <goto-programs/remove_exceptions.h>
3435
#include <goto-programs/remove_java_new.h>
36+
3537
#include <analyses/call_graph.h>
3638
#include <analyses/call_graph_helpers.h>
37-
3839
#include <analyses/goto_check.h>
3940
#include <analyses/local_may_alias.h>
4041

@@ -140,10 +141,36 @@ 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);
147+
148+
status() << "Generating GOTO Program" << messaget::eom;
149+
lazy_goto_model.load_all_functions();
150+
151+
// Show the symbol table before process_goto_functions mangles return
152+
// values, etc
153+
if(cmdline.isset("show-symbol-table"))
154+
{
155+
::show_symbol_table(lazy_goto_model.symbol_table, get_ui());
156+
return 6;
157+
}
144158

145-
if(process_goto_program(options))
159+
std::unique_ptr<goto_modelt> maybe_goto_model =
160+
lazy_goto_modelt::process_whole_model_and_freeze(
161+
std::move(lazy_goto_model));
162+
if(maybe_goto_model == nullptr)
146163
return 6;
164+
goto_modelt &goto_model = *maybe_goto_model;
165+
166+
// show it?
167+
if(cmdline.isset("show-goto-functions"))
168+
{
169+
namespacet ns(goto_model.symbol_table);
170+
171+
goto_model.goto_functions.output(ns, std::cout);
172+
return 6;
173+
}
147174

148175
if (cmdline.isset("security-scanner"))
149176
{
@@ -292,16 +319,45 @@ int sec_driver_parse_optionst::doit()
292319
return 6;
293320
}
294321

295-
bool sec_driver_parse_optionst::process_goto_program(
296-
const optionst &options)
322+
void sec_driver_parse_optionst::process_goto_function(
323+
goto_functionst::goto_functiont &function,
324+
symbol_tablet &symbol_table)
297325
{
298326
try
299327
{
300328
#if 0
301329
// Remove inline assembler; this needs to happen before
302330
// adding the library.
303-
remove_asm(goto_model);
331+
remove_asm(function.body, symbol_table);
332+
#endif
333+
}
304334

335+
catch(const char *e)
336+
{
337+
error() << e << eom;
338+
throw;
339+
}
340+
341+
catch(const std::string &e)
342+
{
343+
error() << e << eom;
344+
throw;
345+
}
346+
347+
catch(const std::bad_alloc &)
348+
{
349+
error() << "Out of memory" << eom;
350+
throw;
351+
}
352+
}
353+
354+
bool sec_driver_parse_optionst::process_goto_functions(
355+
goto_modelt &goto_model,
356+
const optionst &options)
357+
{
358+
try
359+
{
360+
#if 0
305361
// add the library
306362
status() << "Adding CPROVER library ("
307363
<< config.ansi_c.arch << ")" << eom;
@@ -339,25 +395,6 @@ bool sec_driver_parse_optionst::process_goto_program(
339395

340396
// recalculate numbers, etc.
341397
goto_model.goto_functions.update();
342-
343-
// add loop ids
344-
goto_model.goto_functions.compute_loop_numbers();
345-
346-
// show it?
347-
if(cmdline.isset("show-goto-functions"))
348-
{
349-
namespacet ns(goto_model.symbol_table);
350-
351-
goto_model.goto_functions.output(ns, std::cout);
352-
return true;
353-
}
354-
355-
// show it?
356-
if(cmdline.isset("show-symbol-table"))
357-
{
358-
::show_symbol_table(goto_model, get_ui());
359-
return true;
360-
}
361398
}
362399

363400
catch(const char *e)

src/driver/sec_driver_parse_options.h

+6-4
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

src/taint-slicer/slicing_tasks_builder.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,11 @@ std::pair<taint_slicing_taskt,std::string> build_slicing_task(
255255
symbol_table, logger->get_message_handler());
256256
for(const auto &elem : symbol_table.symbols)
257257
{
258-
if(elem.second.value.id()==ID_code &&
259-
converted.count(elem.second.name)==0UL)
258+
irep_idt fn_name = elem.second.name;
259+
if(elem.second.value.id() == ID_code && converted.count(fn_name) == 0UL)
260260
{
261261
converter.convert_function(
262-
elem.second.name,
263-
goto_functions.function_map[elem.second.name]);
262+
fn_name, goto_functions.function_map[fn_name]);
264263
}
265264
}
266265
}

0 commit comments

Comments
 (0)