Skip to content

Commit f74ea2e

Browse files
authored
Merge pull request #4579 from diffblue/instructiont-construction
instructiont construction
2 parents faf0a61 + 5f0962e commit f74ea2e

File tree

10 files changed

+107
-96
lines changed

10 files changed

+107
-96
lines changed

jbmc/unit/java_bytecode/goto-programs/remove_virtual_functions_without_fallback.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ SCENARIO(
124124
symbol_table.insert(test_program_symbol);
125125
namespacet ns(symbol_table);
126126

127-
goto_programt test_program;
128-
auto virtual_call_inst = test_program.add_instruction(FUNCTION_CALL);
129-
130127
const symbolt &callee_symbol =
131128
symbol_table.lookup_ref("java::VirtualFunctionsTestParent.f:()V");
132129

@@ -141,9 +138,12 @@ SCENARIO(
141138
// null pointer:
142139
{null_pointer_exprt(
143140
to_pointer_type(to_code_type(callee.type()).parameters()[0].type()))});
144-
virtual_call_inst->code = call;
145141

146-
test_program.add_instruction(END_FUNCTION);
142+
goto_programt test_program;
143+
auto virtual_call_inst =
144+
test_program.add(goto_programt::make_function_call(call));
145+
146+
test_program.add(goto_programt::make_end_function());
147147

148148
WHEN("Resolving virtual callsite to a single callee")
149149
{

src/analyses/goto_check.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,13 +1438,16 @@ void goto_checkt::add_guarded_claim(
14381438
goto_program_instruction_typet type=
14391439
enable_assert_to_assume?ASSUME:ASSERT;
14401440

1441-
goto_programt::targett t=new_code.add_instruction(type);
1441+
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1442+
static_cast<const codet &>(get_nil_irep()),
1443+
source_location,
1444+
type,
1445+
std::move(new_expr),
1446+
{}));
14421447

14431448
std::string source_expr_string;
14441449
get_language_from_mode(mode)->from_expr(src_expr, source_expr_string, ns);
14451450

1446-
t->set_condition(std::move(new_expr));
1447-
t->source_location=source_location;
14481451
t->source_location.set_comment(comment+" in "+source_expr_string);
14491452
t->source_location.set_property_class(property_class);
14501453
}
@@ -1739,10 +1742,13 @@ void goto_checkt::goto_check(
17391742
goto_program_instruction_typet type=
17401743
enable_assert_to_assume?ASSUME:ASSERT;
17411744

1742-
goto_programt::targett t=new_code.add_instruction(type);
1745+
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1746+
static_cast<const codet &>(get_nil_irep()),
1747+
i.source_location,
1748+
type,
1749+
false_exprt(),
1750+
{}));
17431751

1744-
t->set_condition(false_exprt());
1745-
t->source_location=i.source_location;
17461752
t->source_location.set_property_class("error label");
17471753
t->source_location.set_comment("error label "+label);
17481754
t->source_location.set("user-provided", true);

src/goto-instrument/unwind.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ void goto_unwindt::copy_segment(
4848

4949
for(goto_programt::const_targett t=start; t!=end; t++)
5050
{
51-
goto_programt::targett t_new=goto_program.add_instruction();
52-
*t_new=*t;
51+
// copy the instruction
52+
goto_programt::targett t_new =
53+
goto_program.add(goto_programt::instructiont(*t));
5354
unwind_log.insert(t_new, t->location_number);
5455
target_vector.push_back(t_new); // store copied instruction
5556
}

src/goto-instrument/wmm/goto2graph.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,9 +1245,7 @@ void inline instrumentert::add_instr_to_interleaving(
12451245
}
12461246

12471247
/* add this instruction to the interleaving */
1248-
goto_programt::targett current_instruction=interleaving.add_instruction();
1249-
goto_programt::instructiont new_instruction(*it);
1250-
current_instruction->swap(new_instruction);
1248+
interleaving.add(goto_programt::instructiont(*it));
12511249
}
12521250

