@@ -8,20 +8,64 @@ Author: Daniel Kroening, kroening@kroening.com
8
8
9
9
#include " smt2_format.h"
10
10
11
+ #include < util/arith_tools.h>
12
+ #include < util/std_expr.h>
11
13
#include < util/std_types.h>
12
14
13
- std::ostream &operator << (std::ostream &out, const smt2_format &f )
15
+ std::ostream &smt2_format_rec (std::ostream &out, const typet &type )
14
16
{
15
- if (f. type .id () == ID_unsignedbv)
16
- out << " (_ BitVec " << to_unsignedbv_type (f. type ).get_width () << ' )' ;
17
- else if (f. type .id () == ID_bool)
17
+ if (type.id () == ID_unsignedbv)
18
+ out << " (_ BitVec " << to_unsignedbv_type (type).get_width () << ' )' ;
19
+ else if (type.id () == ID_bool)
18
20
out << " Bool" ;
19
- else if (f. type .id () == ID_integer)
21
+ else if (type.id () == ID_integer)
20
22
out << " Int" ;
21
- else if (f. type .id () == ID_real)
23
+ else if (type.id () == ID_real)
22
24
out << " Real" ;
23
25
else
24
- out << " ? " << f.type .id ();
26
+ out << " ? " << type.id ();
27
+
28
+ return out;
29
+ }
30
+
31
+ std::ostream &smt2_format_rec (std::ostream &out, const exprt &expr)
32
+ {
33
+ if (expr.id () == ID_constant)
34
+ {
35
+ const auto &value = to_constant_expr (expr).get_value ();
36
+
37
+ const typet &expr_type = expr.type ();
38
+
39
+ if (expr_type.id () == ID_unsignedbv)
40
+ {
41
+ const std::size_t width = to_unsignedbv_type (expr_type).get_width ();
42
+
43
+ const auto value = numeric_cast_v<mp_integer>(expr);
44
+
45
+ out << " (_ bv" << value << " " << width << " )" ;
46
+ }
47
+ else if (expr_type.id () == ID_bool)
48
+ {
49
+ if (expr.is_true ())
50
+ out << " true" ;
51
+ else if (expr.is_false ())
52
+ out << " false" ;
53
+ else
54
+ DATA_INVARIANT (false , " unknown Boolean constant" );
55
+ }
56
+ else if (expr_type.id () == ID_integer)
57
+ {
58
+ out << value;
59
+ }
60
+ else
61
+ DATA_INVARIANT (false , " unhandled constant: " + expr_type.id_string ());
62
+ }
63
+ else if (expr.id () == ID_symbol)
64
+ {
65
+ out << to_symbol_expr (expr).get_identifier ();
66
+ }
67
+ else
68
+ out << " ? " << expr.id ();
25
69
26
70
return out;
27
71
}
0 commit comments