Skip to content

Replace all uses of goto_programt::output_instruction #6896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/analyses/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void ai_baset::output(
const goto_programt &goto_program,
std::ostream &out) const
{
(void)function_id; // unused parameter

forall_goto_program_instructions(i_it, goto_program)
{
out << "**** " << i_it->location_number << " " << i_it->source_location()
Expand All @@ -51,7 +53,7 @@ void ai_baset::output(
abstract_state_before(i_it)->output(out, *this, ns);
out << "\n";
#if 1
goto_program.output_instruction(ns, function_id, out, *i_it);
i_it->output(out);
out << "\n";
#endif
}
Expand Down Expand Up @@ -84,13 +86,15 @@ jsont ai_baset::output_json(
const irep_idt &function_id,
const goto_programt &goto_program) const
{
(void)function_id; // unused parameter

json_arrayt contents;

forall_goto_program_instructions(i_it, goto_program)
{
// Ideally we need output_instruction_json
std::ostringstream out;
goto_program.output_instruction(ns, function_id, out, *i_it);
i_it->output(out);

json_objectt location{
{"locationNumber", json_numbert(std::to_string(i_it->location_number))},
Expand Down Expand Up @@ -135,6 +139,8 @@ xmlt ai_baset::output_xml(
const irep_idt &function_id,
const goto_programt &goto_program) const
{
(void)function_id; // unused parameter

xmlt function_body;

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

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

function_body.new_element(location);
Expand Down
20 changes: 10 additions & 10 deletions src/analyses/flow_insensitive_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ bool flow_insensitive_analysis_baset::visit(
// if (id2string(l->function).find("debug")!=std::string::npos)
// std::cout << l->function << '\n'; //=="messages::debug")

// {
// static unsigned state_cntr=0;
// std::string s("pastate"); s += std::to_string(state_cntr);
// std::ofstream f(s.c_str());
// goto_program.output_instruction(ns, "", f, l);
// f << '\n';
// get_state().output(ns, f);
// f.close();
// state_cntr++;
// }
// {
// static unsigned state_cntr=0;
// std::string s("pastate"); s += std::to_string(state_cntr);
// std::ofstream f(s.c_str());
// l->output(f);
// f << '\n';
// get_state().output(ns, f);
// f.close();
// state_cntr++;
// }

return new_data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void local_bitvector_analysist::output(
}

out << "\n";
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
instruction.output(out);
out << "\n";

l++;
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_may_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void local_may_aliast::output(
}

out << "\n";
goto_function.body.output_instruction(ns, irep_idt(), out, instruction);
instruction.output(out);
out << "\n";

l++;
Expand Down
4 changes: 2 additions & 2 deletions src/analyses/local_safe_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void local_safe_pointerst::output(
}

out << '\n';
goto_program.output_instruction(ns, irep_idt(), out, instruction);
instruction.output(out);
out << '\n';
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ void local_safe_pointerst::output_safe_dereferences(
}

out << '\n';
goto_program.output_instruction(ns, irep_idt(), out, instruction);
instruction.output(out);
out << '\n';
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/sese_regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static std::string brief_instruction_string(
&program_relative_instruction_indices)
{
std::ostringstream ostr;
goto_program.output_instruction(ns, "", ostr, *instruction);
instruction->output(ostr);
return instruction_ordinals(
instruction, program_relative_instruction_indices) +
" " + trimmed_last_line(ostr.str());
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/static_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void static_analysis_baset::output(
get_state(i_it).output(ns, out);
out << "\n";
#if 0
goto_program.output_instruction(ns, identifier, out, i_it);
i_it->output(out);
out << "\n";
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void output_dead_plain(
for(dead_mapt::const_iterator it=dead_map.begin();
it!=dead_map.end();
++it)
goto_program.output_instruction(ns, function_identifier, os, *it->second);
it->second->output(os);
}

static void add_to_xml(
Expand Down Expand Up @@ -136,7 +136,7 @@ static void add_to_json(
++it)
{
std::ostringstream oss;
goto_program.output_instruction(ns, function_identifier, oss, *it->second);
it->second->output(oss);
std::string s=oss.str();

std::string::size_type n=s.find('\n');
Expand Down
12 changes: 5 additions & 7 deletions src/goto-diff/change_impact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ class change_impactt
char prefix,
const goto_programt &goto_program,
const namespacet &ns,
const irep_idt &function_id,
goto_programt::const_targett &target) const;
};

Expand Down Expand Up @@ -606,7 +605,7 @@ void change_impactt::output_change_impact(
else
UNREACHABLE;

output_instruction(prefix, goto_program, ns, function_id, target);
output_instruction(prefix, goto_program, ns, target);
}
}

Expand Down Expand Up @@ -644,7 +643,7 @@ void change_impactt::output_change_impact(

if(old_mod_flags&DELETED)
{
output_instruction('-', goto_program, o_ns, function_id, o_target);
output_instruction('-', goto_program, o_ns, o_target);
++o_target;
--target;
continue;
Expand Down Expand Up @@ -696,7 +695,7 @@ void change_impactt::output_change_impact(
else
UNREACHABLE;

output_instruction(prefix, goto_program, n_ns, function_id, target);
output_instruction(prefix, goto_program, n_ns, target);
}
for( ;
o_target!=old_goto_program.instructions.end();
Expand Down Expand Up @@ -724,15 +723,14 @@ void change_impactt::output_change_impact(
else
UNREACHABLE;

output_instruction(prefix, goto_program, o_ns, function_id, o_target);
output_instruction(prefix, goto_program, o_ns, o_target);
}
}

void change_impactt::output_instruction(
char prefix,
const goto_programt &goto_program,
const namespacet &ns,
const irep_idt &function_id,
goto_programt::const_targett &target) const
{
if(compact_output)
Expand All @@ -748,7 +746,7 @@ void change_impactt::output_instruction(
else
{
std::cout << prefix;
goto_program.output_instruction(ns, function_id, std::cout, *target);
target->output(std::cout);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/goto-diff/unified_diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ void unified_difft::output_diff(
{
case differencet::SAME:
os << ' ';
new_goto_program.output_instruction(ns_new, identifier, os, *d.first);
d.first->output(os);
break;
case differencet::DELETED:
os << '-';
old_goto_program.output_instruction(ns_old, identifier, os, *d.first);
d.first->output(os);
break;
case differencet::NEW:
os << '+';
new_goto_program.output_instruction(ns_new, identifier, os, *d.first);
d.first->output(os);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ bool disjunctive_polynomial_accelerationt::accelerate(
++it)
{
if(loop.contains(it))
{
goto_program.output_instruction(ns, "scratch", std::cout, *it);
}
it->output(std::cout);
}

std::cout << "Modified:\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool enumerating_loop_accelerationt::accelerate(
it!=path.end();
++it)
{
goto_program.output_instruction(ns, "OMG", std::cout, *it->loc);
it->loc->output(std::cout);
}
#endif

Expand Down
4 changes: 1 addition & 3 deletions src/goto-instrument/accelerate/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ Author: Matt Lewis

void output_path(
const patht &path,
const goto_programt &program,
const namespacet &ns,
std::ostream &str)
{
for(const auto &step : path)
program.output_instruction(ns, "path", str, *step.loc);
step.loc->output(str);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool polynomial_acceleratort::accelerate(
it!=body.end();
++it)
{
program.output_instruction(ns, "scratch", std::cout, *it);
it->output(std::cout);
}

std::cout << "Modified:\n";
Expand Down
15 changes: 11 additions & 4 deletions src/goto-instrument/contracts/contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,11 @@ void code_contractst::apply_function_contract(
// Kill return value variable if fresh
if(call_ret_is_fresh_var)
{
function_body.output_instruction(ns, "", log.warning(), *target);
log.conditional_output(
log.warning(), [&target](messaget::mstreamt &mstream) {
target->output(mstream);
mstream << messaget::eom;
});
auto dead_inst =
goto_programt::make_dead(to_symbol_expr(call_ret_opt.value()), location);
function_body.insert_before_swap(target, dead_inst);
Expand Down Expand Up @@ -1120,11 +1124,14 @@ void code_contractst::apply_loop_contract(
{
if(std::distance(loop_head, i) < 0 || std::distance(i, loop_end) < 0)
{
log.error() << "Computed loop at " << loop_head->source_location()
log.conditional_output(
log.error(), [&i, &loop_head](messaget::mstreamt &mstream) {
mstream << "Computed loop at " << loop_head->source_location()
<< "contains an instruction beyond [loop_head, loop_end]:"
<< messaget::eom;
goto_function.body.output_instruction(
ns, function_name, log.error(), *i);
i->output(mstream);
mstream << messaget::eom;
});
throw 0;
}
}
Expand Down
24 changes: 14 additions & 10 deletions src/goto-instrument/contracts/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,20 @@ bool is_loop_free(
auto size = scc_size[scc_id];
if(size > 1)
{
log.error() << "Found CFG SCC with size " << size << messaget::eom;
for(const auto &node_id : node_to_scc)
{
if(node_to_scc[node_id] == scc_id)
{
const auto &pc = cfg[node_id].PC;
goto_program.output_instruction(ns, "", log.error(), *pc);
log.error() << messaget::eom;
}
}
log.conditional_output(
log.error(),
[&cfg, &node_to_scc, &scc_id, &size](messaget::mstreamt &mstream) {
mstream << "Found CFG SCC with size " << size << messaget::eom;
for(const auto &node_id : node_to_scc)
{
if(node_to_scc[node_id] == scc_id)
{
const auto &pc = cfg[node_id].PC;
pc->output(mstream);
mstream << messaget::eom;
}
}
});
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int goto_instrument_parse_optionst::doit()

forall_goto_program_instructions(i_it, goto_program)
{
goto_program.output_instruction(ns, gf_entry.first, std::cout, *i_it);
i_it->output(std::cout);
std::cout << "Is threaded: " << (is_threaded(i_it)?"True":"False")
<< "\n\n";
}
Expand Down
4 changes: 1 addition & 3 deletions src/goto-instrument/unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,8 @@ void goto_unwindt::unwind(
i_it!=goto_program.instructions.end();)
{
#ifdef DEBUG
symbol_tablet st;
namespacet ns(st);
std::cout << "Instruction:\n";
goto_program.output_instruction(ns, function_id, std::cout, *i_it);
i_it->output(std::cout);
#endif

if(!i_it->is_backwards_goto())
Expand Down
6 changes: 2 additions & 4 deletions src/goto-programs/goto_inline_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void goto_inlinet::expand_function_call(

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

exprt lhs;
Expand Down Expand Up @@ -691,15 +691,13 @@ void goto_inlinet::output_inline_map(
goto_function.body_available(),
"cannot inline function with empty body");

const goto_programt &goto_program=goto_function.body;

for(const auto &call : call_list)
{
const goto_programt::const_targett target=call.first;
bool transitive=call.second;

out << " Call:\n";
goto_program.output_instruction(ns, id, out, *target);
target->output(out);
out << " Transitive: " << transitive << "\n";
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/goto-programs/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ void interpretert::show_state()
output.status() << "End of function '" << function->first << "'\n";
}
else
function->second.body.output_instruction(
ns, function->first, output.status(), *pc);
pc->output(output.status());

output.status() << messaget::eom;
}
Expand Down
Loading