Skip to content

Commit 8bf3ea6

Browse files
authored
Merge pull request #6896 from tautschnig/cleanup/output_instruction
Replace all uses of goto_programt::output_instruction
2 parents f403924 + f7a33df commit 8bf3ea6

27 files changed

+79
-87
lines changed

src/analyses/ai.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void ai_baset::output(
4343
const goto_programt &goto_program,
4444
std::ostream &out) const
4545
{
46+
(void)function_id; // unused parameter
47+
4648
forall_goto_program_instructions(i_it, goto_program)
4749
{
4850
out << "**** " << i_it->location_number << " " << i_it->source_location()
@@ -51,7 +53,7 @@ void ai_baset::output(
5153
abstract_state_before(i_it)->output(out, *this, ns);
5254
out << "\n";
5355
#if 1
54-
goto_program.output_instruction(ns, function_id, out, *i_it);
56+
i_it->output(out);
5557
out << "\n";
5658
#endif
5759
}
@@ -84,13 +86,15 @@ jsont ai_baset::output_json(
8486
const irep_idt &function_id,
8587
const goto_programt &goto_program) const
8688
{
89+
(void)function_id; // unused parameter
90+
8791
json_arrayt contents;
8892

8993
forall_goto_program_instructions(i_it, goto_program)
9094
{
9195
// Ideally we need output_instruction_json
9296
std::ostringstream out;
93-
goto_program.output_instruction(ns, function_id, out, *i_it);
97+
i_it->output(out);
9498

9599
json_objectt location{
96100
{"locationNumber", json_numbert(std::to_string(i_it->location_number))},
@@ -135,6 +139,8 @@ xmlt ai_baset::output_xml(
135139
const irep_idt &function_id,
136140
const goto_programt &goto_program) const
137141
{
142+
(void)function_id; // unused parameter
143+
138144
xmlt function_body;
139145

140146
forall_goto_program_instructions(i_it, goto_program)
@@ -147,7 +153,7 @@ xmlt ai_baset::output_xml(
147153

148154
// Ideally we need output_instruction_xml
149155
std::ostringstream out;
150-
goto_program.output_instruction(ns, function_id, out, *i_it);
156+
i_it->output(out);
151157
location.set_attribute("instruction", out.str());
152158

153159
function_body.new_element(location);

src/analyses/flow_insensitive_analysis.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ bool flow_insensitive_analysis_baset::visit(
173173
// if (id2string(l->function).find("debug")!=std::string::npos)
174174
// std::cout << l->function << '\n'; //=="messages::debug")
175175

176-
// {
177-
// static unsigned state_cntr=0;
178-
// std::string s("pastate"); s += std::to_string(state_cntr);
179-
// std::ofstream f(s.c_str());
180-
// goto_program.output_instruction(ns, "", f, l);
181-
// f << '\n';
182-
// get_state().output(ns, f);
183-
// f.close();
184-
// state_cntr++;
185-
// }
176+
// {
177+
// static unsigned state_cntr=0;
178+
// std::string s("pastate"); s += std::to_string(state_cntr);
179+
// std::ofstream f(s.c_str());
180+
// l->output(f);
181+
// f << '\n';
182+
// get_state().output(ns, f);
183+
// f.close();
184+
// state_cntr++;
185+
// }
186186

187187
return new_data;
188188
}

src/analyses/local_bitvector_analysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void local_bitvector_analysist::output(
365365
}
366366

367367
out << "\n";
368-
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
368+
instruction.output(out);
369369
out << "\n";
370370

371371
l++;

src/analyses/local_may_alias.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void local_may_aliast::output(
497497
}
498498

499499
out << "\n";
500-
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
500+
instruction.output(out);
501501
out << "\n";
502502

503503
l++;

src/analyses/local_safe_pointers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void local_safe_pointerst::output(
217217
}
218218

219219
out << '\n';
220-
goto_program.output_instruction(ns, irep_idt(), out, instruction);
220+
instruction.output(out);
221221
out << '\n';
222222
}
223223
}
@@ -268,7 +268,7 @@ void local_safe_pointerst::output_safe_dereferences(
268268
}
269269

270270
out << '\n';
271-
goto_program.output_instruction(ns, irep_idt(), out, instruction);
271+
instruction.output(out);
272272
out << '\n';
273273
}
274274
}

src/analyses/sese_regions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static std::string brief_instruction_string(
221221
&program_relative_instruction_indices)
222222
{
223223
std::ostringstream ostr;
224-
goto_program.output_instruction(ns, "", ostr, *instruction);
224+
instruction->output(ostr);
225225
return instruction_ordinals(
226226
instruction, program_relative_instruction_indices) +
227227
" " + trimmed_last_line(ostr.str());

src/analyses/static_analysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void static_analysis_baset::output(
9494
get_state(i_it).output(ns, out);
9595
out << "\n";
9696
#if 0
97-
goto_program.output_instruction(ns, identifier, out, i_it);
97+
i_it->output(out);
9898
out << "\n";
9999
#endif
100100
}

src/goto-analyzer/unreachable_instructions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void output_dead_plain(
7575
for(dead_mapt::const_iterator it=dead_map.begin();
7676
it!=dead_map.end();
7777
++it)
78-
goto_program.output_instruction(ns, function_identifier, os, *it->second);
78+
it->second->output(os);
7979
}
8080

8181
static void add_to_xml(
@@ -136,7 +136,7 @@ static void add_to_json(
136136
++it)
137137
{
138138
std::ostringstream oss;
139-
goto_program.output_instruction(ns, function_identifier, oss, *it->second);
139+
it->second->output(oss);
140140
std::string s=oss.str();
141141

142142
std::string::size_type n=s.find('\n');

src/goto-diff/change_impact.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ class change_impactt
284284
char prefix,
285285
const goto_programt &goto_program,
286286
const namespacet &ns,
287-
const irep_idt &function_id,
288287
goto_programt::const_targett &target) const;
289288
};
290289

@@ -606,7 +605,7 @@ void change_impactt::output_change_impact(
606605
else
607606
UNREACHABLE;
608607

609-
output_instruction(prefix, goto_program, ns, function_id, target);
608+
output_instruction(prefix, goto_program, ns, target);
610609
}
611610
}
612611

@@ -644,7 +643,7 @@ void change_impactt::output_change_impact(
644643

645644
if(old_mod_flags&DELETED)
646645
{
647-
output_instruction('-', goto_program, o_ns, function_id, o_target);
646+
output_instruction('-', goto_program, o_ns, o_target);
648647
++o_target;
649648
--target;
650649
continue;
@@ -696,7 +695,7 @@ void change_impactt::output_change_impact(
696695
else
697696
UNREACHABLE;
698697

699-
output_instruction(prefix, goto_program, n_ns, function_id, target);
698+
output_instruction(prefix, goto_program, n_ns, target);
700699
}
701700
for( ;
702701
o_target!=old_goto_program.instructions.end();
@@ -724,15 +723,14 @@ void change_impactt::output_change_impact(
724723
else
725724
UNREACHABLE;
726725

727-
output_instruction(prefix, goto_program, o_ns, function_id, o_target);
726+
output_instruction(prefix, goto_program, o_ns, o_target);
728727
}
729728
}
730729

731730
void change_impactt::output_instruction(
732731
char prefix,
733732
const goto_programt &goto_program,
734733
const namespacet &ns,
735-
const irep_idt &function_id,
736734
goto_programt::const_targett &target) const
737735
{
738736
if(compact_output)
@@ -748,7 +746,7 @@ void change_impactt::output_instruction(
748746
else
749747
{
750748
std::cout << prefix;
751-
goto_program.output_instruction(ns, function_id, std::cout, *target);
749+
target->output(std::cout);
752750
}
753751
}
754752

src/goto-diff/unified_diff.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ void unified_difft::output_diff(
130130
{
131131
case differencet::SAME:
132132
os << ' ';
133-
new_goto_program.output_instruction(ns_new, identifier, os, *d.first);
133+
d.first->output(os);
134134
break;
135135
case differencet::DELETED:
136136
os << '-';
137-
old_goto_program.output_instruction(ns_old, identifier, os, *d.first);
137+
d.first->output(os);
138138
break;
139139
case differencet::NEW:
140140
os << '+';
141-
new_goto_program.output_instruction(ns_new, identifier, os, *d.first);
141+
d.first->output(os);
142142
break;
143143
}
144144
}

src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ bool disjunctive_polynomial_accelerationt::accelerate(
5151
++it)
5252
{
5353
if(loop.contains(it))
54-
{
55-
goto_program.output_instruction(ns, "scratch", std::cout, *it);
56-
}
54+
it->output(std::cout);
5755
}
5856

5957
std::cout << "Modified:\n";

src/goto-instrument/accelerate/enumerating_loop_acceleration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool enumerating_loop_accelerationt::accelerate(
3232
it!=path.end();
3333
++it)
3434
{
35-
goto_program.output_instruction(ns, "OMG", std::cout, *it->loc);
35+
it->loc->output(std::cout);
3636
}
3737
#endif
3838

src/goto-instrument/accelerate/path.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ Author: Matt Lewis
1515

1616
void output_path(
1717
const patht &path,
18-
const goto_programt &program,
19-
const namespacet &ns,
2018
std::ostream &str)
2119
{
2220
for(const auto &step : path)
23-
program.output_instruction(ns, "path", str, *step.loc);
21+
step.loc->output(str);
2422
}

src/goto-instrument/accelerate/polynomial_accelerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool polynomial_acceleratort::accelerate(
6262
it!=body.end();
6363
++it)
6464
{
65-
program.output_instruction(ns, "scratch", std::cout, *it);
65+
it->output(std::cout);
6666
}
6767

6868
std::cout << "Modified:\n";

src/goto-instrument/contracts/contracts.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,11 @@ void code_contractst::apply_function_contract(
947947
// Kill return value variable if fresh
948948
if(call_ret_is_fresh_var)
949949
{
950-
function_body.output_instruction(ns, "", log.warning(), *target);
950+
log.conditional_output(
951+
log.warning(), [&target](messaget::mstreamt &mstream) {
952+
target->output(mstream);
953+
mstream << messaget::eom;
954+
});
951955
auto dead_inst =
952956
goto_programt::make_dead(to_symbol_expr(call_ret_opt.value()), location);
953957
function_body.insert_before_swap(target, dead_inst);
@@ -1120,11 +1124,14 @@ void code_contractst::apply_loop_contract(
11201124
{
11211125
if(std::distance(loop_head, i) < 0 || std::distance(i, loop_end) < 0)
11221126
{
1123-
log.error() << "Computed loop at " << loop_head->source_location()
1127+
log.conditional_output(
1128+
log.error(), [&i, &loop_head](messaget::mstreamt &mstream) {
1129+
mstream << "Computed loop at " << loop_head->source_location()
11241130
<< "contains an instruction beyond [loop_head, loop_end]:"
11251131
<< messaget::eom;
1126-
goto_function.body.output_instruction(
1127-
ns, function_name, log.error(), *i);
1132+
i->output(mstream);
1133+
mstream << messaget::eom;
1134+
});
11281135
throw 0;
11291136
}
11301137
}

src/goto-instrument/contracts/utils.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,20 @@ bool is_loop_free(
204204
auto size = scc_size[scc_id];
205205
if(size > 1)
206206
{
207-
log.error() << "Found CFG SCC with size " << size << messaget::eom;
208-
for(const auto &node_id : node_to_scc)
209-
{
210-
if(node_to_scc[node_id] == scc_id)
211-
{
212-
const auto &pc = cfg[node_id].PC;
213-
goto_program.output_instruction(ns, "", log.error(), *pc);
214-
log.error() << messaget::eom;
215-
}
216-
}
207+
log.conditional_output(
208+
log.error(),
209+
[&cfg, &node_to_scc, &scc_id, &size](messaget::mstreamt &mstream) {
210+
mstream << "Found CFG SCC with size " << size << messaget::eom;
211+
for(const auto &node_id : node_to_scc)
212+
{
213+
if(node_to_scc[node_id] == scc_id)
214+
{
215+
const auto &pc = cfg[node_id].PC;
216+
pc->output(mstream);
217+
mstream << messaget::eom;
218+
}
219+
}
220+
});
217221
return false;
218222
}
219223
}

src/goto-instrument/goto_instrument_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int goto_instrument_parse_optionst::doit()
273273

274274
forall_goto_program_instructions(i_it, goto_program)
275275
{
276-
goto_program.output_instruction(ns, gf_entry.first, std::cout, *i_it);
276+
i_it->output(std::cout);
277277
std::cout << "Is threaded: " << (is_threaded(i_it)?"True":"False")
278278
<< "\n\n";
279279
}

src/goto-instrument/unwind.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,8 @@ void goto_unwindt::unwind(
282282
i_it!=goto_program.instructions.end();)
283283
{
284284
#ifdef DEBUG
285-
symbol_tablet st;
286-
namespacet ns(st);
287285
std::cout << "Instruction:\n";
288-
goto_program.output_instruction(ns, function_id, std::cout, *i_it);
286+
i_it->output(std::cout);
289287
#endif
290288

291289
if(!i_it->is_backwards_goto())

src/goto-programs/goto_inline_class.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void goto_inlinet::expand_function_call(
311311

312312
#ifdef DEBUG
313313
std::cout << "Expanding call:\n";
314-
dest.output_instruction(ns, irep_idt(), std::cout, *target);
314+
target->output(std::cout);
315315
#endif
316316

317317
exprt lhs;
@@ -691,15 +691,13 @@ void goto_inlinet::output_inline_map(
691691
goto_function.body_available(),
692692
"cannot inline function with empty body");
693693

694-
const goto_programt &goto_program=goto_function.body;
695-
696694
for(const auto &call : call_list)
697695
{
698696
const goto_programt::const_targett target=call.first;
699697
bool transitive=call.second;
700698

701699
out << " Call:\n";
702-
goto_program.output_instruction(ns, id, out, *target);
700+
target->output(out);
703701
out << " Transitive: " << transitive << "\n";
704702
}
705703
}

src/goto-programs/interpreter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ void interpretert::show_state()
120120
output.status() << "End of function '" << function->first << "'\n";
121121
}
122122
else
123-
function->second.body.output_instruction(
124-
ns, function->first, output.status(), *pc);
123+
pc->output(output.status());
125124

126125
output.status() << messaget::eom;
127126
}

0 commit comments

Comments
 (0)