Skip to content

Commit be87973

Browse files
authored
Merge pull request #4088 from diffblue/goto_programt_code_cleanup
use new goto_programt::instructiont API
2 parents f9c0f33 + c56dbfd commit be87973

File tree

15 files changed

+107
-104
lines changed

15 files changed

+107
-104
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ bool remove_exceptionst::instrument_function_call(
432432
goto_programt::targett next_it=instr_it;
433433
next_it++;
434434

435-
code_function_callt &function_call=to_code_function_call(instr_it->code);
435+
code_function_callt &function_call = instr_it->get_function_call();
436436
DATA_INVARIANT(
437437
function_call.function().id()==ID_symbol,
438438
"identified expected to be a symbol");
@@ -493,7 +493,7 @@ void remove_exceptionst::instrument_exceptions(
493493
{
494494
if(instr_it->is_decl())
495495
{
496-
code_declt decl=to_code_decl(instr_it->code);
496+
code_declt decl = instr_it->get_decl();
497497
locals.push_back(decl.symbol());
498498
}
499499
// Is it a handler push/pop or catch landing-pad?

src/assembler/remove_asm.cpp

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ void remove_asmt::gcc_asm_function_call(
107107

108108
code_function_callt function_call(std::move(fkt), std::move(arguments));
109109

110-
goto_programt::targett call = dest.add_instruction(FUNCTION_CALL);
111-
call->code = function_call;
112-
call->source_location = code.source_location();
110+
dest.add(
111+
goto_programt::make_function_call(function_call, code.source_location()));
113112

114113
// do we have it?
115114
if(!symbol_table.has_symbol(function_identifier))
@@ -157,9 +156,8 @@ void remove_asmt::msc_asm_function_call(
157156

158157
code_function_callt function_call(fkt);
159158

160-
goto_programt::targett call = dest.add_instruction(FUNCTION_CALL);
161-
call->code = function_call;
162-
call->source_location = code.source_location();
159+
dest.add(
160+
goto_programt::make_function_call(function_call, code.source_location()));
163161

164162
// do we have it?
165163
if(!symbol_table.has_symbol(function_identifier))
@@ -194,7 +192,7 @@ void remove_asmt::process_instruction(
194192
goto_programt::instructiont &instruction,
195193
goto_programt &dest)
196194
{
197-
const code_asmt &code = to_code_asm(instruction.code);
195+
const code_asmt &code = to_code_asm(instruction.get_other());
198196

199197
const irep_idt &flavor = code.get_flavor();
200198

@@ -271,14 +269,15 @@ void remove_asmt::process_instruction_gcc(
271269
goto_programt::targett ab = tmp_dest.add_instruction(ATOMIC_BEGIN);
272270
ab->source_location = code.source_location();
273271

274-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
275-
t->source_location = code.source_location();
276-
t->code = codet(ID_fence);
277-
t->code.add_source_location() = code.source_location();
278-
t->code.set(ID_WWfence, true);
279-
t->code.set(ID_RRfence, true);
280-
t->code.set(ID_RWfence, true);
281-
t->code.set(ID_WRfence, true);
272+
codet code_fence(ID_fence);
273+
code_fence.add_source_location() = code.source_location();
274+
code_fence.set(ID_WWfence, true);
275+
code_fence.set(ID_RRfence, true);
276+
code_fence.set(ID_RWfence, true);
277+
code_fence.set(ID_WRfence, true);
278+
279+
tmp_dest.add(
280+
goto_programt::make_other(code_fence, code.source_location()));
282281
}
283282

284283
if(command == "fstcw" || command == "fnstcw" || command == "fldcw") // x86
@@ -292,62 +291,67 @@ void remove_asmt::process_instruction_gcc(
292291
}
293292
else if(command == ID_sync) // Power
294293
{
295-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
296-
t->source_location = code.source_location();
297-
t->code = codet(ID_fence);
298-
t->code.add_source_location() = code.source_location();
299-
t->code.set(ID_WWfence, true);
300-
t->code.set(ID_RRfence, true);
301-
t->code.set(ID_RWfence, true);
302-
t->code.set(ID_WRfence, true);
303-
t->code.set(ID_WWcumul, true);
304-
t->code.set(ID_RWcumul, true);
305-
t->code.set(ID_RRcumul, true);
306-
t->code.set(ID_WRcumul, true);
294+
codet code_fence(ID_fence);
295+
code_fence.add_source_location() = code.source_location();
296+
code_fence.set(ID_WWfence, true);
297+
code_fence.set(ID_RRfence, true);
298+
code_fence.set(ID_RWfence, true);
299+
code_fence.set(ID_WRfence, true);
300+
code_fence.set(ID_WWcumul, true);
301+
code_fence.set(ID_RWcumul, true);
302+
code_fence.set(ID_RRcumul, true);
303+
code_fence.set(ID_WRcumul, true);
304+
305+
tmp_dest.add(
306+
goto_programt::make_other(code_fence, code.source_location()));
307307
}
308308
else if(command == ID_lwsync) // Power
309309
{
310-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
311-
t->source_location = code.source_location();
312-
t->code = codet(ID_fence);
313-
t->code.add_source_location() = code.source_location();
314-
t->code.set(ID_WWfence, true);
315-
t->code.set(ID_RRfence, true);
316-
t->code.set(ID_RWfence, true);
317-
t->code.set(ID_WWcumul, true);
318-
t->code.set(ID_RWcumul, true);
319-
t->code.set(ID_RRcumul, true);
310+
codet code_fence(ID_fence);
311+
code_fence.add_source_location() = code.source_location();
312+
code_fence.set(ID_WWfence, true);
313+
code_fence.set(ID_RRfence, true);
314+
code_fence.set(ID_RWfence, true);
315+
code_fence.set(ID_WWcumul, true);
316+
code_fence.set(ID_RWcumul, true);
317+
code_fence.set(ID_RRcumul, true);
318+
319+
tmp_dest.add(
320+
goto_programt::make_other(code_fence, code.source_location()));
320321
}
321322
else if(command == ID_isync) // Power
322323
{
323-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
324-
t->source_location = code.source_location();
325-
t->code = codet(ID_fence);
326-
t->code.add_source_location() = code.source_location();
324+
codet code_fence(ID_fence);
325+
code_fence.add_source_location() = code.source_location();
326+
327+
tmp_dest.add(
328+
goto_programt::make_other(code_fence, code.source_location()));
327329
// doesn't do anything by itself,
328330
// needs to be combined with branch
329331
}
330332
else if(command == "dmb" || command == "dsb") // ARM
331333
{
332-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
333-
t->source_location = code.source_location();
334-
t->code = codet(ID_fence);
335-
t->code.add_source_location() = code.source_location();
336-
t->code.set(ID_WWfence, true);
337-
t->code.set(ID_RRfence, true);
338-
t->code.set(ID_RWfence, true);
339-
t->code.set(ID_WRfence, true);
340-
t->code.set(ID_WWcumul, true);
341-
t->code.set(ID_RWcumul, true);
342-
t->code.set(ID_RRcumul, true);
343-
t->code.set(ID_WRcumul, true);
334+
codet code_fence(ID_fence);
335+
code_fence.add_source_location() = code.source_location();
336+
code_fence.set(ID_WWfence, true);
337+
code_fence.set(ID_RRfence, true);
338+
code_fence.set(ID_RWfence, true);
339+
code_fence.set(ID_WRfence, true);
340+
code_fence.set(ID_WWcumul, true);
341+
code_fence.set(ID_RWcumul, true);
342+
code_fence.set(ID_RRcumul, true);
343+
code_fence.set(ID_WRcumul, true);
344+
345+
tmp_dest.add(
346+
goto_programt::make_other(code_fence, code.source_location()));
344347
}
345348
else if(command == "isb") // ARM
346349
{
347-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
348-
t->source_location = code.source_location();
349-
t->code = codet(ID_fence);
350-
t->code.add_source_location() = code.source_location();
350+
codet code_fence(ID_fence);
351+
code_fence.add_source_location() = code.source_location();
352+
353+
tmp_dest.add(
354+
goto_programt::make_other(code_fence, code.source_location()));
351355
// doesn't do anything by itself,
352356
// needs to be combined with branch
353357
}
@@ -436,14 +440,15 @@ void remove_asmt::process_instruction_msc(
436440
goto_programt::targett ab = tmp_dest.add_instruction(ATOMIC_BEGIN);
437441
ab->source_location = code.source_location();
438442

439-
goto_programt::targett t = tmp_dest.add_instruction(OTHER);
440-
t->source_location = code.source_location();
441-
t->code = codet(ID_fence);
442-
t->code.add_source_location() = code.source_location();
443-
t->code.set(ID_WWfence, true);
444-
t->code.set(ID_RRfence, true);
445-
t->code.set(ID_RWfence, true);
446-
t->code.set(ID_WRfence, true);
443+
codet code_fence(ID_fence);
444+
code_fence.add_source_location() = code.source_location();
445+
code_fence.set(ID_WWfence, true);
446+
code_fence.set(ID_RRfence, true);
447+
code_fence.set(ID_RWfence, true);
448+
code_fence.set(ID_WRfence, true);
449+
450+
tmp_dest.add(
451+
goto_programt::make_other(code_fence, code.source_location()));
447452
}
448453

449454
if(command == "fstcw" || command == "fnstcw" || command == "fldcw") // x86

src/goto-analyzer/static_simplifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool static_simplifier(
9595
}
9696
else if(i_it->is_assign())
9797
{
98-
code_assignt &assign=to_code_assign(i_it->code);
98+
code_assignt &assign = i_it->get_assign();
9999

100100
// Simplification needs to be aware of which side of the
101101
// expression it is handling as:
@@ -115,7 +115,7 @@ bool static_simplifier(
115115
}
116116
else if(i_it->is_function_call())
117117
{
118-
code_function_callt &fcall=to_code_function_call(i_it->code);
118+
code_function_callt &fcall = i_it->get_function_call();
119119

120120
bool unchanged =
121121
ai.abstract_state_before(i_it)->ai_simplify(fcall.function(), ns);

src/goto-analyzer/taint_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ void taint_analysist::instrument(
7373
{
7474
case FUNCTION_CALL:
7575
{
76-
const code_function_callt &function_call=
77-
to_code_function_call(instruction.code);
76+
const code_function_callt &function_call =
77+
instruction.get_function_call();
7878
const exprt &function=function_call.function();
7979

8080
if(function.id()==ID_symbol)

src/goto-instrument/accelerate/accelerate.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ void acceleratet::make_overflow_loc(
257257
}
258258

259259
goto_programt::targett t=program.insert_after(loop_header);
260-
t->make_assignment();
261-
t->code=code_assignt(overflow_var, false_exprt());
260+
*t =
261+
goto_programt::make_assignment(code_assignt(overflow_var, false_exprt()));
262262
t->swap(*loop_header);
263263
loop.insert(t);
264264
overflow_locs[loop_header].push_back(t);
@@ -360,8 +360,8 @@ void acceleratet::add_dirty_checks()
360360
it!=dirty_vars_map.end();
361361
++it)
362362
{
363-
goto_programt::instructiont assign(ASSIGN);
364-
assign.code=code_assignt(it->second, false_exprt());
363+
goto_programt::instructiont assign =
364+
goto_programt::make_assignment(code_assignt(it->second, false_exprt()));
365365
program.insert_before_swap(program.instructions.begin(), assign);
366366
}
367367

@@ -384,8 +384,8 @@ void acceleratet::add_dirty_checks()
384384

385385
if(dirty_var!=dirty_vars_map.end())
386386
{
387-
goto_programt::instructiont clear_flag(ASSIGN);
388-
clear_flag.code=code_assignt(dirty_var->second, false_exprt());
387+
goto_programt::instructiont clear_flag = goto_programt::make_assignment(
388+
code_assignt(dirty_var->second, false_exprt()));
389389
program.insert_before_swap(it, clear_flag);
390390
}
391391
}

src/goto-instrument/count_eloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void print_global_state_size(const goto_modelt &goto_model)
164164
{
165165
if(ins.is_assign())
166166
{
167-
const code_assignt &code_assign = to_code_assign(ins.code);
167+
const code_assignt &code_assign = ins.get_assign();
168168
object_descriptor_exprt ode;
169169
ode.build(code_assign.lhs(), ns);
170170

src/goto-programs/cfg.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ void cfg_baset<T, P, I>::compute_edges_function_call(
288288
goto_programt::const_targett next_PC,
289289
entryt &entry)
290290
{
291-
const exprt &function=
292-
to_code_function_call(instruction.code).function();
291+
const exprt &function = instruction.get_function_call().function();
293292

294293
if(function.id()!=ID_symbol)
295294
return;
@@ -339,8 +338,7 @@ void procedure_local_cfg_baset<T, P, I>::compute_edges_function_call(
339338
goto_programt::const_targett next_PC,
340339
typename cfg_baset<T, P, I>::entryt &entry)
341340
{
342-
const exprt &function=
343-
to_code_function_call(instruction.code).function();
341+
const exprt &function = instruction.get_function_call().function();
344342

345343
if(function.id()!=ID_symbol)
346344
return;

src/goto-programs/goto_program.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,11 @@ class goto_programt
826826
static_cast<const codet &>(get_nil_irep()), l, ASSUME, g, {});
827827
}
828828

829-
static instructiont make_other(const codet &_code)
829+
static instructiont make_other(
830+
const codet &_code,
831+
const source_locationt &l = source_locationt::nil())
830832
{
831-
return instructiont(_code, source_locationt::nil(), OTHER, nil_exprt(), {});
833+
return instructiont(_code, l, OTHER, nil_exprt(), {});
832834
}
833835

834836
static instructiont make_decl(

src/goto-symex/symex_dead.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void goto_symext::symex_dead(statet &state)
2121
{
2222
const goto_programt::instructiont &instruction=*state.source.pc;
2323

24-
const code_deadt &code = to_code_dead(instruction.code);
24+
const code_deadt &code = instruction.get_dead();
2525

2626
// We increase the L2 renaming to make these non-deterministic.
2727
// We also prevent propagation of old values.

src/goto-symex/symex_decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ void goto_symext::symex_decl(statet &state)
2323
{
2424
const goto_programt::instructiont &instruction=*state.source.pc;
2525

26-
const codet &code = instruction.code;
26+
const auto &code = instruction.get_decl();
2727

2828
// two-operand decl not supported here
2929
// we handle the decl with only one operand
3030
PRECONDITION(code.operands().size() == 1);
3131

32-
symex_decl(state, to_code_decl(code).symbol());
32+
symex_decl(state, code.symbol());
3333
}
3434

3535
void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)

0 commit comments

Comments
 (0)