|
14 | 14 | #include <goto-programs/write_goto_binary.h>
|
15 | 15 | #include <goto-programs/remove_returns.h>
|
16 | 16 | #include <goto-programs/goto_convert_functions.h>
|
| 17 | +#include <goto-programs/goto_statistics.h> |
17 | 18 | #include <java_bytecode/java_entry_point.h>
|
18 | 19 | #include <util/config.h>
|
19 | 20 | #include <util/cprover_prefix.h>
|
@@ -324,7 +325,55 @@ std::pair<taint_slicing_taskt,std::string> build_slicing_task(
|
324 | 325 | if(fail)
|
325 | 326 | fail_message="Not available.";
|
326 | 327 | else
|
327 |
| - return {{props.get_root(),sink_locations,pathname},""}; |
| 328 | + { |
| 329 | + // Before return we compute and same basic statistics of the saved |
| 330 | + // GOTO program (i.e. the slicing task). These statistics will later |
| 331 | + // be used by the Python driver script to compare them with similar |
| 332 | + // statistics from the full slicer (implemented in goto-instrument) |
| 333 | + // in order to get the efficiency of the slicing. |
| 334 | + |
| 335 | + const std::string out_json_file_pathname= |
| 336 | + fileutl_remove_extension(pathname) + ".stats.json"; |
| 337 | + |
| 338 | + // We start with safety check related to the file to be written. |
| 339 | + bool can_write_stats=true; |
| 340 | + if(fileutl_is_directory(out_json_file_pathname)) |
| 341 | + { |
| 342 | + logger->error() |
| 343 | + << "The path-name '" |
| 344 | + << out_json_file_pathname |
| 345 | + << "' for the statistics JSON output is actually an existing " |
| 346 | + << "directory." |
| 347 | + << messaget::eom; |
| 348 | + can_write_stats=false; |
| 349 | + } |
| 350 | + if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json") |
| 351 | + { |
| 352 | + logger->error() |
| 353 | + << "The file of the path-name '" << out_json_file_pathname |
| 354 | + << "' for the statistics JSON output does not have '.json' extension." |
| 355 | + << messaget::eom; |
| 356 | + can_write_stats=false; |
| 357 | + } |
| 358 | + if(can_write_stats) |
| 359 | + { |
| 360 | + // And let's compute and save the statistics. |
| 361 | + goto_statisticst stats; |
| 362 | + stats.extend(goto_model); |
| 363 | + std::ofstream ofile(out_json_file_pathname); |
| 364 | + if(!ofile) |
| 365 | + { |
| 366 | + logger->error() |
| 367 | + << "Failed to open the JSON file '" << out_json_file_pathname |
| 368 | + << "' for writing. The statistic of the GOTO program won't be " |
| 369 | + << "available." |
| 370 | + << messaget::eom; |
| 371 | + } |
| 372 | + else |
| 373 | + ofile << to_json(stats); |
| 374 | + } |
| 375 | + return {{props.get_root(), sink_locations, pathname}, ""}; |
| 376 | + } |
328 | 377 | }
|
329 | 378 | catch(const std::exception &e)
|
330 | 379 | {
|
|
0 commit comments