cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
vcd_goto_trace.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Traces of GOTO Programs in VCD (Value Change Dump) Format
4
5
Author: Daniel Kroening
6
7
Date: June 2011
8
9
\*******************************************************************/
10
13
14
#include "
vcd_goto_trace.h
"
15
16
#include <ctime>
17
18
#include <
util/arith_tools.h
>
19
#include <
util/numbering.h
>
20
#include <
util/pointer_offset_size.h
>
21
22
#include "
goto_trace.h
"
23
24
std::string
as_vcd_binary
(
25
const
exprt
&expr,
26
const
namespacet
&ns)
27
{
28
const
typet
&type = expr.
type
();
29
30
if
(expr.
is_constant
())
31
{
32
if
(type.
id
()==ID_unsignedbv ||
33
type.
id
()==ID_signedbv ||
34
type.
id
()==ID_bv ||
35
type.
id
()==ID_fixedbv ||
36
type.
id
()==ID_floatbv ||
37
type.
id
()==ID_pointer)
38
return
expr.
get_string
(ID_value);
39
}
40
else
if
(expr.
id
()==ID_array)
41
{
42
std::string result;
43
44
for
(
const
auto
&op : expr.
operands
())
45
result +=
as_vcd_binary
(op, ns);
46
47
return
result;
48
}
49
else
if
(expr.
id
()==ID_struct)
50
{
51
std::string result;
52
53
for
(
const
auto
&op : expr.
operands
())
54
result +=
as_vcd_binary
(op, ns);
55
56
return
result;
57
}
58
else
if
(expr.
id
()==ID_union)
59
{
60
return
as_vcd_binary
(
to_union_expr
(expr).op(), ns);
61
}
62
63
// build "xxx"
64
65
const
auto
width =
pointer_offset_bits
(type, ns);
66
67
if
(width.has_value())
68
return
std::string(
numeric_cast_v<std::size_t>
(*width),
'x'
);
69
else
70
return
""
;
71
}
72
73
void
output_vcd
(
74
const
namespacet
&ns,
75
const
goto_tracet
&goto_trace,
76
std::ostream &out)
77
{
78
time_t t;
79
time(&t);
80
out <<
"$date\n "
<< ctime(&t) <<
"$end"
<<
"\n"
;
81
82
// this is pretty arbitrary
83
out <<
"$timescale 1 ns $end"
<<
"\n"
;
84
85
// we first collect all variables that are assigned
86
87
numberingt<irep_idt>
n;
88
89
for
(
const
auto
&step : goto_trace.
steps
)
90
{
91
if
(step.is_assignment())
92
{
93
auto
lhs_object=step.get_lhs_object();
94
if
(lhs_object.has_value())
95
{
96
irep_idt
identifier=lhs_object->get_identifier();
97
const
typet
&type=lhs_object->type();
98
99
const
auto
number=n.
number
(identifier);
100
101
const
auto
width =
pointer_offset_bits
(type, ns);
102
103
if
(width.has_value() && (*width) >= 1)
104
out <<
"$var reg "
<< (*width) <<
" V"
<< number <<
" "
<< identifier
105
<<
" $end"
106
<<
"\n"
;
107
}
108
}
109
}
110
111
// end of header
112
out <<
"$enddefinitions $end"
<<
"\n"
;
113
114
unsigned
timestamp=0;
115
116
for
(
const
auto
&step : goto_trace.
steps
)
117
{
118
if
(step.is_assignment())
119
{
120
auto
lhs_object = step.get_lhs_object();
121
if
(lhs_object.has_value())
122
{
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 ==
true
)
135
out <<
"1"
136
<<
"V"
<< number <<
"\n"
;
137
else
if
(step.full_lhs_value ==
false
)
138
out <<
"0"
139
<<
"V"
<< number <<
"\n"
;
140
else
141
out <<
"x"
142
<<
"V"
<< number <<
"\n"
;
143
}
144
else
145
{
146
std::string
binary
=
as_vcd_binary
(step.full_lhs_value, ns);
147
148
if
(!
binary
.empty())
149
out <<
"b"
<<
binary
<<
" V"
<< number <<
" "
150
<<
"\n"
;
151
}
152
}
153
}
154
}
155
}
arith_tools.h
numeric_cast_v
Target numeric_cast_v(const mp_integer &arg)
Convert an mp_integer to integral type Target An invariant will fail if the conversion is not possibl...
Definition
arith_tools.h:135
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::is_constant
bool is_constant() const
Return whether the expression is a constant.
Definition
expr.h:213
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
goto_tracet
Trace of a GOTO program.
Definition
goto_trace.h:177
goto_tracet::steps
stepst steps
Definition
goto_trace.h:180
irept::id
const irep_idt & id() const
Definition
irep.h:388
irept::get_string
const std::string & get_string(const irep_idt &name) const
Definition
irep.h:401
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
numberingt
Definition
numbering.h:22
numberingt::number
number_type number(const key_type &a)
Definition
numbering.h:37
typet
The type of an expression, extends irept.
Definition
type.h:29
goto_trace.h
Traces of GOTO Programs.
binary
static std::string binary(const constant_exprt &src)
Definition
json_expr.cpp:185
numbering.h
pointer_offset_bits
std::optional< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
Definition
pointer_offset_size.cpp:102
pointer_offset_size.h
Pointer Logic.
to_union_expr
const union_exprt & to_union_expr(const exprt &expr)
Cast an exprt to a union_exprt.
Definition
std_expr.h:1755
as_vcd_binary
std::string as_vcd_binary(const exprt &expr, const namespacet &ns)
Definition
vcd_goto_trace.cpp:24
output_vcd
void output_vcd(const namespacet &ns, const goto_tracet &goto_trace, std::ostream &out)
Definition
vcd_goto_trace.cpp:73
vcd_goto_trace.h
Traces of GOTO Programs in VCD (Value Change Dump) Format.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-programs
vcd_goto_trace.cpp
Generated by
1.17.0