|
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"
|
@@ -127,6 +130,29 @@ int goto_instrument_parse_optionst::doit()
|
127 | 130 | return 0;
|
128 | 131 | }
|
129 | 132 |
|
| 133 | + if(cmdline.isset("save-code-statistics")) |
| 134 | + { |
| 135 | + // Here we only early-check for requirements and we handle the option later. |
| 136 | + const std::string out_json_file_pathname= |
| 137 | + cmdline.get_value("save-code-statistics"); |
| 138 | + if(fileutl_is_directory(out_json_file_pathname)) |
| 139 | + { |
| 140 | + error() << "The path-name '" << out_json_file_pathname |
| 141 | + << "'passed to the option '--save-code-statistics' " |
| 142 | + "represents an existing directory." |
| 143 | + << eom; |
| 144 | + return 12; |
| 145 | + } |
| 146 | + if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json") |
| 147 | + { |
| 148 | + error() << "The file of the path-name '" << out_json_file_pathname |
| 149 | + << "'passed to the option '--save-code-statistics' does " |
| 150 | + "not have '.json' extension." |
| 151 | + << eom; |
| 152 | + return 13; |
| 153 | + } |
| 154 | + } |
| 155 | + |
130 | 156 | eval_verbosity();
|
131 | 157 |
|
132 | 158 | try
|
@@ -738,6 +764,31 @@ int goto_instrument_parse_optionst::doit()
|
738 | 764 | undefined_function_abort_path(goto_model);
|
739 | 765 | }
|
740 | 766 |
|
| 767 | + if(cmdline.isset("save-code-statistics")) |
| 768 | + { |
| 769 | + goto_statisticst stats; |
| 770 | + stats.extend(goto_model); |
| 771 | + const std::string out_json_file_pathname= |
| 772 | + cmdline.get_value("save-code-statistics"); |
| 773 | + INVARIANT(!fileutl_is_directory(out_json_file_pathname), |
| 774 | + "The early check passed so the JSON file indeed should not be " |
| 775 | + " a directory."); |
| 776 | + INVARIANT( |
| 777 | + fileutl_parse_extension_in_pathname(out_json_file_pathname)==".json", |
| 778 | + "The early check passed so the JSON file indeed should have " |
| 779 | + "'.json' extension."); |
| 780 | + std::ofstream ofile(out_json_file_pathname); |
| 781 | + if(!ofile) |
| 782 | + { |
| 783 | + error() << "Failed to open the JSON file '" << out_json_file_pathname |
| 784 | + << "' passed to the option '--save-code-statistics' " |
| 785 | + << "for writing." |
| 786 | + << eom; |
| 787 | + return 13; |
| 788 | + } |
| 789 | + ofile << to_json(stats); |
| 790 | + } |
| 791 | + |
741 | 792 | // write new binary?
|
742 | 793 | if(cmdline.args.size()==2)
|
743 | 794 | {
|
@@ -1450,6 +1501,9 @@ void goto_instrument_parse_optionst::help()
|
1450 | 1501 | " --list-calls-args list all function calls with their arguments\n"
|
1451 | 1502 | // NOLINTNEXTLINE(whitespace/line_length)
|
1452 | 1503 | " --print-path-lengths print statistics about control-flow graph paths\n"
|
| 1504 | + " --save-code-statistics saves a json file with basic statistical data of" |
| 1505 | + " the analysed program after all analyses and\n" |
| 1506 | + " transformations have been performed on it.\n" |
1453 | 1507 | "\n"
|
1454 | 1508 | "Safety checks:\n"
|
1455 | 1509 | " --no-assertions ignore user assertions\n"
|
|
0 commit comments