12531251
bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc)

src/goto-programs/goto_convert.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ void goto_convertt::copy(
298298
goto_program_instruction_typet type,
299299
goto_programt &dest)
300300
{
301-
goto_programt::targett t=dest.add_instruction(type);
302-
t->code=code;
303-
t->source_location=code.source_location();
301+
dest.add(goto_programt::instructiont(
302+
code, code.source_location(), type, nil_exprt(), {}));
304303
}
305304

306305
void goto_convertt::convert_label(
@@ -827,9 +826,8 @@ void goto_convertt::convert_skip(
827826
const codet &code,
828827
goto_programt &dest)
829828
{
830-
goto_programt::targett t=dest.add_instruction(SKIP);
831-
t->source_location=code.source_location();
832-
t->code=code;
829+
dest.add(goto_programt::instructiont(
830+
code, code.source_location(), SKIP, nil_exprt(), {}));
833831
}
834832

835833
void goto_convertt::convert_assume(
@@ -900,7 +898,7 @@ void goto_convertt::convert_for(
900898

901899
// do the v label
902900
goto_programt tmp_v;
903-
goto_programt::targett v=tmp_v.add_instruction();
901+
goto_programt::targett v = tmp_v.add(goto_programt::instructiont());
904902

905903
// do the z label
906904
goto_programt tmp_z;
@@ -990,9 +988,10 @@ void goto_convertt::convert_while(
990988
// do the v label
991989
goto_programt::targett v=tmp_branch.instructions.begin();
992990

993-
// do the y label
991+
// y: goto v;
994992
goto_programt tmp_y;
995-
goto_programt::targett y=tmp_y.add_instruction();
993+
goto_programt::targett y = tmp_y.add(
994+
goto_programt::make_goto(v, true_exprt(), code.source_location()));
996995

997996
// set the targets
998997
targets.set_break(z);
@@ -1002,9 +1001,6 @@ void goto_convertt::convert_while(
10021001
goto_programt tmp_x;
10031002
convert(code.body(), tmp_x, mode);
10041003

1005-
// y: if(c) goto v;
1006-
*y = goto_programt::make_goto(v, true_exprt(), code.source_location());
1007-
10081004
// loop invariant
10091005
convert_loop_invariant(code, y, mode);
10101006

@@ -1047,7 +1043,8 @@ void goto_convertt::convert_dowhile(
10471043

10481044
// do the y label
10491045
goto_programt tmp_y;
1050-
goto_programt::targett y=tmp_y.add_instruction();
1046+
goto_programt::targett y =
1047+
tmp_y.add(goto_programt::make_incomplete_goto(cond, condition_location));
10511048

10521049
// do the z label
10531050
goto_programt tmp_z;
@@ -1071,7 +1068,7 @@ void goto_convertt::convert_dowhile(
10711068
goto_programt::targett w=tmp_w.instructions.begin();
10721069

10731070
// y: if(c) goto w;
1074-
*y = goto_programt::make_goto(w, cond, condition_location);
1071+
y->complete_goto(w);
10751072

10761073
// loop invariant
10771074
convert_loop_invariant(code, y, mode);
@@ -1315,9 +1312,8 @@ void goto_convertt::convert_gcc_computed_goto(
13151312
goto_programt &dest)
13161313
{
13171314
// this instruction will turn into OTHER during post-processing
1318-
goto_programt::targett t=dest.add_instruction(NO_INSTRUCTION_TYPE);
1319-
t->source_location=code.source_location();
1320-
t->code=code;
1315+
goto_programt::targett t = dest.add(goto_programt::instructiont(
1316+
code, code.source_location(), NO_INSTRUCTION_TYPE, nil_exprt(), {}));
13211317

13221318
// remember it to do this later
13231319
targets.computed_gotos.push_back(t);
@@ -1327,10 +1323,8 @@ void goto_convertt::convert_start_thread(
13271323
const codet &code,
13281324
goto_programt &dest)
13291325
{
1330-
goto_programt::targett start_thread=
1331-
dest.add_instruction(START_THREAD);
1332-
start_thread->source_location=code.source_location();
1333-
start_thread->code=code;
1326+
goto_programt::targett start_thread = dest.add(goto_programt::instructiont(
1327+
code, code.source_location(), START_THREAD, nil_exprt(), {}));
13341328

13351329
// remember it to do target later
13361330
targets.gotos.emplace_back(
@@ -1543,7 +1537,8 @@ void goto_convertt::generate_ifthenelse(
15431537

15441538
// do the x label
15451539
goto_programt tmp_x;
1546-
goto_programt::targett x=tmp_x.add_instruction();
1540+
goto_programt::targett x =
1541+
tmp_x.add(goto_programt::make_incomplete_goto(true_exprt()));
15471542

15481543
// do the z label
15491544
goto_programt tmp_z;
@@ -1571,8 +1566,8 @@ void goto_convertt::generate_ifthenelse(
15711566

15721567
// x: goto z;
15731568
CHECK_RETURN(!tmp_w.instructions.empty());
1574-
*x = goto_programt::make_goto(
1575-
z, true_exprt(), tmp_w.instructions.back().source_location);
1569+
x->complete_goto(z);
1570+
x->source_location = tmp_w.instructions.back().source_location;
15761571

15771572
dest.destructive_append(tmp_v);
15781573
dest.destructive_append(tmp_w);
@@ -1894,13 +1889,21 @@ void goto_convertt::generate_thread_block(
18941889
goto_programt::targett c = body.add(goto_programt::make_skip());
18951890
convert(thread_body, body, mode);
18961891

1897-
goto_programt::targett e=postamble.add_instruction(END_THREAD);
1892+
goto_programt::targett e = postamble.add(goto_programt::instructiont(
1893+
static_cast<const codet &>(get_nil_irep()),
1894+
thread_body.source_location(),
1895+
END_THREAD,
1896+
nil_exprt(),
1897+
{}));
18981898
e->source_location=thread_body.source_location();
18991899
goto_programt::targett z = postamble.add(goto_programt::make_skip());
19001900

1901-
goto_programt::targett a=preamble.add_instruction(START_THREAD);
1902-
a->source_location=thread_body.source_location();
1903-
a->targets.push_back(c);
1901+
preamble.add(goto_programt::instructiont(
1902+
static_cast<const codet &>(get_nil_irep()),
1903+
thread_body.source_location(),
1904+
START_THREAD,
1905+
nil_exprt(),
1906+
{c}));
19041907
preamble.add(goto_programt::make_goto(z, thread_body.source_location()));
19051908

19061909
dest.destructive_append(preamble);

src/goto-programs/goto_convert_function_call.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ void goto_convertt::do_function_call_if(
112112

113113
// do the v label
114114
goto_programt tmp_v;
115-
goto_programt::targett v=tmp_v.add_instruction();
115+
goto_programt::targett v = tmp_v.add(goto_programt::make_incomplete_goto(
116+
boolean_negate(function.cond()), function.cond().source_location()));
116117

117118
// do the x label
118119
goto_programt tmp_x;
119-
goto_programt::targett x=tmp_x.add_instruction();
120+
goto_programt::targett x =
121+
tmp_x.add(goto_programt::make_incomplete_goto(true_exprt()));
120122

121123
// do the z label
122124
goto_programt tmp_z;
@@ -134,8 +136,7 @@ void goto_convertt::do_function_call_if(
134136
y=tmp_y.instructions.begin();
135137

136138
// v: if(!c) goto y;
137-
*v = goto_programt::make_goto(
138-
y, boolean_negate(function.cond()), function.cond().source_location());
139+
v->complete_goto(y);
139140

140141
// w: f();
141142
goto_programt tmp_w;
@@ -146,7 +147,7 @@ void goto_convertt::do_function_call_if(
146147
tmp_w.add(goto_programt::make_skip());
147148

148149
// x: goto z;
149-
*x = goto_programt::make_goto(z, true_exprt());
150+
x->complete_goto(z);
150151

151152
dest.destructive_append(tmp_v);
152153
dest.destructive_append(tmp_w);

src/goto-programs/goto_convert_functions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ void goto_convert_functionst::convert_function(
182182
end_location.make_nil();
183183

184184
goto_programt tmp_end_function;
185-
goto_programt::targett end_function=tmp_end_function.add_instruction();
186-
end_function->type=END_FUNCTION;
187-
end_function->source_location=end_location;
185+
goto_programt::targett end_function =
186+
tmp_end_function.add(goto_programt::make_end_function(end_location));
188187

189188
targets=targetst();
190189
targets.set_return(end_function);

src/goto-programs/goto_convert_side_effect.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,12 @@ void goto_convertt::remove_side_effect(
594594
}
595595
else if(statement==ID_throw)
596596
{
597-
goto_programt::targett t=dest.add_instruction(THROW);
598-
t->code = code_expressiont(
599-
side_effect_expr_throwt(
600-
expr.find(ID_exception_list), expr.type(), expr.source_location()));
601-
t->code.op0().operands().swap(expr.operands());
602-
t->code.add_source_location()=expr.source_location();
603-
t->source_location=expr.source_location();
597+
codet code = code_expressiont(side_effect_expr_throwt(
598+
expr.find(ID_exception_list), expr.type(), expr.source_location()));
599+
code.op0().operands().swap(expr.operands());
600+
code.add_source_location() = expr.source_location();
601+
dest.add(goto_programt::instructiont(
602+
std::move(code), expr.source_location(), THROW, nil_exprt(), {}));
604603

605604
// the result can't be used, these are void
606605
expr.make_nil();

src/goto-programs/string_abstraction.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ void string_abstractiont::build_new_symbol(const symbolt &symbol,
993993

994994
if(symbol.is_static_lifetime)
995995
{
996-
goto_programt::targett dummy_loc=initialization.add_instruction();
996+
goto_programt::targett dummy_loc =
997+
initialization.add(goto_programt::instructiont());
997998
dummy_loc->source_location=symbol.location;
998999
make_decl_and_def(initialization, dummy_loc, identifier, symbol.name);
9991000
initialization.instructions.erase(dummy_loc);
@@ -1249,20 +1250,18 @@ goto_programt::targett string_abstractiont::value_assignments_if(
12491250
{
12501251
goto_programt tmp;
12511252

1252-
goto_programt::targett goto_else=tmp.add_instruction(GOTO);
1253-
goto_programt::targett goto_out=tmp.add_instruction(GOTO);
1254-
goto_programt::targett else_target=tmp.add_instruction(SKIP);
1255-
goto_programt::targett out_target=tmp.add_instruction(SKIP);
1256-
1257-
*goto_else = goto_programt::make_goto(
1258-
else_target, boolean_negate(rhs.cond()), target->source_location);
1259-
1260-
*goto_out =
1261-
goto_programt::make_goto(out_target, true_exprt(), target->source_location);
1262-
1263-
else_target->source_location=target->source_location;
1264-
1265-
out_target->source_location=target->source_location;
1253+
goto_programt::targett goto_else =
1254+
tmp.add(goto_programt::make_incomplete_goto(
1255+
boolean_negate(rhs.cond()), target->source_location));
1256+
goto_programt::targett goto_out = tmp.add(
1257+
goto_programt::make_incomplete_goto(true_exprt(), target->source_location));
1258+
goto_programt::targett else_target =
1259+
tmp.add(goto_programt::make_skip(target->source_location));
1260+
goto_programt::targett out_target =
1261+
tmp.add(goto_programt::make_skip(target->source_location));
1262+
1263+
goto_else->complete_goto(else_target);
1264+
goto_out->complete_goto(out_target);
12661265

12671266
value_assignments(tmp, goto_out, lhs, rhs.true_case());
12681267
value_assignments(tmp, else_target, lhs, rhs.false_case());

0 commit comments

Comments
 (0)