Skip to content

Commit 6b12425

Browse files
committed
Invert is_assign check
To reduce indentation and make it clear that this check filters which instructions the loop operates on.
1 parent d7776db commit 6b12425

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/goto-programs/mm_io.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,64 +45,64 @@ void mm_io(
4545
it!=goto_function.body.instructions.end();
4646
it++)
4747
{
48+
if(!it->is_assign())
49+
continue;
50+
4851
std::set<dereference_exprt> deref_expr_w, deref_expr_r;
4952

50-
if(it->is_assign())
51-
{
52-
auto &a_lhs = it->assign_lhs();
53-
auto &a_rhs = it->assign_rhs_nonconst();
54-
collect_deref_expr(a_rhs, deref_expr_r);
53+
auto &a_lhs = it->assign_lhs();
54+
auto &a_rhs = it->assign_rhs_nonconst();
55+
collect_deref_expr(a_rhs, deref_expr_r);
5556

56-
if(mm_io_r.is_not_nil())
57+
if(mm_io_r.is_not_nil())
58+
{
59+
if(deref_expr_r.size() == 1)
5760
{
58-
if(deref_expr_r.size()==1)
59-
{
60-
const dereference_exprt &d=*deref_expr_r.begin();
61-
source_locationt source_location = it->source_location();
62-
const code_typet &ct=to_code_type(mm_io_r.type());
63-
64-
if_exprt if_expr(
65-
integer_address(d.pointer()),
66-
typecast_exprt::conditional_cast(mm_io_r_value, d.type()),
67-
d);
68-
replace_expr(d, if_expr, a_rhs);
69-
70-
const typet &pt=ct.parameters()[0].type();
71-
const typet &st=ct.parameters()[1].type();
72-
auto size_opt = size_of_expr(d.type(), ns);
73-
CHECK_RETURN(size_opt.has_value());
74-
auto call = goto_programt::make_function_call(
75-
mm_io_r_value,
76-
mm_io_r,
77-
{typecast_exprt(d.pointer(), pt),
78-
typecast_exprt(size_opt.value(), st)},
79-
source_location);
80-
goto_function.body.insert_before_swap(it, call);
81-
it++;
82-
}
61+
const dereference_exprt &d = *deref_expr_r.begin();
62+
source_locationt source_location = it->source_location();
63+
const code_typet &ct = to_code_type(mm_io_r.type());
64+
65+
if_exprt if_expr(
66+
integer_address(d.pointer()),
67+
typecast_exprt::conditional_cast(mm_io_r_value, d.type()),
68+
d);
69+
replace_expr(d, if_expr, a_rhs);
70+
71+
const typet &pt = ct.parameters()[0].type();
72+
const typet &st = ct.parameters()[1].type();
73+
auto size_opt = size_of_expr(d.type(), ns);
74+
CHECK_RETURN(size_opt.has_value());
75+
auto call = goto_programt::make_function_call(
76+
mm_io_r_value,
77+
mm_io_r,
78+
{typecast_exprt(d.pointer(), pt),
79+
typecast_exprt(size_opt.value(), st)},
80+
source_location);
81+
goto_function.body.insert_before_swap(it, call);
82+
it++;
8383
}
84+
}
8485

85-
if(mm_io_w.is_not_nil())
86+
if(mm_io_w.is_not_nil())
87+
{
88+
if(a_lhs.id() == ID_dereference)
8689
{
87-
if(a_lhs.id() == ID_dereference)
88-
{
89-
const dereference_exprt &d = to_dereference_expr(a_lhs);
90-
source_locationt source_location = it->source_location();
91-
const code_typet &ct=to_code_type(mm_io_w.type());
92-
const typet &pt=ct.parameters()[0].type();
93-
const typet &st=ct.parameters()[1].type();
94-
const typet &vt=ct.parameters()[2].type();
95-
auto size_opt = size_of_expr(d.type(), ns);
96-
CHECK_RETURN(size_opt.has_value());
97-
const code_function_callt fc(
98-
mm_io_w,
99-
{typecast_exprt(d.pointer(), pt),
100-
typecast_exprt(size_opt.value(), st),
101-
typecast_exprt(a_rhs, vt)});
102-
goto_function.body.insert_before_swap(it);
103-
*it = goto_programt::make_function_call(fc, source_location);
104-
it++;
105-
}
90+
const dereference_exprt &d = to_dereference_expr(a_lhs);
91+
source_locationt source_location = it->source_location();
92+
const code_typet &ct = to_code_type(mm_io_w.type());
93+
const typet &pt = ct.parameters()[0].type();
94+
const typet &st = ct.parameters()[1].type();
95+
const typet &vt = ct.parameters()[2].type();
96+
auto size_opt = size_of_expr(d.type(), ns);
97+
CHECK_RETURN(size_opt.has_value());
98+
const code_function_callt fc(
99+
mm_io_w,
100+
{typecast_exprt(d.pointer(), pt),
101+
typecast_exprt(size_opt.value(), st),
102+
typecast_exprt(a_rhs, vt)});
103+
goto_function.body.insert_before_swap(it);
104+
*it = goto_programt::make_function_call(fc, source_location);
105+
it++;
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)