Skip to content

Commit a2430a9

Browse files
author
Daniel Kroening
committed
remove_java_new now takes function identifier
1 parent 71353e8 commit a2430a9

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,29 @@ class remove_java_newt : public messaget
3333
}
3434

3535
// Lower java_new for a single function
36-
bool lower_java_new(goto_programt &);
36+
bool lower_java_new(
37+
const irep_idt &function_identifier,
38+
goto_programt &);
3739

3840
// Lower java_new for a single instruction
3941
goto_programt::targett
40-
lower_java_new(goto_programt &, goto_programt::targett);
42+
lower_java_new(
43+
const irep_idt &function_identifier,
44+
goto_programt &, goto_programt::targett);
4145

4246
protected:
4347
symbol_table_baset &symbol_table;
4448
namespacet ns;
4549

4650
goto_programt::targett lower_java_new(
51+
const irep_idt &function_identifier,
4752
exprt lhs,
4853
side_effect_exprt rhs,
4954
goto_programt &,
5055
goto_programt::targett);
5156

5257
goto_programt::targett lower_java_new_array(
58+
const irep_idt &function_identifier,
5359
exprt lhs,
5460
side_effect_exprt rhs,
5561
goto_programt &,
@@ -68,6 +74,7 @@ class remove_java_newt : public messaget
6874
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
6975
/// destruction when replacing the instruction.
7076
goto_programt::targett remove_java_newt::lower_java_new(
77+
const irep_idt &function_identifier,
7178
exprt lhs,
7279
side_effect_exprt rhs,
7380
goto_programt &dest,
@@ -116,6 +123,7 @@ goto_programt::targett remove_java_newt::lower_java_new(
116123
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
117124
/// destruction when replacing the instruction.
118125
goto_programt::targett remove_java_newt::lower_java_new_array(
126+
const irep_idt &function_identifier,
119127
exprt lhs,
120128
side_effect_exprt rhs,
121129
goto_programt &dest,
@@ -206,7 +214,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
206214
// `x=typecast_exprt(side_effect_exprt(...))`
207215
symbol_exprt new_array_data_symbol = get_fresh_aux_symbol(
208216
data_java_new_expr.type(),
209-
id2string(target->function),
217+
id2string(function_identifier),
210218
"tmp_new_data_array",
211219
location,
212220
ID_java,
@@ -253,7 +261,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
253261

254262
symbol_exprt tmp_i = get_fresh_aux_symbol(
255263
length.type(),
256-
id2string(target->function),
264+
id2string(function_identifier),
257265
"tmp_index",
258266
location,
259267
ID_java,
@@ -287,7 +295,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
287295
code_blockt for_body;
288296
symbol_exprt init_sym = get_fresh_aux_symbol(
289297
sub_type,
290-
id2string(target->function),
298+
id2string(function_identifier),
291299
"subarray_init",
292300
location,
293301
ID_java,
@@ -311,7 +319,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
311319
goto_convert(for_loop, symbol_table, tmp, get_message_handler(), ID_java);
312320

313321
// lower new side effects recursively
314-
lower_java_new(tmp);
322+
lower_java_new(function_identifier, tmp);
315323

316324
dest.destructive_insert(next, tmp);
317325
}
@@ -325,6 +333,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
325333
/// \param target: instruction to check for java_new expressions
326334
/// \return true if a replacement has been made
327335
goto_programt::targett remove_java_newt::lower_java_new(
336+
const irep_idt &function_identifier,
328337
goto_programt &goto_program,
329338
goto_programt::targett target)
330339
{
@@ -338,13 +347,13 @@ goto_programt::targett remove_java_newt::lower_java_new(
338347

339348
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new)
340349
{
341-
return lower_java_new(lhs, to_side_effect_expr(rhs), goto_program, target);
350+
return lower_java_new(function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
342351
}
343352

344353
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new_array)
345354
{
346355
return lower_java_new_array(
347-
lhs, to_side_effect_expr(rhs), goto_program, target);
356+
function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
348357
}
349358

350359
return target;
@@ -355,15 +364,17 @@ goto_programt::targett remove_java_newt::lower_java_new(
355364
/// Extra auxiliary variables may be introduced into symbol_table.
356365
/// \param goto_program: The function body to work on.
357366
/// \return true if one or more java_new expressions have been replaced
358-
bool remove_java_newt::lower_java_new(goto_programt &goto_program)
367+
bool remove_java_newt::lower_java_new(
368+
const irep_idt &function_identifier,
369+
goto_programt &goto_program)
359370
{
360371
bool changed = false;
361372
for(goto_programt::instructionst::iterator target =
362373
goto_program.instructions.begin();
363374
target != goto_program.instructions.end();
364375
++target)
365376
{
366-
goto_programt::targett new_target = lower_java_new(goto_program, target);
377+
goto_programt::targett new_target = lower_java_new(function_identifier, goto_program, target);
367378
changed = changed || new_target == target;
368379
target = new_target;
369380
}
@@ -381,13 +392,14 @@ bool remove_java_newt::lower_java_new(goto_programt &goto_program)
381392
/// \param symbol_table: The symbol table to add symbols to.
382393
/// \param message_handler: a message handler
383394
void remove_java_new(
395+
const irep_idt &function_identifier,
384396
goto_programt::targett target,
385397
goto_programt &goto_program,
386398
symbol_table_baset &symbol_table,
387399
message_handlert &message_handler)
388400
{
389401
remove_java_newt rem(symbol_table, message_handler);
390-
rem.lower_java_new(goto_program, target);
402+
rem.lower_java_new(function_identifier, goto_program, target);
391403
}
392404

393405
/// Replace every java_new or java_new_array by a malloc side-effect
@@ -397,12 +409,13 @@ void remove_java_new(
397409
/// \param symbol_table: The symbol table to add symbols to.
398410
/// \param message_handler: a message handler
399411
void remove_java_new(
412+
const irep_idt &function_identifier,
400413
goto_functionst::goto_functiont &function,
401414
symbol_table_baset &symbol_table,
402415
message_handlert &message_handler)
403416
{
404417
remove_java_newt rem(symbol_table, message_handler);
405-
rem.lower_java_new(function.body);
418+
rem.lower_java_new(function_identifier, function.body);
406419
}
407420

408421
/// Replace every java_new or java_new_array by a malloc side-effect
@@ -419,7 +432,7 @@ void remove_java_new(
419432
remove_java_newt rem(symbol_table, message_handler);
420433
bool changed = false;
421434
for(auto &f : goto_functions.function_map)
422-
changed = rem.lower_java_new(f.second.body) || changed;
435+
changed = rem.lower_java_new(f.first, f.second.body) || changed;
423436
if(changed)
424437
goto_functions.compute_location_numbers();
425438
}

jbmc/src/java_bytecode/remove_java_new.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Author: Peter Schrammel
2020
class message_handlert;
2121

2222
void remove_java_new(
23+
const irep_idt &function_identifier,
2324
goto_programt::targett target,
2425
goto_programt &goto_program,
2526
symbol_table_baset &symbol_table,
2627
message_handlert &_message_handler);
2728

2829
void remove_java_new(
30+
const irep_idt &function_identifier,
2931
goto_functionst::goto_functiont &function,
3032
symbol_table_baset &symbol_table,
3133
message_handlert &_message_handler);

0 commit comments

Comments
 (0)