Skip to content

Commit c0c51c3

Browse files
committed
Added flags to goto-diff
minor bug fixing, compact output mode for the demo, forward and backward only impact
1 parent 7326a50 commit c0c51c3

File tree

4 files changed

+135
-68
lines changed

4 files changed

+135
-68
lines changed

src/goto-diff/change_impact.cpp

Lines changed: 111 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,16 @@ class change_impactt
239239
public:
240240
change_impactt(
241241
const goto_modelt &model_old,
242-
const goto_modelt &model_new);
242+
const goto_modelt &model_new,
243+
impact_modet impact_mode,
244+
bool compact_output);
243245

244246
void operator()();
245247

246248
protected:
249+
impact_modet impact_mode;
250+
bool compact_output;
251+
247252
const goto_functionst &old_goto_functions;
248253
const namespacet ns_old;
249254
const goto_functionst &new_goto_functions;
@@ -301,6 +306,12 @@ class change_impactt
301306
const goto_program_change_impactt &n_c_i,
302307
const goto_functionst &n_goto_functions,
303308
const namespacet &n_ns) const;
309+
310+
void output_instruction(char prefix,
311+
const goto_programt &goto_program,
312+
const namespacet &ns,
313+
const irep_idt &function,
314+
goto_programt::const_targett& target) const;
304315
};
305316

306317
/*******************************************************************\
@@ -317,7 +328,11 @@ Function: change_impactt::change_impactt
317328

318329
change_impactt::change_impactt(
319330
const goto_modelt &model_old,
320-
const goto_modelt &model_new):
331+
const goto_modelt &model_new,
332+
impact_modet _impact_mode,
333+
bool _compact_output):
334+
impact_mode(_impact_mode),
335+
compact_output(_compact_output),
321336
old_goto_functions(model_old.goto_functions),
322337
ns_old(model_old.symbol_table),
323338
new_goto_functions(model_new.goto_functions),
@@ -425,8 +440,10 @@ void change_impactt::change_impact(
425440
const dependence_grapht::nodet &d_node=
426441
old_dep_graph[old_dep_graph[o_it].get_node_id()];
427442

428-
propogate_dep_back(d_node, old_dep_graph, old_change_impact, true);
429-
propogate_dep_forward(d_node, old_dep_graph, old_change_impact, true);
443+
if(impact_mode == BACKWARD || impact_mode == BOTH)
444+
propogate_dep_back(d_node, old_dep_graph, old_change_impact, true);
445+
if(impact_mode == FORWARD || impact_mode == BOTH)
446+
propogate_dep_forward(d_node, old_dep_graph, old_change_impact, true);
430447
}
431448
old_impact[o_it]|=DELETED;
432449
++o_it;
@@ -438,8 +455,10 @@ void change_impactt::change_impact(
438455
const dependence_grapht::nodet &d_node=
439456
new_dep_graph[new_dep_graph[n_it].get_node_id()];
440457

441-
propogate_dep_back(d_node, new_dep_graph, new_change_impact, false);
442-
propogate_dep_forward(d_node, new_dep_graph, new_change_impact, false);
458+
if(impact_mode == BACKWARD || impact_mode == BOTH)
459+
propogate_dep_back(d_node, new_dep_graph, new_change_impact, false);
460+
if(impact_mode == FORWARD || impact_mode == BOTH)
461+
propogate_dep_forward(d_node, new_dep_graph, new_change_impact, false);
443462
}
444463
new_impact[n_it]|=NEW;
445464
++n_it;
@@ -464,26 +483,25 @@ Function: change_impactt::propogate_dep_forward
464483
void change_impactt::propogate_dep_forward(const dependence_grapht::nodet &d_node,
465484
const dependence_grapht &dep_graph,
466485
goto_functions_change_impactt &change_impact, bool del) {
467-
for (dependence_grapht::edgest::const_iterator it = d_node.out.begin();
468-
it != d_node.out.end(); ++it) {
469-
goto_programt::const_targett src = dep_graph[it->first].PC;
470-
471-
mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP;
472-
mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP;
473-
474-
if ((change_impact[src->function][src] & data_flag)
475-
|| (change_impact[src->function][src] & ctrl_flag))
476-
continue;
477-
if (it->second.get() == dep_edget::DATA
478-
|| it->second.get() == dep_edget::BOTH)
479-
change_impact[src->function][src] |= data_flag;
480-
else
481-
change_impact[src->function][src] |= ctrl_flag;
482-
propogate_dep_forward(
483-
dep_graph[dep_graph[src].get_node_id()], dep_graph,
484-
change_impact, del);
485-
}
486+
for(dependence_grapht::edgest::const_iterator it = d_node.out.begin();
487+
it != d_node.out.end(); ++it)
488+
{
489+
goto_programt::const_targett src = dep_graph[it->first].PC;
486490

491+
mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP;
492+
mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP;
493+
494+
if((change_impact[src->function][src] & data_flag)
495+
|| (change_impact[src->function][src] & ctrl_flag))
496+
continue;
497+
if(it->second.get() == dep_edget::DATA
498+
|| it->second.get() == dep_edget::BOTH)
499+
change_impact[src->function][src] |= data_flag;
500+
else
501+
change_impact[src->function][src] |= ctrl_flag;
502+
propogate_dep_forward(dep_graph[dep_graph[src].get_node_id()], dep_graph,
503+
change_impact, del);
504+
}
487505
}
488506

489507
/*******************************************************************\
@@ -501,27 +519,28 @@ Function: change_impactt::propogate_dep_back
501519
void change_impactt::propogate_dep_back(const dependence_grapht::nodet &d_node,
502520
const dependence_grapht &dep_graph,
503521
goto_functions_change_impactt &change_impact, bool del) {
504-
for (dependence_grapht::edgest::const_iterator it = d_node.in.begin();
505-
it != d_node.in.end(); ++it) {
506-
goto_programt::const_targett src = dep_graph[it->first].PC;
507-
508-
mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP;
509-
mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP;
510-
511-
if ((change_impact[src->function][src] & data_flag)
512-
|| (change_impact[src->function][src] & ctrl_flag)) {
513-
continue;
514-
}
515-
if (it->second.get() == dep_edget::DATA
516-
|| it->second.get() == dep_edget::BOTH)
517-
change_impact[src->function][src] |= data_flag;
518-
else
519-
change_impact[src->function][src] |= ctrl_flag;
520-
521-
propogate_dep_back(
522-
dep_graph[dep_graph[src].get_node_id()], dep_graph,
523-
change_impact, del);
524-
}
522+
for(dependence_grapht::edgest::const_iterator it = d_node.in.begin();
523+
it != d_node.in.end(); ++it)
524+
{
525+
goto_programt::const_targett src = dep_graph[it->first].PC;
526+
527+
mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP;
528+
mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP;
529+
530+
if((change_impact[src->function][src] & data_flag)
531+
|| (change_impact[src->function][src] & ctrl_flag))
532+
{
533+
continue;
534+
}
535+
if(it->second.get() == dep_edget::DATA
536+
|| it->second.get() == dep_edget::BOTH)
537+
change_impact[src->function][src] |= data_flag;
538+
else
539+
change_impact[src->function][src] |= ctrl_flag;
540+
541+
propogate_dep_back(dep_graph[dep_graph[src].get_node_id()], dep_graph,
542+
change_impact, del);
543+
}
525544
}
526545

527546
/*******************************************************************\
@@ -629,7 +648,8 @@ void change_impactt::output_change_impact(
629648
assert(f_it!=goto_functions.function_map.end());
630649
const goto_programt &goto_program=f_it->second.body;
631650

632-
std::cout << "/** " << function << " **/\n";
651+
if(!compact_output)
652+
std::cout << "/** " << function << " **/\n";
633653

