Skip to content

Commit df868b8

Browse files
author
Daniel Kroening
committed
remove lhs_object from goto_trace_stept
Rationale: * lhs_object_value may be extremely large (think of large struct or array), but the information is contained in (more compact form) full_lhs_value. * lhs_object is contained in full_lhs. A helper function is provided to extract it.
1 parent f702e6b commit df868b8

8 files changed

+110
-120
lines changed

src/goto-programs/goto_trace.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ Author: Daniel Kroening
2424

2525
#include "printf_formatter.h"
2626

27+
static optionalt<symbol_exprt> get_object_rec(const exprt &src)
28+
{
29+
if(src.id()==ID_symbol)
30+
return to_symbol_expr(src);
31+
else if(src.id()==ID_member)
32+
return get_object_rec(to_member_expr(src).struct_op());
33+
else if(src.id()==ID_index)
34+
return get_object_rec(to_index_expr(src).array());
35+
else if(src.id()==ID_typecast)
36+
return get_object_rec(to_typecast_expr(src).op());
37+
else
38+
return {}; // give up
39+
}
40+
41+
optionalt<symbol_exprt> goto_trace_stept::get_lhs_object() const
42+
{
43+
return get_object_rec(full_lhs);
44+
}
45+
2746
void goto_tracet::output(
2847
const class namespacet &ns,
2948
std::ostream &out) const
@@ -217,15 +236,15 @@ std::string trace_numeric_value(
217236
void trace_value(
218237
std::ostream &out,
219238
const namespacet &ns,
220-
const ssa_exprt &lhs_object,
239+
const optionalt<symbol_exprt> &lhs_object,
221240
const exprt &full_lhs,
222241
const exprt &value,
223242
const trace_optionst &options)
224243
{
225244
irep_idt identifier;
226245

227-
if(lhs_object.is_not_nil())
228-
identifier=lhs_object.get_object_name();
246+
if(lhs_object.has_value())
247+
identifier=lhs_object->get_identifier();
229248

230249
std::string value_string;
231250

@@ -346,7 +365,7 @@ void show_full_goto_trace(
346365
if(step.pc->is_assign() ||
347366
step.pc->is_return() || // returns have a lhs!
348367
step.pc->is_function_call() ||
349-
(step.pc->is_other() && step.lhs_object.is_not_nil()))
368+
(step.pc->is_other() && step.full_lhs.is_not_nil()))
350369
{
351370
if(prev_step_nr!=step.step_nr || first_step)
352371
{
@@ -356,23 +375,13 @@ void show_full_goto_trace(
356375
out, ns, step, step.pc->source_location, step.step_nr, options);
357376
}
358377

359-
// see if the full lhs is something clean
360-
if(is_index_member_symbol(step.full_lhs))
361-
trace_value(
362-
out,
363-
ns,
364-
step.lhs_object,
365-
step.full_lhs,
366-
step.full_lhs_value,
367-
options);
368-
else
369-
trace_value(
370-
out,
371-
ns,
372-
step.lhs_object,
373-
step.lhs_object,
374-
step.lhs_object_value,
375-
options);
378+
trace_value(
379+
out,
380+
ns,
381+
step.get_lhs_object(),
382+
step.full_lhs,
383+
step.full_lhs_value,
384+
options);
376385
}
377386
break;
378387

@@ -386,7 +395,7 @@ void show_full_goto_trace(
386395
}
387396

388397
trace_value(
389-
out, ns, step.lhs_object, step.full_lhs, step.full_lhs_value, options);
398+
out, ns, step.get_lhs_object(), step.full_lhs, step.full_lhs_value, options);
390399
break;
391400

392401
case goto_trace_stept::typet::OUTPUT:

src/goto-programs/goto_trace.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class goto_trace_stept
104104
// for assert
105105
std::string comment;
106106

107-
// the object being assigned
108-
ssa_exprt lhs_object;
109-
110-
// the full, original lhs expression
107+
// the full, original lhs expression, after dereferencing
111108
exprt full_lhs;
112109

113-
// A constant with the new value
114-
exprt lhs_object_value, full_lhs_value;
110+
// the object being assigned
111+
optionalt<symbol_exprt> get_lhs_object() const;
112+
113+
// A constant with the new value of the lhs
114+
exprt full_lhs_value;
115115

116116
// for INPUT/OUTPUT
117117
irep_idt format_string, io_id;
@@ -141,8 +141,6 @@ class goto_trace_stept
141141
cond_value(false),
142142
formatted(false)
143143
{
144-
lhs_object.make_nil();
145-
lhs_object_value.make_nil();
146144
full_lhs.make_nil();
147145
full_lhs_value.make_nil();
148146
cond_expr.make_nil();
@@ -245,9 +243,10 @@ void show_goto_trace(
245243
void trace_value(
246244
std::ostream &out,
247245
const namespacet &,
248-
const ssa_exprt &lhs_object,
246+
const optionalt<symbol_exprt> &lhs_object,
249247
const exprt &full_lhs,
250-
const exprt &value);
248+
const exprt &value,
249+
const trace_optionst &);
251250

252251
#define OPT_GOTO_TRACE \
253252
"(trace-json-extended)" \

src/goto-programs/graphml_witness.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,24 +278,17 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace)
278278
}
279279

