@@ -239,11 +239,16 @@ class change_impactt
239
239
public:
240
240
change_impactt (
241
241
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);
243
245
244
246
void operator ()();
245
247
246
248
protected:
249
+ impact_modet impact_mode;
250
+ bool compact_output;
251
+
247
252
const goto_functionst &old_goto_functions;
248
253
const namespacet ns_old;
249
254
const goto_functionst &new_goto_functions;
@@ -301,6 +306,12 @@ class change_impactt
301
306
const goto_program_change_impactt &n_c_i,
302
307
const goto_functionst &n_goto_functions,
303
308
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 ;
304
315
};
305
316
306
317
/* ******************************************************************\
@@ -317,7 +328,11 @@ Function: change_impactt::change_impactt
317
328
318
329
change_impactt::change_impactt (
319
330
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),
321
336
old_goto_functions(model_old.goto_functions),
322
337
ns_old(model_old.symbol_table),
323
338
new_goto_functions(model_new.goto_functions),
@@ -425,8 +440,10 @@ void change_impactt::change_impact(
425
440
const dependence_grapht::nodet &d_node=
426
441
old_dep_graph[old_dep_graph[o_it].get_node_id ()];
427
442
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 );
430
447
}
431
448
old_impact[o_it]|=DELETED;
432
449
++o_it;
@@ -438,8 +455,10 @@ void change_impactt::change_impact(
438
455
const dependence_grapht::nodet &d_node=
439
456
new_dep_graph[new_dep_graph[n_it].get_node_id ()];
440
457
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 );
443
462
}
444
463
new_impact[n_it]|=NEW;
445
464
++n_it;
@@ -464,26 +483,25 @@ Function: change_impactt::propogate_dep_forward
464
483
void change_impactt::propogate_dep_forward (const dependence_grapht::nodet &d_node,
465
484
const dependence_grapht &dep_graph,
466
485
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 ;
486
490
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
+ }
487
505
}
488
506
489
507
/* ******************************************************************\
@@ -501,27 +519,28 @@ Function: change_impactt::propogate_dep_back
501
519
void change_impactt::propogate_dep_back (const dependence_grapht::nodet &d_node,
502
520
const dependence_grapht &dep_graph,
503
521
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
+ }
525
544
}
526
545
527
546
/* ******************************************************************\
@@ -629,7 +648,8 @@ void change_impactt::output_change_impact(
629
648
assert (f_it!=goto_functions.function_map .end ());
630
649
const goto_programt &goto_program=f_it->second .body ;
631
650
632
- std::cout << " /** " << function << " **/\n " ;
651
+ if (!compact_output)
652
+ std::cout << " /** " << function << " **/\n " ;
633
653
634
654
forall_goto_program_instructions (target, goto_program)
635
655
{
@@ -658,8 +678,7 @@ void change_impactt::output_change_impact(
658
678
else
659
679
assert (false );
660
680
661
- std::cout << prefix;
662
- goto_program.output_instruction (ns, function, std::cout, target);
681
+ output_instruction (prefix, goto_program, ns, function, target);
663
682
}
664
683
}
665
684
@@ -694,7 +713,8 @@ void change_impactt::output_change_impact(
694
713
assert (f_it!=n_goto_functions.function_map .end ());
695
714
const goto_programt &goto_program=f_it->second .body ;
696
715
697
- std::cout << " /** " << function << " **/\n " ;
716
+ if (!compact_output)
717
+ std::cout << " /** " << function << " **/\n " ;
698
718
699
719
goto_programt::const_targett o_target=
700
720
old_goto_program.instructions .begin ();
@@ -707,14 +727,9 @@ void change_impactt::output_change_impact(
707
727
708
728
if (old_mod_flags&DELETED)
709
729
{
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);
717
731
++o_target;
732
+ --target;
718
733
continue ;
719
734
}
720
735
@@ -764,8 +779,7 @@ void change_impactt::output_change_impact(
764
779
else
765
780
assert (false );
766
781
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);
769
783
}
770
784
for ( ;
771
785
o_target!=old_goto_program.instructions .end ();
@@ -792,8 +806,41 @@ void change_impactt::output_change_impact(
792
806
else
793
807
assert (false );
794
808
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
+ {
795
842
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 );
797
844
}
798
845
}
799
846
@@ -811,8 +858,10 @@ Function: change_impact
811
858
812
859
void change_impact (
813
860
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)
815
864
{
816
- change_impactt c (model_old, model_new);
865
+ change_impactt c (model_old, model_new, impact_mode, compact_output );
817
866
c ();
818
867
}
0 commit comments