CBMC
jdiff_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: JDIFF Command Line Option Processing
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "jdiff_parse_options.h"
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 
24 #include <goto-programs/loop_ids.h>
25 #include <goto-programs/mm_io.h>
32 
34 #include <goto-diff/unified_diff.h>
35 #include <goto-instrument/cover.h>
39 
40 #include "java_syntactic_diff.h"
41 
42 #include <cstdlib> // exit()
43 #include <iostream>
44 
45 jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
48  argc,
49  argv,
50  std::string("JDIFF ") + CBMC_VERSION)
51 {
52 }
53 
55 {
56  if(config.set(cmdline))
57  {
58  usage_error();
59  exit(1);
60  }
61 
63 
64  // check assertions
65  if(cmdline.isset("no-assertions"))
66  options.set_option("assertions", false);
67  else
68  options.set_option("assertions", true);
69 
70  // use assumptions
71  if(cmdline.isset("no-assumptions"))
72  options.set_option("assumptions", false);
73  else
74  options.set_option("assumptions", true);
75 
76  if(cmdline.isset("cover"))
77  parse_cover_options(cmdline, options);
78 
79  options.set_option("show-properties", cmdline.isset("show-properties"));
80 }
81 
84 {
85  if(cmdline.isset("version"))
86  {
87  std::cout << CBMC_VERSION << '\n';
88  return CPROVER_EXIT_SUCCESS;
89  }
90 
91  //
92  // command line options
93  //
94 
95  optionst options;
96  get_command_line_options(options);
99 
101 
102  if(cmdline.args.size() != 2)
103  {
104  log.error() << "Please provide two programs to compare" << messaget::eom;
106  }
107 
109 
110  goto_modelt goto_model1 =
112  if(process_goto_program(options, goto_model1))
114  goto_modelt goto_model2 =
116  if(process_goto_program(options, goto_model2))
118 
119  if(cmdline.isset("show-loops"))
120  {
121  show_loop_ids(ui_message_handler.get_ui(), goto_model1);
122  show_loop_ids(ui_message_handler.get_ui(), goto_model2);
123  return CPROVER_EXIT_SUCCESS;
124  }
125 
126  if(
127  cmdline.isset("show-goto-functions") ||
128  cmdline.isset("list-goto-functions"))
129  {
131  goto_model1, ui_message_handler, cmdline.isset("list-goto-functions"));
133  goto_model2, ui_message_handler, cmdline.isset("list-goto-functions"));
134  return CPROVER_EXIT_SUCCESS;
135  }
136 
137  if(
138  cmdline.isset("change-impact") || cmdline.isset("forward-impact") ||
139  cmdline.isset("backward-impact"))
140  {
141  impact_modet impact_mode =
142  cmdline.isset("forward-impact")
144  : (cmdline.isset("backward-impact") ? impact_modet::BACKWARD
147  goto_model1,
148  goto_model2,
149  impact_mode,
150  cmdline.isset("compact-output"),
152 
153  return CPROVER_EXIT_SUCCESS;
154  }
155 
156  if(cmdline.isset("unified") || cmdline.isset('u'))
157  {
158  unified_difft u(goto_model1, goto_model2);
159  u();
160  u.output(std::cout);
161 
162  return CPROVER_EXIT_SUCCESS;
163  }
164 
166  goto_model1, goto_model2, options, ui_message_handler);
167  sd();
168  sd.output_functions();
169 
170  return CPROVER_EXIT_SUCCESS;
171 }
172 
174  const optionst &options,
175  goto_modelt &goto_model)
176 {
177  // remove function pointers
178  log.status() << "Removing function pointers and virtual functions"
179  << messaget::eom;
180  remove_function_pointers(ui_message_handler, goto_model, false);
181 
182  // Java virtual functions -> explicit dispatch tables:
183  remove_virtual_functions(goto_model);
184 
185  // remove Java throw and catch
186  // This introduces instanceof, so order is important:
188 
189  // Java instanceof -> clsid comparison:
190  class_hierarchyt class_hierarchy(goto_model.symbol_table);
191  remove_instanceof(goto_model, class_hierarchy, ui_message_handler);
192 
193  mm_io(goto_model, ui_message_handler);
194 
195  // instrument library preconditions
196  instrument_preconditions(goto_model);
197 
198  // remove returns
199  remove_returns(goto_model);
200 
201  transform_assertions_assumptions(options, goto_model);
202 
203  // checks don't know about adjusted float expressions
204  adjust_float_expressions(goto_model);
205 
206  // recalculate numbers, etc.
207  goto_model.goto_functions.update();
208 
209  // instrument cover goals
210  if(cmdline.isset("cover"))
211  {
212  // remove skips such that trivial GOTOs are deleted and not considered for
213  // coverage annotation:
214  remove_skip(goto_model);
215 
216  const auto cover_config =
217  get_cover_config(options, goto_model.symbol_table, ui_message_handler);
218  if(instrument_cover_goals(cover_config, goto_model, ui_message_handler))
219  return true;
220  }
221 
222  // label the assertions
223  // This must be done after adding assertions and
224  // before using the argument of the "property" option.
225  // Do not re-label after using the property slicer because
226  // this would cause the property identifiers to change.
227  label_properties(goto_model);
228 
229  // remove any skips introduced since coverage instrumentation
230  remove_skip(goto_model);
231 
232  return false;
233 }
234 
237 {
238  // clang-format off
239  std::cout << '\n' << banner_string("JDIFF", CBMC_VERSION) << '\n'
240  << align_center_with_border("Copyright (C) 2016-2018") << '\n'
241  << align_center_with_border("Daniel Kroening, Peter Schrammel") << '\n' // NOLINT(*)
242  << align_center_with_border("kroening@kroening.com") << '\n';
243 
244  std::cout << help_formatter(
245  "\n"
246  "Usage: \tPurpose:\n"
247  "\n"
248  " {bjdiff} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
249  " {bjdiff} {uold} {unew} \t jars to be compared\n"
250  "\n"
251  "Diff options:\n"
254  " {y--show-loops} \t show the loops in the programs\n"
255  " {y-u}, {y--unified} \t output unified diff\n"
256  " {y--change-impact}, {y--forward-impact}, {y--backward-impact} \t output"
257  " unified diff with forward&backward/forward/backward dependencies\n"
258  " {y--compact-output} \t output dependencies in compact mode\n"
259  "\n"
260  "Program instrumentation options:\n"
261  " {y--no-assertions} \t ignore user assertions\n"
262  " {y--no-assumptions} \t ignore user assumptions\n"
263  HELP_COVER
264  "\n"
265  "Other options:\n"
266  " {y--version} \t show version and exit\n"
267  " {y--json-ui} \t use JSON-formatted output\n"
268  " {y--verbosity} {u#} \t verbosity level\n"
270  "\n");
271  // clang-format on
272 }
void adjust_float_expressions(exprt &expr, const exprt &rounding_mode)
Replaces arithmetic operations and typecasts involving floating point numbers with their equivalent f...
Symbolic Execution.
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
Definition: change_impact.h:19
Non-graph-based representation of the class hierarchy.
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:151
bool set(const cmdlinet &cmdline)
Definition: config.cpp:863
virtual void output_functions() const
Output diff result.
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:31
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:34
jdiff_parse_optionst(int argc, const char **argv)
void register_languages() override
void help() override
display command line help
bool process_goto_program(const optionst &options, goto_modelt &goto_model)
void get_command_line_options(optionst &options)
int doit() override
invoke main modules
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
mstreamt & status() const
Definition: message.h:406
@ M_STATISTICS
Definition: message.h:170
static eomt eom
Definition: message.h:289
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
Definition: parse_options.h:45
virtual uit get_ui() const
Definition: ui_message.h:33
void output(std::ostream &os) const
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
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
static void transform_assertions_assumptions(goto_programt &goto_program, bool enable_assertions, bool enable_built_in_assertions, bool enable_assumptions)
Definition: goto_check.cpp:19
Checks for Errors in C and Java Programs.
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 instrument_preconditions(const goto_modelt &goto_model, goto_programt &goto_program)
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
Syntactic GOTO-DIFF for Java.
JDIFF Command Line Option Processing.
#define JDIFF_OPTIONS
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition: loop_ids.cpp:21
Loop IDs.
void mm_io(symbol_tablet &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler)
Definition: mm_io.cpp:154
Perform Memory-mapped I/O instrumentation.
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_exceptions_using_instanceof(symbol_table_baset &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
Remove function exceptional returns.
void remove_function_pointers(message_handlert &_message_handler, goto_modelt &goto_model, bool only_remove_const_fps)
Remove Indirect Function Calls.
void remove_instanceof(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
Replace an instanceof in the expression or guard of the passed instruction of the given function body...
Remove Instance-of Operators.
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
Replace function returns by assignments to global variables.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:87
Program Transformation.
void remove_virtual_functions(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Functions for replacing virtual function call with a static function calls in functions,...
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
#define HELP_TIMESTAMP
Definition: timestamper.h:14
Unified diff (using LCSS) of goto functions.
const char * CBMC_VERSION