|
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 |
| 46 | + << " " << width << ")"; |
| 47 | + } |
| 48 | + else if(expr_type.id()==ID_bool) |
| 49 | + { |
| 50 | + if(expr.is_true()) |
| 51 | + out << "true"; |
| 52 | + else if(expr.is_false()) |
| 53 | + out << "false"; |
| 54 | + else |
| 55 | + DATA_INVARIANT(false, "unknown Boolean constant"); |
| 56 | + } |
| 57 | + else if(expr_type.id()==ID_integer) |
| 58 | + { |
| 59 | + out << value; |
| 60 | + } |
| 61 | + else |
| 62 | + DATA_INVARIANT(false, "unhandled constant: "+expr_type.id_string()); |
| 63 | + } |
| 64 | + else if(expr.id()==ID_symbol) |
| 65 | + { |
| 66 | + out << to_symbol_expr(expr).get_identifier(); |
| 67 | + } |
| 68 | + else |
| 69 | + out << "? " << expr.id(); |
25 | 70 |
|
26 | 71 | return out;
|
27 | 72 | }
|
0 commit comments