Skip to content

Commit 5a5788c

Browse files
Extract convert_ushr function
1 parent 305ede8 commit 5a5788c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -1644,21 +1644,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
16441644
else if(statement==patternt("?ushr"))
16451645
{
16461646
PRECONDITION(op.size() == 2 && results.size() == 1);
1647-
const typet type=java_type_from_char(statement[0]);
1648-
1649-
const std::size_t width=type.get_size_t(ID_width);
1650-
typet target=unsignedbv_typet(width);
1651-
1652-
exprt lhs=op[0];
1653-
if(lhs.type()!=target)
1654-
lhs.make_typecast(target);
1655-
exprt rhs=op[1];
1656-
if(rhs.type()!=target)
1657-
rhs.make_typecast(target);
1658-
1659-
results[0]=lshr_exprt(lhs, rhs);
1660-
if(results[0].type()!=op[0].type())
1661-
results[0].make_typecast(op[0].type());
1647+
results = convert_ushr(statement, op, results);
16621648
}
16631649
else if(statement==patternt("?add"))
16641650
{
@@ -2522,6 +2508,29 @@ codet java_bytecode_convert_methodt::convert_instructions(
25222508
return code;
25232509
}
25242510

2511+
exprt::operandst &java_bytecode_convert_methodt::convert_ushr(
2512+
const irep_idt &statement,
2513+
const exprt::operandst &op,
2514+
exprt::operandst &results) const
2515+
{
2516+
const typet type = java_type_from_char(statement[0]);
2517+
2518+
const std::size_t width = type.get_size_t(ID_width);
2519+
typet target = unsignedbv_typet(width);
2520+
2521+
exprt lhs = op[0];
2522+
if(lhs.type() != target)
2523+
lhs.make_typecast(target);
2524+
exprt rhs = op[1];
2525+
if(rhs.type() != target)
2526+
rhs.make_typecast(target);
2527+
2528+
results[0] = lshr_exprt(lhs, rhs);
2529+
if(results[0].type() != op[0].type())
2530+
results[0].make_typecast(op[0].type());
2531+
return results;
2532+
}
2533+
25252534
codet java_bytecode_convert_methodt::convert_iinc(
25262535
const exprt &arg0,
25272536
const exprt &arg1,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+5
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,10 @@ class java_bytecode_convert_methodt:public messaget
367367
const exprt &arg1,
368368
const source_locationt &location,
369369
unsigned address);
370+
371+
exprt::operandst &convert_ushr(
372+
const irep_idt &statement,
373+
const exprt::operandst &op,
374+
exprt::operandst &results) const;
370375
};
371376
#endif

0 commit comments

Comments
 (0)