280280
if(it->type==goto_trace_stept::typet::ASSIGNMENT &&
281-
it->lhs_object_value.is_not_nil() &&
281+
it->full_lhs_value.is_not_nil() &&
282282
it->full_lhs.is_not_nil())
283283
{
284-
if(!it->lhs_object_value.is_constant() ||
285-
!it->lhs_object_value.has_operands() ||
286-
!has_prefix(id2string(it->lhs_object_value.op0().get(ID_value)),
287-
"INVALID-"))
288-
{
289-
xmlt &val=edge.new_element("data");
290-
val.set_attribute("key", "assumption");
291-
code_assignt assign(it->lhs_object, it->lhs_object_value);
292-
irep_idt identifier=it->lhs_object.get_identifier();
293-
val.data=convert_assign_rec(identifier, assign);
294-
295-
xmlt &val_s=edge.new_element("data");
296-
val_s.set_attribute("key", "assumption.scope");
297-
val_s.data=id2string(it->pc->source_location.get_function());
298-
}
284+
xmlt &val=edge.new_element("data");
285+
val.set_attribute("key", "assumption");
286+
val.data=from_expr(ns, it->pc->function, it->full_lhs)+" = "+
287+
from_expr(ns, it->pc->function, it->full_lhs_value)+";";
288+
289+
xmlt &val_s=edge.new_element("data");
290+
val_s.set_attribute("key", "assumption.scope");
291+
val_s.data=id2string(it->pc->source_location.get_function());
299292
}
300293
else if(it->type==goto_trace_stept::typet::GOTO &&
301294
it->pc->is_goto())

src/goto-programs/interpreter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,15 +677,7 @@ void interpretert::execute_assign()
677677
goto_trace_stept &trace_step=steps.get_last_step();
678678
assign(address, rhs);
679679
trace_step.full_lhs=code_assign.lhs();
680-
681-
// TODO: need to look at other cases on ssa_exprt
682-
// (dereference should be handled on ssa)
683-
if(ssa_exprt::can_build_identifier(trace_step.full_lhs))
684-
{
685-
trace_step.lhs_object=ssa_exprt(trace_step.full_lhs);
686-
}
687680
trace_step.full_lhs_value=get_value(trace_step.full_lhs.type(), rhs);
688-
trace_step.lhs_object_value=trace_step.full_lhs_value;
689681
}
690682
}
691683
else if(code_assign.rhs().id()==ID_side_effect)