634654
forall_goto_program_instructions(target, goto_program)
635655
{
@@ -658,8 +678,7 @@ void change_impactt::output_change_impact(
658678
else
659679
assert(false);
660680

661-
std::cout << prefix;
662-
goto_program.output_instruction(ns, function, std::cout, target);
681+
output_instruction(prefix, goto_program, ns, function, target);
663682
}
664683
}
665684

@@ -694,7 +713,8 @@ void change_impactt::output_change_impact(
694713
assert(f_it!=n_goto_functions.function_map.end());
695714
const goto_programt &goto_program=f_it->second.body;
696715

697-
std::cout << "/** " << function << " **/\n";
716+
if(!compact_output)
717+
std::cout << "/** " << function << " **/\n";
698718

699719
goto_programt::const_targett o_target=
700720
old_goto_program.instructions.begin();
@@ -707,14 +727,9 @@ void change_impactt::output_change_impact(
707727

708728
if(old_mod_flags&DELETED)
709729
{
710-
std::cout << '-';
711-
goto_program.output_instruction(
712-
o_ns,
713-
function,
714-
std::cout,
715-
o_target);
716-
730+
output_instruction('-', goto_program, o_ns, function, o_target);
717731
++o_target;
732+
--target;
718733
continue;
719734
}
720735

@@ -764,8 +779,7 @@ void change_impactt::output_change_impact(
764779
else
765780
assert(false);
766781

767-
std::cout << prefix;
768-
goto_program.output_instruction(n_ns, function, std::cout, target);
782+
output_instruction(prefix, goto_program, n_ns, function, target);
769783
}
770784
for( ;
771785
o_target!=old_goto_program.instructions.end();
@@ -792,8 +806,41 @@ void change_impactt::output_change_impact(
792806
else
793807
assert(false);
794808

809+
output_instruction(prefix, goto_program, o_ns, function, o_target);
810+
}
811+
}
812+
813+
/*******************************************************************\
814+
815+
Function: change_impactt::output_instruction
816+
817+
Inputs:
818+
819+
Outputs:
820+
821+
Purpose:
822+
823+
\*******************************************************************/
824+
825+
void change_impactt::output_instruction(char prefix,
826+
const goto_programt &goto_program,
827+
const namespacet &ns,
828+
const irep_idt &function,
829+
goto_programt::const_targett& target) const
830+
{
831+
if(compact_output)
832+
{
833+
if(prefix == ' ')
834+
return;
835+
const irep_idt &file=target->source_location.get_file();
836+
const irep_idt &line=target->source_location.get_line();
837+
if (!file.empty() && !line.empty())
838+
std::cout << prefix << " " << id2string(file)
839+
<< " " << id2string(line) << std::endl;
840+
} else
841+
{
795842
std::cout << prefix;
796-
goto_program.output_instruction(o_ns, function, std::cout, o_target);
843+
goto_program.output_instruction(ns, function, std::cout, target);
797844
}
798845
}
799846

@@ -811,8 +858,10 @@ Function: change_impact
811858

812859
void change_impact(
813860
const goto_modelt &model_old,
814-
const goto_modelt &model_new)
861+
const goto_modelt &model_new,
862+
impact_modet impact_mode,
863+
bool compact_output)
815864
{
816-
change_impactt c(model_old, model_new);
865+
change_impactt c(model_old, model_new, impact_mode, compact_output);
817866
c();
818867
}

src/goto-diff/change_impact.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ Date: April 2016
1212
#define CPROVER_CHANGE_IMPACT_H
1313

1414
class goto_modelt;
15+
typedef enum {FORWARD, BACKWARD, BOTH} impact_modet;
1516

1617
void change_impact(
1718
const goto_modelt &model_old,
18-
const goto_modelt &model_new);
19+
const goto_modelt &model_new,
20+
impact_modet impact_mode,
21+
bool compact_output);
1922

