Skip to content

Commit fc95df1

Browse files
Extract convert_ret function
1 parent ce58dca commit fc95df1

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+33-24
Original file line numberDiff line numberDiff line change
@@ -1514,31 +1514,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
15141514
// and write something like:
15151515
// if(retaddr==5) goto 5; else if(retaddr==10) goto 10; ...
15161516
PRECONDITION(op.empty() && results.empty());
1517-
c=code_blockt();
1518-
auto retvar=variable(arg0, 'a', i_it->address, NO_CAST);
15191517
assert(!jsr_ret_targets.empty());
1520-
for(size_t idx=0, idxlim=jsr_ret_targets.size(); idx!=idxlim; ++idx)
1521-
{
1522-
irep_idt number=std::to_string(jsr_ret_targets[idx]);
1523-
code_gotot g(label(number));
1524-
g.add_source_location()=i_it->source_location;
1525-
if(idx==idxlim-1)
1526-
c.move_to_operands(g);
1527-
else
1528-
{
1529-
code_ifthenelset branch;
1530-
auto address_ptr=
1531-
from_integer(
1532-
jsr_ret_targets[idx],
1533-
unsignedbv_typet(64));
1534-
address_ptr.type()=pointer_type(void_typet());
1535-
branch.cond()=equal_exprt(retvar, address_ptr);
1536-
branch.cond().add_source_location()=i_it->source_location;
1537-
branch.then_case()=g;
1538-
branch.add_source_location()=i_it->source_location;
1539-
c.move_to_operands(branch);
1540-
}
1541-
}
1518+
c = convert_ret(
1519+
jsr_ret_targets, arg0, i_it->source_location, i_it->address);
15421520
}
15431521
else if(statement=="iconst_m1")
15441522
{
@@ -2615,6 +2593,37 @@ codet java_bytecode_convert_methodt::convert_instructions(
26152593
return code;
26162594
}
26172595

2596+
code_blockt java_bytecode_convert_methodt::convert_ret(
2597+
const std::vector<unsigned int> &jsr_ret_targets,
2598+
const exprt &arg0,
2599+
const source_locationt &location,
2600+
const unsigned address)
2601+
{
2602+
code_blockt c;
2603+
auto retvar = variable(arg0, 'a', address, NO_CAST);
2604+
for(size_t idx = 0, idxlim = jsr_ret_targets.size(); idx != idxlim; ++idx)
2605+
{
2606+
irep_idt number = std::to_string(jsr_ret_targets[idx]);
2607+
code_gotot g(label(number));
2608+
g.add_source_location() = location;
2609+
if(idx == idxlim - 1)
2610+
c.move_to_operands(g);
2611+
else
2612+
{
2613+
code_ifthenelset branch;
2614+
auto address_ptr =
2615+
from_integer(jsr_ret_targets[idx], unsignedbv_typet(64));
2616+
address_ptr.type() = pointer_type(void_typet());
2617+
branch.cond() = equal_exprt(retvar, address_ptr);
2618+
branch.cond().add_source_location() = location;
2619+
branch.then_case() = g;
2620+
branch.add_source_location() = location;
2621+
c.move_to_operands(branch);
2622+
}
2623+
}
2624+
return c;
2625+
}
2626+
26182627
exprt java_bytecode_convert_methodt::convert_aload(
26192628
const irep_idt &statement,
26202629
const exprt::operandst &op) const

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+6
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ class java_bytecode_convert_methodt:public messaget
305305

306306
exprt
307307
convert_aload(const irep_idt &statement, const exprt::operandst &op) const;
308+
309+
code_blockt convert_ret(
310+
const std::vector<unsigned int> &jsr_ret_targets,
311+
const exprt &arg0,
312+
const source_locationt &location,
313+
unsigned address);
308314
};
309315

310316
#endif

0 commit comments

Comments
 (0)