Skip to content

Commit df0890b

Browse files
committed
GraphML witnesses: code cleanup, output nondet return values
1 parent 24a9ca0 commit df0890b

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

src/goto-programs/graphml_witness.cpp

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,65 @@ std::string graphml_witnesst::convert_assign_rec(
146146
exprt clean_rhs=assign.rhs();
147147
remove_l0_l1(clean_rhs);
148148

149-
result=from_expr(ns, identifier, assign.lhs())+" = "+
150-
from_expr(ns, identifier, clean_rhs)+";";
149+
std::string lhs=from_expr(ns, identifier, assign.lhs());
150+
if(lhs.find('$')!=std::string::npos)
151+
lhs="\\result";
152+
153+
result=lhs+" = "+from_expr(ns, identifier, clean_rhs)+";";
151154
}
152155

153156
return result;
154157
}
155158

156159
/*******************************************************************\
157160
161+
Function: filter_out
162+
163+
Inputs:
164+
165+
Outputs:
166+
167+
Purpose:
168+
169+
\*******************************************************************/
170+
171+
static bool filter_out(
172+
const goto_tracet &goto_trace,
173+
const goto_tracet::stepst::const_iterator &prev_it,
174+
goto_tracet::stepst::const_iterator &it)
175+
{
176+
if(it->hidden &&
177+
(!it->is_assignment() ||
178+
to_code_assign(it->pc->code).rhs().id()!=ID_side_effect ||
179+
to_code_assign(it->pc->code).rhs().get(ID_statement)!=ID_nondet))
180+
return true;
181+
182+
if(!it->is_assignment() && !it->is_goto() && !it->is_assert())
183+
return true;
184+
185+
// we filter out steps with the same source location
186+
// TODO: if these are assignments we should accumulate them into
187+
// a single edge
188+
if(prev_it!=goto_trace.steps.end() &&
189+
prev_it->pc->source_location==it->pc->source_location)
190+
return true;
191+
192+
if(it->is_goto() && it->pc->guard.is_true())
193+
return true;
194+
195+
const source_locationt &source_location=it->pc->source_location;
196+
197+
if(source_location.is_nil() ||
198+
source_location.get_file().empty() ||
199+
source_location.is_built_in() ||
200+
source_location.get_line().empty())
201+
return true;
202+
203+
return false;
204+
}
205+
206+
/*******************************************************************\
207+
158208
Function: graphml_witnesst::operator()
159209
160210
Inputs:
@@ -184,20 +234,7 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
184234
it!=goto_trace.steps.end();
185235
it++) // we cannot replace this by a ranged for
186236
{
187-
const source_locationt &source_location=it->pc->source_location;
188-
189-
if(it->hidden ||
190-
(!it->is_assignment() && !it->is_goto() && !it->is_assert()) ||
191-
// we filter out steps with the same source location
192-
// TODO: if these are assignments we should accumulate them into
193-
// a single edge
194-
(prev_it!=goto_trace.steps.end() &&
195-
prev_it->pc->source_location==it->pc->source_location) ||
196-
(it->is_goto() && it->pc->guard.is_true()) ||
197-
source_location.is_nil() ||
198-
source_location.get_file().empty() ||
199-
source_location.is_built_in() ||
200-
source_location.get_line().empty())
237+
if(filter_out(goto_trace, prev_it, it))
201238
{
202239
step_to_node[it->step_nr]=sink;
203240

@@ -219,6 +256,8 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
219256

220257
prev_it=it;
221258

259+
const source_locationt &source_location=it->pc->source_location;
260+
222261
const graphmlt::node_indext node=graphml.add_node();
223262
graphml[node].node_name=
224263
std::to_string(it->pc->location_number)+"."+std::to_string(it->step_nr);
@@ -278,23 +317,19 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
278317
data_l.data=id2string(graphml[from].line);
279318
}
280319

281-
if((it->type==goto_trace_stept::ASSIGNMENT ||
282-
it->type==goto_trace_stept::DECL) &&
320+
if(it->type==goto_trace_stept::ASSIGNMENT &&
283321
it->lhs_object_value.is_not_nil() &&
284322
it->full_lhs.is_not_nil())
285323
{
286-
irep_idt identifier=it->lhs_object.get_identifier();
287-
288-
if(id2string(it->lhs_object.get_identifier()).find('$')==
289-
std::string::npos &&
290-
(!it->lhs_object_value.is_constant() ||
291-
!it->lhs_object_value.has_operands() ||
292-
!has_prefix(id2string(it->lhs_object_value.op0().get(ID_value)),
293-
"INVALID-")))
324+
if(!it->lhs_object_value.is_constant() ||
325+
!it->lhs_object_value.has_operands() ||
326+
!has_prefix(id2string(it->lhs_object_value.op0().get(ID_value)),
327+
"INVALID-"))
294328
{
295329
xmlt &val=edge.new_element("data");
296330
val.set_attribute("key", "assumption");
297331
code_assignt assign(it->lhs_object, it->lhs_object_value);
332+
irep_idt identifier=it->lhs_object.get_identifier();
298333
val.data=convert_assign_rec(identifier, assign);
299334

300335
xmlt &val_s=edge.new_element("data");

0 commit comments

Comments
 (0)