|
42 | 42 | #include <goto-programs/parameter_assignments.h>
|
43 | 43 | #include <goto-programs/slice_global_inits.h>
|
44 | 44 | #include <goto-programs/show_symbol_table.h>
|
| 45 | +#include <goto-programs/goto_statistics.h> |
45 | 46 |
|
46 | 47 | #include <pointer-analysis/value_set_analysis.h>
|
47 | 48 | #include <pointer-analysis/goto_program_dereference.h>
|
|
61 | 62 | #include <analyses/constant_propagator.h>
|
62 | 63 | #include <analyses/is_threaded.h>
|
63 | 64 |
|
| 65 | +#include <util/file_util.h> |
| 66 | + |
64 | 67 | #include <cbmc/version.h>
|
65 | 68 |
|
66 | 69 | #include "document_properties.h"
|
@@ -738,6 +741,32 @@ int goto_instrument_parse_optionst::doit()
|
738 | 741 | undefined_function_abort_path(goto_model);
|
739 | 742 | }
|
740 | 743 |
|
| 744 | + if(cmdline.isset("save-code-statistics")) |
| 745 | + { |
| 746 | + goto_statisticst stats; |
| 747 | + stats.extend(goto_model); |
| 748 | + const std::string out_json_file_pathname= |
| 749 | + cmdline.get_value("save-code-statistics"); |
| 750 | + if(fileutl_is_directory(out_json_file_pathname)) |
| 751 | + { |
| 752 | + error() << "The path-name '" << cmdline.args[1] |
| 753 | + << "'passed to the option '--save-code-statistics' " |
| 754 | + "represents an existing directory." |
| 755 | + << eom; |
| 756 | + return 12; |
| 757 | + } |
| 758 | + if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json") |
| 759 | + { |
| 760 | + error() << "The file of the path-name '" << cmdline.args[1] |
| 761 | + << "'passed to the option '--save-code-statistics' does " |
| 762 | + "not have '.json' extension." |
| 763 | + << eom; |
| 764 | + return 13; |
| 765 | + } |
| 766 | + std::ofstream ofile(out_json_file_pathname); |
| 767 | + ofile << to_json(stats); |
| 768 | + } |
| 769 | + |
741 | 770 | // write new binary?
|
742 | 771 | if(cmdline.args.size()==2)
|
743 | 772 | {
|
@@ -1450,6 +1479,9 @@ void goto_instrument_parse_optionst::help()
|
1450 | 1479 | " --list-calls-args list all function calls with their arguments\n"
|
1451 | 1480 | // NOLINTNEXTLINE(whitespace/line_length)
|
1452 | 1481 | " --print-path-lengths print statistics about control-flow graph paths\n"
|
| 1482 | + " --save-code-statistics saves a json file with basic statistical data of" |
| 1483 | + " the analysed program after all analyses and\n" |
| 1484 | + " transformations have been performed on it.\n" |
1453 | 1485 | "\n"
|
1454 | 1486 | "Safety checks:\n"
|
1455 | 1487 | " --no-assertions ignore user assertions\n"
|
|
0 commit comments