-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathgoto_diff_parse_options.cpp
419 lines (341 loc) · 11.9 KB
/
goto_diff_parse_options.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*******************************************************************\
Module: GOTO-DIFF Command Line Option Processing
Author: Peter Schrammel
\*******************************************************************/
/// \file
/// GOTO-DIFF Command Line Option Processing
#include "goto_diff_parse_options.h"
#include <cstdlib> // exit()
#include <fstream>
#include <iostream>
#include <memory>
#include <util/config.h>
#include <util/exit_codes.h>
#include <util/make_unique.h>
#include <util/options.h>
#include <util/version.h>
#include <langapi/language.h>
#include <goto-programs/adjust_float_expressions.h>
#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/goto_inline.h>
#include <goto-programs/initialize_goto_model.h>
#include <goto-programs/instrument_preconditions.h>
#include <goto-programs/link_to_library.h>
#include <goto-programs/loop_ids.h>
#include <goto-programs/mm_io.h>
#include <goto-programs/read_goto_binary.h>
#include <goto-programs/remove_complex.h>
#include <goto-programs/remove_function_pointers.h>
#include <goto-programs/remove_returns.h>
#include <goto-programs/remove_skip.h>
#include <goto-programs/remove_unused_functions.h>
#include <goto-programs/remove_vector.h>
#include <goto-programs/remove_virtual_functions.h>
#include <goto-programs/rewrite_union.h>
#include <goto-programs/set_properties.h>
#include <goto-programs/show_properties.h>
#include <goto-programs/string_abstraction.h>
#include <goto-programs/string_instrumentation.h>
#include <goto-instrument/cover.h>
#include <pointer-analysis/add_failed_symbols.h>
#include <langapi/mode.h>
#include <ansi-c/cprover_library.h>
#include <assembler/remove_asm.h>
#include <cpp/cprover_library.h>
#include "goto_diff.h"
#include "syntactic_diff.h"
#include "unified_diff.h"
#include "change_impact.h"
goto_diff_parse_optionst::goto_diff_parse_optionst(int argc, const char **argv)
: parse_options_baset(
GOTO_DIFF_OPTIONS,
argc,
argv,
std::string("GOTO-DIFF ") + CBMC_VERSION)
{
}
void goto_diff_parse_optionst::get_command_line_options(optionst &options)
{
if(config.set(cmdline))
{
usage_error();
exit(1);
}
if(cmdline.isset("program-only"))
options.set_option("program-only", true);
if(cmdline.isset("show-vcc"))
options.set_option("show-vcc", true);
if(cmdline.isset("cover"))
parse_cover_options(cmdline, options);
if(cmdline.isset("mm"))
options.set_option("mm", cmdline.get_value("mm"));
if(cmdline.isset("c89"))
config.ansi_c.set_c89();
if(cmdline.isset("c99"))
config.ansi_c.set_c99();
if(cmdline.isset("c11"))
config.ansi_c.set_c11();
if(cmdline.isset("cpp98"))
config.cpp.set_cpp98();
if(cmdline.isset("cpp03"))
config.cpp.set_cpp03();
if(cmdline.isset("cpp11"))
config.cpp.set_cpp11();
// all checks supported by goto_check
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
if(cmdline.isset("debug-level"))
options.set_option("debug-level", cmdline.get_value("debug-level"));
if(cmdline.isset("unwindset"))
options.set_option("unwindset", cmdline.get_value("unwindset"));
// constant propagation
if(cmdline.isset("no-propagation"))
options.set_option("propagation", false);
else
options.set_option("propagation", true);
// check array bounds
if(cmdline.isset("bounds-check"))
options.set_option("bounds-check", true);
else
options.set_option("bounds-check", false);
// check division by zero
if(cmdline.isset("div-by-zero-check"))
options.set_option("div-by-zero-check", true);
else
options.set_option("div-by-zero-check", false);
// check overflow/underflow
if(cmdline.isset("signed-overflow-check"))
options.set_option("signed-overflow-check", true);
else
options.set_option("signed-overflow-check", false);
// check overflow/underflow
if(cmdline.isset("unsigned-overflow-check"))
options.set_option("unsigned-overflow-check", true);
else
options.set_option("unsigned-overflow-check", false);
// check overflow/underflow
if(cmdline.isset("float-overflow-check"))
options.set_option("float-overflow-check", true);
else
options.set_option("float-overflow-check", false);
// check for NaN (not a number)
if(cmdline.isset("nan-check"))
options.set_option("nan-check", true);
else
options.set_option("nan-check", false);
// check pointers
if(cmdline.isset("pointer-check"))
options.set_option("pointer-check", true);
else
options.set_option("pointer-check", false);
// check for memory leaks
if(cmdline.isset("memory-leak-check"))
options.set_option("memory-leak-check", true);
else
options.set_option("memory-leak-check", false);
// check assertions
if(cmdline.isset("no-assertions"))
options.set_option("assertions", false);
else
options.set_option("assertions", true);
// use assumptions
if(cmdline.isset("no-assumptions"))
options.set_option("assumptions", false);
else
options.set_option("assumptions", true);
// magic error label
if(cmdline.isset("error-label"))
options.set_option("error-label", cmdline.get_values("error-label"));
// generate unwinding assertions
if(cmdline.isset("cover"))
options.set_option("unwinding-assertions", false);
else
options.set_option(
"unwinding-assertions",
cmdline.isset("unwinding-assertions"));
// generate unwinding assumptions otherwise
options.set_option("partial-loops", cmdline.isset("partial-loops"));
if(options.get_bool_option("partial-loops") &&
options.get_bool_option("unwinding-assertions"))
{
log.error() << "--partial-loops and --unwinding-assertions"
<< " must not be given together" << messaget::eom;
exit(1);
}
options.set_option("show-properties", cmdline.isset("show-properties"));
}
/// invoke main modules
int goto_diff_parse_optionst::doit()
{
if(cmdline.isset("version"))
{
std::cout << CBMC_VERSION << '\n';
return CPROVER_EXIT_SUCCESS;
}
//
// command line options
//
optionst options;
get_command_line_options(options);
messaget::eval_verbosity(
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);
//
// Print a banner
//
log.status() << "GOTO-DIFF version " << CBMC_VERSION << " "
<< sizeof(void *) * 8 << "-bit " << config.this_architecture()
<< " " << config.this_operating_system() << messaget::eom;
if(cmdline.args.size()!=2)
{
log.error() << "Please provide two programs to compare" << messaget::eom;
return CPROVER_EXIT_INCORRECT_TASK;
}
register_languages();
goto_modelt goto_model1 =
initialize_goto_model({cmdline.args[0]}, ui_message_handler, options);
if(process_goto_program(options, goto_model1))
return CPROVER_EXIT_INTERNAL_ERROR;
goto_modelt goto_model2 =
initialize_goto_model({cmdline.args[1]}, ui_message_handler, options);
if(process_goto_program(options, goto_model2))
return CPROVER_EXIT_INTERNAL_ERROR;
if(cmdline.isset("show-loops"))
{
show_loop_ids(ui_message_handler.get_ui(), goto_model1);
show_loop_ids(ui_message_handler.get_ui(), goto_model2);
return CPROVER_EXIT_SUCCESS;
}
if(
cmdline.isset("show-goto-functions") ||
cmdline.isset("list-goto-functions"))
{
show_goto_functions(
goto_model1, ui_message_handler, cmdline.isset("list-goto-functions"));
show_goto_functions(
goto_model2, ui_message_handler, cmdline.isset("list-goto-functions"));
return CPROVER_EXIT_SUCCESS;
}
if(cmdline.isset("change-impact") ||
cmdline.isset("forward-impact") ||
cmdline.isset("backward-impact"))
{
impact_modet impact_mode=
cmdline.isset("forward-impact") ?
impact_modet::FORWARD :
(cmdline.isset("backward-impact") ?
impact_modet::BACKWARD :
impact_modet::BOTH);
change_impact(
goto_model1,
goto_model2,
impact_mode,
cmdline.isset("compact-output"));
return CPROVER_EXIT_SUCCESS;
}
if(cmdline.isset("unified") ||
cmdline.isset('u'))
{
unified_difft u(goto_model1, goto_model2);
u();
u.output(std::cout);
return CPROVER_EXIT_SUCCESS;
}
syntactic_difft sd(goto_model1, goto_model2, options, ui_message_handler);
sd();
sd.output_functions();
return CPROVER_EXIT_SUCCESS;
}
bool goto_diff_parse_optionst::process_goto_program(
const optionst &options,
goto_modelt &goto_model)
{
{
// Remove inline assembler; this needs to happen before
// adding the library.
remove_asm(goto_model);
// add the library
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
<< messaget::eom;
link_to_library(
goto_model, ui_message_handler, cprover_cpp_library_factory);
link_to_library(goto_model, ui_message_handler, cprover_c_library_factory);
// remove function pointers
log.status() << "Removal of function pointers and virtual functions"
<< messaget::eom;
remove_function_pointers(
ui_message_handler, goto_model, cmdline.isset("pointer-check"));
mm_io(goto_model);
// instrument library preconditions
instrument_preconditions(goto_model);
// remove returns, gcc vectors, complex
remove_returns(goto_model);
remove_vector(goto_model);
remove_complex(goto_model);
rewrite_union(goto_model);
// add generic checks
log.status() << "Generic Property Instrumentation" << messaget::eom;
goto_check(options, goto_model);
// checks don't know about adjusted float expressions
adjust_float_expressions(goto_model);
// recalculate numbers, etc.
goto_model.goto_functions.update();
// add loop ids
goto_model.goto_functions.compute_loop_numbers();
// instrument cover goals
if(cmdline.isset("cover"))
{
// remove skips such that trivial GOTOs are deleted and not considered
// for coverage annotation:
remove_skip(goto_model);
const auto cover_config =
get_cover_config(options, goto_model.symbol_table, ui_message_handler);
if(instrument_cover_goals(cover_config, goto_model, ui_message_handler))
return true;
}
// label the assertions
// This must be done after adding assertions and
// before using the argument of the "property" option.
// Do not re-label after using the property slicer because
// this would cause the property identifiers to change.
label_properties(goto_model);
// remove any skips introduced since coverage instrumentation
remove_skip(goto_model);
}
return false;
}
/// display command line help
void goto_diff_parse_optionst::help()
{
// clang-format off
std::cout << '\n' << banner_string("GOTO_DIFF", CBMC_VERSION) << '\n'
<< align_center_with_border("Copyright (C) 2016") << '\n'
<< align_center_with_border("Daniel Kroening, Peter Schrammel") << '\n' // NOLINT (*)
<< align_center_with_border("[email protected]") << '\n'
<<
"\n"
"Usage: Purpose:\n"
"\n"
" goto_diff [-?] [-h] [--help] show help\n"
" goto_diff old new goto binaries to be compared\n"
"\n"
"Diff options:\n"
HELP_SHOW_GOTO_FUNCTIONS
HELP_SHOW_PROPERTIES
" --syntactic do syntactic diff (default)\n"
" -u | --unified output unified diff\n"
" --change-impact | \n"
" --forward-impact |\n"
// NOLINTNEXTLINE(whitespace/line_length)
" --backward-impact output unified diff with forward&backward/forward/backward dependencies\n"
" --compact-output output dependencies in compact mode\n"
"\n"
"Program instrumentation options:\n"
<< HELP_GOTO_CHECK <<
" --cover CC create test-suite with coverage criterion CC\n" // NOLINT(*)
"Other options:\n"
" --version show version and exit\n"
" --json-ui use JSON-formatted output\n"
HELP_FLUSH
HELP_TIMESTAMP
"\n";
// clang-format on
}