2023
#endif

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Author: Peter Schrammel
3232
#include <goto-programs/string_instrumentation.h>
3333
#include <goto-programs/loop_ids.h>
3434
#include <goto-programs/link_to_library.h>
35+
#include <goto-programs/remove_returns.h>
3536

3637
#include <pointer-analysis/add_failed_symbols.h>
3738

@@ -330,14 +331,24 @@ int goto_diff_parse_optionst::doit()
330331
namespacet ns1(goto_model1.symbol_table);
331332
goto_model1.goto_functions.output(ns1, std::cout);
332333
std::cout << "*******************************************************\n";
333-
namespacet ns2(goto_model1.symbol_table);
334+
namespacet ns2(goto_model2.symbol_table);
334335
goto_model2.goto_functions.output(ns2, std::cout);
335336
return 0;
336337
}
337338

338-
if(cmdline.isset("change-impact"))
339+
if(cmdline.isset("change-impact") ||
340+
cmdline.isset("forward-impact")||
341+
cmdline.isset("backward-impact"))
339342
{
340-
change_impact(goto_model1, goto_model2);
343+
//Workaround to avoid deps not propagating between return and end_func
344+
remove_returns(goto_model1);
345+
remove_returns(goto_model2);
346+
347+
impact_modet impact_mode =
348+
cmdline.isset("forward-impact") ?
349+
FORWARD : (cmdline.isset("backward-impact") ? BACKWARD : BOTH);
350+
change_impact(goto_model1, goto_model2, impact_mode,
351+
cmdline.isset("compact-output"));
341352
return 0;
342353
}
343354

@@ -536,7 +547,10 @@ void goto_diff_parse_optionst::help()
536547
" --show-functions show functions (default)\n"
537548
" --syntactic do syntactic diff (default)\n"
538549
" -u | --unified output unified diff\n"
539-
" --change-impact output unified diff with dependencies\n"
550+
" --change-impact | \n"
551+
" --forward-impact |\n"
552+
" --backward-impact output unified diff with forward&backward/forward/backward dependencies\n"
553+
" --compact-output output dependencies in compact mode\n"
540554
"\n"
541555
"Other options:\n"
542556
" --version show version and exit\n"

src/goto-diff/goto_diff_parse_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class optionst;
2323
"(json-ui)" \
2424
"(show-goto-functions)" \
2525
"(verbosity):(version)" \
26-
"u(unified)(change-impact)"
26+
"u(unified)(change-impact)(forward-impact)(backward-impact)" \
27+
"(compact-output)"
2728

2829
class goto_diff_parse_optionst:
2930
public parse_options_baset,

0 commit comments

Comments
 (0)