Skip to content

Commit 0e911d4

Browse files
Extract convert_if function
1 parent 651246e commit 0e911d4

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+22-15
Original file line numberDiff line numberDiff line change
@@ -1590,25 +1590,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
15901590
irep_idt();
15911591

15921592
INVARIANT(!id.empty(), "unexpected bytecode-if");
1593-
15941593
PRECONDITION(op.size() == 1 && results.empty());
15951594
mp_integer number;
15961595
bool ret=to_integer(to_constant_expr(arg0), number);
15971596
INVARIANT(!ret, "if?? argument should be an integer");
1598-
1599-
code_ifthenelset code_branch;
1600-
code_branch.cond()=
1601-
binary_relation_exprt(op[0], id, from_integer(0, op[0].type()));
1602-
code_branch.cond().add_source_location()=i_it->source_location;
1603-
code_branch.cond().add_source_location().set_function(method_id);
1604-
code_branch.then_case()=code_gotot(label(integer2string(number)));
1605-
code_branch.then_case().add_source_location()=
1606-
address_map.at(integer2unsigned(number)).source->source_location;
1607-
code_branch.then_case().add_source_location().set_function(method_id);
1608-
code_branch.add_source_location()=i_it->source_location;
1609-
code_branch.add_source_location().set_function(method_id);
1610-
1611-
c=code_branch;
1597+
c = convert_if(address_map, op, id, number, i_it->source_location);
16121598
}
16131599
else if(statement==patternt("ifnonnull"))
16141600
{
@@ -2575,6 +2561,27 @@ codet java_bytecode_convert_methodt::convert_instructions(
25752561
return code;
25762562
}
25772563

2564+
codet java_bytecode_convert_methodt::convert_if(
2565+
const java_bytecode_convert_methodt::address_mapt &address_map,
2566+
const exprt::operandst &op,
2567+
const irep_idt &id,
2568+
const mp_integer &number,
2569+
const source_locationt &location) const
2570+
{
2571+
code_ifthenelset code_branch;
2572+
code_branch.cond() =
2573+
binary_relation_exprt(op[0], id, from_integer(0, op[0].type()));
2574+
code_branch.cond().add_source_location() = location;
2575+
code_branch.cond().add_source_location().set_function(method_id);
2576+
code_branch.then_case() = code_gotot(label(integer2string(number)));
2577+
code_branch.then_case().add_source_location() =
2578+
address_map.at(integer2unsigned(number)).source->source_location;
2579+
code_branch.then_case().add_source_location().set_function(method_id);
2580+
code_branch.add_source_location() = location;
2581+
code_branch.add_source_location().set_function(method_id);
2582+
return code_branch;
2583+
}
2584+
25782585
codet java_bytecode_convert_methodt::convert_if_cmp(
25792586
const java_bytecode_convert_methodt::address_mapt &address_map,
25802587
const irep_idt &statement,

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class java_bytecode_convert_methodt:public messaget
324324
const irep_idt &statement,
325325
const exprt &arg0,
326326
const exprt::operandst &op,
327-
unsigned address,
327+
const unsigned address,
328328
const source_locationt &location);
329329

330330
exprt
@@ -334,7 +334,7 @@ class java_bytecode_convert_methodt:public messaget
334334
const std::vector<unsigned int> &jsr_ret_targets,
335335
const exprt &arg0,
336336
const source_locationt &location,
337-
unsigned address);
337+
const unsigned address);
338338

339339
codet convert_if_cmp(
340340
const java_bytecode_convert_methodt::address_mapt &address_map,
@@ -343,4 +343,11 @@ class java_bytecode_convert_methodt:public messaget
343343
const mp_integer &number,
344344
const source_locationt &location) const;
345345

346+
codet convert_if(
347+
const java_bytecode_convert_methodt::address_mapt &address_map,
348+
const exprt::operandst &op,
349+
const irep_idt &id,
350+
const mp_integer &number,
351+
const source_locationt &location) const;
352+
};
346353
#endif

0 commit comments

Comments
 (0)