src/goto-programs/json_goto_trace.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ void convert_decl(
7777
const jsont &json_location = conversion_dependencies.location;
7878
const namespacet &ns = conversion_dependencies.ns;
7979

80-
irep_idt identifier = step.lhs_object.get_identifier();
80+
auto lhs_object=step.get_lhs_object();
81+
82+
irep_idt identifier =
83+
lhs_object.has_value()?lhs_object->get_identifier():irep_idt();
8184

8285
json_assignment["stepType"] = json_stringt("assignment");
8386

src/goto-programs/vcd_goto_trace.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,20 @@ void output_vcd(
8989
{
9090
if(step.is_assignment())
9191
{
92-
irep_idt identifier=step.lhs_object.get_identifier();
93-
const typet &type=step.lhs_object.type();
92+
auto lhs_object=step.get_lhs_object();
93+
if(lhs_object.has_value())
94+
{
95+
irep_idt identifier=lhs_object->get_identifier();
96+
const typet &type=lhs_object->type();
9497

95-
const auto number=n.number(identifier);
98+
const auto number=n.number(identifier);
9699

97-
const mp_integer width = pointer_offset_bits(type, ns);
100+
const mp_integer width = pointer_offset_bits(type, ns);
98101

99-
if(width>=1)
100-
out << "$var reg " << width << " V" << number << " "
101-
<< identifier << " $end" << "\n";
102+
if(width>=1)
103+
out << "$var reg " << width << " V" << number << " "
104+
<< identifier << " $end" << "\n";
105+
}
102106
}
103107
}
104108

@@ -113,30 +117,34 @@ void output_vcd(
113117
{
114118
case goto_trace_stept::typet::ASSIGNMENT:
115119
{
116-
irep_idt identifier=step.lhs_object.get_identifier();
117-
const typet &type=step.lhs_object.type();
118-
119-
out << '#' << timestamp << "\n";
120-
timestamp++;
121-
122-
const auto number=n.number(identifier);
123-
124-
// booleans are special in VCD
125-
if(type.id()==ID_bool)
120+
auto lhs_object=step.get_lhs_object();
121+
if(lhs_object.has_value())
126122
{
127-
if(step.lhs_object_value.is_true())
128-
out << "1" << "V" << number << "\n";
129-
else if(step.lhs_object_value.is_false())
130-
out << "0" << "V" << number << "\n";
123+
irep_idt identifier=lhs_object->get_identifier();
124+
const typet &type=lhs_object->type();
125+
126+
out << '#' << timestamp << "\n";
127+
timestamp++;
128+
129+
const auto number=n.number(identifier);
130+
131+
// booleans are special in VCD
132+
if(type.id()==ID_bool)
133+
{
134+
if(step.full_lhs_value.is_true())
135+
out << "1" << "V" << number << "\n";
136+
else if(step.full_lhs_value.is_false())
137+
out << "0" << "V" << number << "\n";
138+
else
139+
out << "x" << "V" << number << "\n";
140+
}
131141
else
132-
out << "x" << "V" << number << "\n";
133-
}
134-
else
135-
{
136-
std::string binary=as_vcd_binary(step.lhs_object_value, ns);
142+
{
143+
std::string binary=as_vcd_binary(step.full_lhs_value, ns);
137144

138-
if(binary!="")
139-
out << "b" << binary << " V" << number << " " << "\n";
145+
if(binary!="")
146+
out << "b" << binary << " V" << number << " " << "\n";
147+
}
140148
}
141149
}
142150
break;

src/goto-programs/xml_goto_trace.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,33 @@ void convert(
7171
case goto_trace_stept::typet::ASSIGNMENT:
7272
case goto_trace_stept::typet::DECL:
7373
{
74-
irep_idt identifier=step.lhs_object.get_identifier();
74+
auto lhs_object=step.get_lhs_object();
75+
irep_idt identifier=
76+
lhs_object.has_value()?lhs_object->get_identifier():irep_idt();
7577
xmlt &xml_assignment=dest.new_element("assignment");
7678

7779
if(xml_location.name!="")
7880
xml_assignment.new_element().swap(xml_location);
7981

80-
std::string value_string, type_string,
81-
full_lhs_string, full_lhs_value_string;
82+
{
83+
auto lhs_object=step.get_lhs_object();
84+
85+
const symbolt *symbol;
86+
87+
if(lhs_object.has_value() &&
88+
!ns.lookup(lhs_object->get_identifier(), symbol))
89+
{
90+
std::string type_string=from_type(ns, symbol->name, symbol->type);
91+
92+
xml_assignment.set_attribute("mode", id2string(symbol->mode));
93+
xml_assignment.set_attribute("identifier", id2string(symbol->name));
94+
xml_assignment.set_attribute("base_name", id2string(symbol->base_name));
95+
xml_assignment.set_attribute("display_name", id2string(symbol->display_name()));
96+
xml_assignment.new_element("type").data=type_string;
97+
}
98+
}
8299

83-
if(step.lhs_object_value.is_not_nil())
84-
value_string=from_expr(ns, identifier, step.lhs_object_value);
100+
std::string full_lhs_string, full_lhs_value_string;
85101

86102
if(step.full_lhs.is_not_nil())
87103
full_lhs_string=from_expr(ns, identifier, step.full_lhs);
@@ -90,28 +106,11 @@ void convert(
90106
full_lhs_value_string=
91107
from_expr(ns, identifier, step.full_lhs_value);
92108

93-
const symbolt *symbol;
94-
irep_idt base_name, display_name;
95-
96-
if(!ns.lookup(identifier, symbol))
97-
{
98-
base_name=symbol->base_name;
99-
display_name=symbol->display_name();
100-
if(type_string=="")
101-
type_string=from_type(ns, identifier, symbol->type);
102-
103-
xml_assignment.set_attribute("mode", id2string(symbol->mode));
104-
}
105-
106-
xml_assignment.new_element("type").data=type_string;
107109
xml_assignment.new_element("full_lhs").data=full_lhs_string;
108110
xml_assignment.new_element("full_lhs_value").data=full_lhs_value_string;
109111

110112
xml_assignment.set_attribute_bool("hidden", step.hidden);
111113
xml_assignment.set_attribute("thread", std::to_string(step.thread_nr));
112-
xml_assignment.set_attribute("identifier", id2string(identifier));
113-
xml_assignment.set_attribute("base_name", id2string(base_name));
114-
xml_assignment.set_attribute("display_name", id2string(display_name));
115114
xml_assignment.set_attribute("step_nr", std::to_string(step.step_nr));
116115

117116
xml_assignment.set_attribute("assignment_type",

src/goto-symex/build_goto_trace.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,6 @@ void build_goto_trace(
295295
goto_trace_step.thread_nr = SSA_step.source.thread_nr;
296296
goto_trace_step.pc = SSA_step.source.pc;
297297
goto_trace_step.comment = SSA_step.comment;
298-
if(SSA_step.ssa_lhs.is_not_nil())
299-
{
300-
goto_trace_step.lhs_object =
301-
ssa_exprt(SSA_step.ssa_lhs.get_original_expr());
302-
}
303-
else
304-
{
305-
goto_trace_step.lhs_object.make_nil();
306-
}
307-
308298
goto_trace_step.type = SSA_step.type;
309299
goto_trace_step.hidden = SSA_step.hidden;
310300
goto_trace_step.format_string = SSA_step.format_string;
@@ -334,9 +324,6 @@ void build_goto_trace(
334324
prop_conv, ns, SSA_step.original_full_lhs, SSA_step.ssa_full_lhs);
335325
}
336326

337-
if(SSA_step.ssa_lhs.is_not_nil())
338-
goto_trace_step.lhs_object_value = prop_conv.get(SSA_step.ssa_lhs);
339-
340327
if(SSA_step.ssa_full_lhs.is_not_nil())
341328
{
342329
goto_trace_step.full_lhs_value = prop_conv.get(SSA_step.ssa_full_lhs);

0 commit comments

Comments
 (0)