@@ -13,6 +13,7 @@ Date: April 2017
1313
1414#include " mm_io.h"
1515
16+ #include < util/fresh_symbol.h>
1617#include < util/pointer_expr.h>
1718#include < util/pointer_offset_size.h>
1819#include < util/pointer_predicates.h>
@@ -35,6 +36,7 @@ void collect_deref_expr(
3536
3637void mm_io (
3738 const exprt &mm_io_r,
39+ const exprt &mm_io_r_value,
3840 const exprt &mm_io_w,
3941 goto_functionst::goto_functiont &goto_function,
4042 const namespacet &ns)
@@ -60,21 +62,20 @@ void mm_io(
6062 source_locationt source_location = it->source_location ();
6163 const code_typet &ct=to_code_type (mm_io_r.type ());
6264
63- irep_idt identifier=to_symbol_expr (mm_io_r).get_identifier ();
64- auto return_value = return_value_symbol (identifier, ns);
65- if_exprt if_expr (integer_address (d.pointer ()), return_value, d);
65+ if_exprt if_expr (integer_address (d.pointer ()), mm_io_r_value, d);
6666 replace_expr (d, if_expr, a_rhs);
6767
6868 const typet &pt=ct.parameters ()[0 ].type ();
6969 const typet &st=ct.parameters ()[1 ].type ();
7070 auto size_opt = size_of_expr (d.type (), ns);
7171 CHECK_RETURN (size_opt.has_value ());
72- const code_function_callt fc (
72+ auto call = goto_programt::make_function_call (
73+ mm_io_r_value,
7374 mm_io_r,
7475 {typecast_exprt (d.pointer (), pt),
75- typecast_exprt (size_opt.value (), st)});
76- goto_function. body . insert_before_swap (it );
77- *it = goto_programt::make_function_call (fc, source_location );
76+ typecast_exprt (size_opt.value (), st)},
77+ source_location );
78+ goto_function. body . insert_before_swap (it, call );
7879 it++;
7980 }
8081 }
@@ -105,26 +106,37 @@ void mm_io(
105106 }
106107}
107108
108- void mm_io (
109- const symbol_tablet &symbol_table,
110- goto_functionst &goto_functions)
109+ void mm_io (symbol_tablet &symbol_table, goto_functionst &goto_functions)
111110{
112111 const namespacet ns (symbol_table);
113- exprt mm_io_r=nil_exprt (), mm_io_w=nil_exprt ();
112+ exprt mm_io_r = nil_exprt (), mm_io_r_value = nil_exprt (),
113+ mm_io_w = nil_exprt ();
114114
115115 irep_idt id_r=CPROVER_PREFIX " mm_io_r" ;
116116 irep_idt id_w=CPROVER_PREFIX " mm_io_w" ;
117117
118118 auto maybe_symbol=symbol_table.lookup (id_r);
119119 if (maybe_symbol)
120+ {
120121 mm_io_r=maybe_symbol->symbol_expr ();
121122
123+ const auto &value_symbol = get_fresh_aux_symbol (
124+ to_code_type (mm_io_r.type ()).return_type (),
125+ id2string (id_r) + " $value" ,
126+ id2string (id_r) + " $value" ,
127+ maybe_symbol->location ,
128+ maybe_symbol->mode ,
129+ symbol_table);
130+
131+ mm_io_r_value = value_symbol.symbol_expr ();
132+ }
133+
122134 maybe_symbol=symbol_table.lookup (id_w);
123135 if (maybe_symbol)
124136 mm_io_w=maybe_symbol->symbol_expr ();
125137
126138 for (auto & f : goto_functions.function_map )
127- mm_io (mm_io_r, mm_io_w, f.second , ns);
139+ mm_io (mm_io_r, mm_io_r_value, mm_io_w, f.second , ns);
128140}
129141
130142void mm_io (goto_modelt &model)
0 commit comments