CBMC
Loading...
Searching...
No Matches
goto_diff_parse_options.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: GOTO-DIFF Command Line Option Processing
4
5Author: Peter Schrammel
6
7\*******************************************************************/
8
11
13
14#include <util/config.h>
15#include <util/exit_codes.h>
16#include <util/help_formatter.h>
17#include <util/options.h>
18#include <util/version.h>
19
26
28#include <ansi-c/gcc_version.h>
31#include <cpp/cprover_library.h>
33
34#include "change_impact.h"
35#include "syntactic_diff.h"
36#include "unified_diff.h"
37
38#include <cstdlib> // exit()
39#include <fstream> // IWYU pragma: keep
40#include <iostream>
41
45 argc,
46 argv,
47 std::string("GOTO-DIFF ") + CBMC_VERSION)
48{
49}
50
52{
53 if(config.set(cmdline))
54 {
56 exit(1);
57 }
58
59 if(cmdline.isset("cover"))
61
62 // all checks supported by goto_check
64
65 options.set_option("show-properties", cmdline.isset("show-properties"));
66
67 // Options for process_goto_program
68 options.set_option("rewrite-rw-ok", false);
69 options.set_option("rewrite-union", true);
70}
71
74{
75 if(cmdline.isset("version"))
76 {
77 std::cout << CBMC_VERSION << '\n';
79 }
80
81 //
82 // command line options
83 //
84
85 optionst options;
89
91
92 if(cmdline.args.size()!=2)
93 {
94 log.error() << "Please provide two programs to compare" << messaget::eom;
96 }
97
99
100 goto_modelt goto_model1 =
102
103 // configure gcc, if required -- initialize_goto_model will have set config
105 {
106 gcc_versiont gcc_version;
107 gcc_version.get("gcc");
108 configure_gcc(gcc_version);
109 }
110
111 if(process_goto_program(options, goto_model1))
113 goto_modelt goto_model2 =
115 if(process_goto_program(options, goto_model2))
117
118 if(cmdline.isset("show-loops"))
119 {
123 }
124
125 if(
126 cmdline.isset("show-goto-functions") ||
127 cmdline.isset("list-goto-functions"))
128 {
130 goto_model1, ui_message_handler, cmdline.isset("list-goto-functions"));
132 goto_model2, ui_message_handler, cmdline.isset("list-goto-functions"));
134 }
135
136 if(cmdline.isset("change-impact") ||
137 cmdline.isset("forward-impact") ||
138 cmdline.isset("backward-impact"))
139 {
140 impact_modet impact_mode=
141 cmdline.isset("forward-impact") ?
143 (cmdline.isset("backward-impact") ?
147 goto_model1,
148 goto_model2,
149 impact_mode,
150 cmdline.isset("compact-output"),
152
154 }
155
156 if(cmdline.isset("unified") ||
157 cmdline.isset('u'))
158 {
159 unified_difft u(goto_model1, goto_model2);
160 u();
161 u.output(std::cout);
162
164 }
165
166 syntactic_difft sd(goto_model1, goto_model2, options, ui_message_handler);
167 sd();
168 sd.output_functions();
169
171}
172
174 const optionst &options,
175 goto_modelt &goto_model)
176{
177 // Remove inline assembler; this needs to happen before
178 // adding the library.
179 remove_asm(goto_model, ui_message_handler);
180
181 // add the library
182 log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
183 << messaget::eom;
186 // library functions may introduce inline assembler
187 while(has_asm(goto_model))
188 {
189 remove_asm(goto_model, ui_message_handler);
193 }
194
195 // Common removal of types and complex constructs
196 if(::process_goto_program(goto_model, options, log))
197 return true;
198
199 // instrument cover goals
200 if(cmdline.isset("cover"))
201 {
202 // remove skips such that trivial GOTOs are deleted and not considered
203 // for coverage annotation:
204 remove_skip(goto_model);
205
206 const auto cover_config =
209 return true;
210
211 goto_model.goto_functions.update();
212 }
213
214 // label the assertions
215 // This must be done after adding assertions and
216 // before using the argument of the "property" option.
217 // Do not re-label after using the property slicer because
218 // this would cause the property identifiers to change.
219 label_properties(goto_model);
220
221 // remove any skips introduced since coverage instrumentation
222 remove_skip(goto_model);
223
224 return false;
225}
226
229{
230 // clang-format off
231 std::cout << '\n' << banner_string("GOTO_DIFF", CBMC_VERSION) << '\n'
232 << align_center_with_border("Copyright (C) 2016") << '\n'
233 << align_center_with_border("Daniel Kroening, Peter Schrammel") << '\n' // NOLINT (*)
234 << align_center_with_border("kroening@kroening.com") << '\n';
235
236 std::cout << help_formatter(
237 "\n"
238 "Usage: \tPurpose:\n"
239 "\n"
240 " {bgoto-diff} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
241 " {bgoto-diff} {uold} {unew} \t compare two goto binaries\n"
242 "\n"
243 "Diff options:\n"
246 " {y--show-loops} \t show the loops in the programs\n"
247 " {y-u}, {y--unified} \t output unified diff\n"
248 " {y--change-impact}, {y--forward-impact}, {y--backward-impact} \t output"
249 " unified diff with forward&backward/forward/backward dependencies\n"
250 " {y--compact-output} \t output dependencies in compact mode\n"
251 "\n"
252 "Program instrumentation options:\n"
255 "\n"
256 "Other options:\n"
257 " {y--version} \t show version and exit\n"
258 " {y--json-ui} \t use JSON-formatted output\n"
260 " {y--verbosity} {u#} \t verbosity level\n"
262 "\n");
263 // clang-format on
264}
void cprover_c_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
configt config
Definition config.cpp:25
void change_impact(const goto_modelt &model_old, const goto_modelt &model_new, impact_modet impact_mode, bool compact_output, message_handlert &message_handler)
Data and control-dependencies of syntactic diff.
impact_modet
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
Definition ai.cpp:39
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::string get_value(char option) const
Definition cmdline.cpp:48
virtual bool isset(char option) const
Definition cmdline.cpp:30
argst args
Definition cmdline.h:154
bool set(const cmdlinet &cmdline)
Definition config.cpp:863
struct configt::ansi_ct ansi_c
void get(const std::string &executable)
int doit() override
invoke main modules
bool process_goto_program(const optionst &options, goto_modelt &goto_model)
void help() override
display command line help
goto_diff_parse_optionst(int argc, const char **argv)
void get_command_line_options(optionst &options)
symbol_tablet symbol_table
Symbol table.
Definition goto_model.h:31
goto_functionst goto_functions
GOTO functions.
Definition goto_model.h:34
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
Definition message.cpp:105
mstreamt & error() const
Definition message.h:391
@ M_STATUS
Definition message.h:169
static eomt eom
Definition message.h:289
mstreamt & status() const
Definition message.h:406
void set_option(const std::string &option, const bool value)
Definition options.cpp:28
virtual void usage_error()
void log_version_and_architecture(const std::string &front_end)
Write version and system architecture to log.status().
ui_message_handlert ui_message_handler
virtual uit get_ui() const
Definition ui_message.h:33
static void instrument_cover_goals(const irep_idt &function_id, goto_programt &goto_program, const cover_instrumenterst &instrumenters, const irep_idt &mode, message_handlert &message_handler, const cover_instrumenter_baset::assertion_factoryt &make_assertion)
Applies instrumenters to given goto program.
Definition cover.cpp:36
cover_configt get_cover_config(const optionst &options, const symbol_tablet &symbol_table, message_handlert &message_handler)
Build data structures controlling coverage from command-line options.
Definition cover.cpp:181
void parse_cover_options(const cmdlinet &cmdline, optionst &options)
Parses coverage-related command line options.
Definition cover.cpp:143
Coverage Instrumentation.
#define HELP_COVER
Definition cover.h:32
void cprover_cpp_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
static void show_goto_functions(const goto_modelt &goto_model)
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_INTERNAL_ERROR
An error has been encountered during processing the requested analysis.
Definition exit_codes.h:45
#define CPROVER_EXIT_INCORRECT_TASK
The command line is correctly structured but cannot be carried out due to missing files,...
Definition exit_codes.h:49
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Definition exit_codes.h:16
void configure_gcc(const gcc_versiont &gcc_version)
#define PARSE_OPTIONS_GOTO_CHECK(cmdline, options)
#define HELP_GOTO_CHECK
GOTO-DIFF Command Line Option Processing.
#define GOTO_DIFF_OPTIONS
Help Formatter.
static help_formattert help_formatter(const std::string &s)
goto_modelt initialize_goto_model(const std::vector< std::string > &files, message_handlert &message_handler, const optionst &options)
Initialize a Goto Program.
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition loop_ids.cpp:21
Loop IDs.
STL namespace.
Options.
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
std::string banner_string(const std::string &front_end, const std::string &version)
void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table, message_handlert &message_handler)
Replaces inline assembly instructions in the goto program (i.e., instructions of kind OTHER with a co...
bool has_asm(const goto_functionst &goto_functions)
returns true iff the given goto functions use asm instructions
Remove 'asm' statements by compiling them into suitable standard goto program instructions.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Program Transformation.
void label_properties(goto_modelt &goto_model)
Set the properties to check.
#define HELP_SHOW_GOTO_FUNCTIONS
Show the properties.
#define HELP_SHOW_PROPERTIES
void exit(int status)
Definition stdlib.c:102
Syntactic GOTO-DIFF.
#define HELP_TIMESTAMP
Definition timestamper.h:14
#define HELP_FLUSH
Definition ui_message.h:108
Unified diff (using LCSS) of goto functions.
const char * CBMC_VERSION