ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
bitblast_conv.h
Go to the documentation of this file.
1#ifndef _ESBMC_SOLVERS_SMT_BITBLAST_CONV_H_
2#define _ESBMC_SOLVERS_SMT_BITBLAST_CONV_H_
3
5#include <sat_iface.h>
6
8{
9 // Record all the things.
10public:
11#define bitblast_sort_downcast(x) static_cast<const bitblast_smt_sort *>(x)
12
16 bitblast_smt_sort(smt_sort_kind i, unsigned int _width, bool _sign)
17 : smt_sort(i, _width), sign(_sign)
18 {
19 }
22 unsigned long rangewidth,
23 unsigned long domwidth)
24 : smt_sort(i, rangewidth, domwidth), sign(false)
25 {
26 }
27
28 bool sign;
30 {
31 }
32};
33
35{
36public:
37#define bitblast_ast_downcast(x) static_cast<const bitblast_smt_ast *>(x)
39 {
40 }
41
42 // Everything is, to a greater or lesser extend, a vector of booleans
44};
45
47{
48public:
49 typedef enum
50 {
54 } shiftt;
55
58
59 // The plan: have a mk_func_app method available, that's called by the
60 // subclass when appropriate, and if there's an operation on bitvectors
61 // in there, we convert it to an operation on literals, implemented using
62 // the abstract api below.
63 //
64 // This means that the subclass relinquishes all control over both ASTs
65 // and sorts: this class will manage all of that. Only operations on literals
66 // will reach the subclass (via the aforementioned api), and crucially that's
67 // _all_ operations. Operations on booleans from a higher level should all
68 // pass through this class before becoming a literal operation.
69 //
70 // (This alas is not the truth yet, but it's an aim).
71 //
72 // The remanining flexibility options available to the solver are then only
73 // in the domain of logical operations on literals, although all kinds of
74 // other API things can be fudged, such as tuples and arrays.
75
76 // Update: SAT solver no longer subclasses this class, it instead provides a
77 // SAT api pointer. Documentation not yet updated, sorry.
78
79 // smt_solver_baset apis we fufil
80
81 virtual smt_astt mk_func_app(
82 const smt_sort *ressort,
84 const smt_ast *const *args,
85 unsigned int num);
86 virtual smt_sort *mk_sort(smt_sort_kind k, ...);
87 virtual smt_ast *mk_smt_int(const BigInt &intval);
88 virtual smt_ast *mk_smt_real(const std::string &value);
89 virtual smt_ast *mk_smt_bvint(const BigInt &inval, bool sign, unsigned int w);
90 virtual smt_ast *mk_smt_bool(bool boolval);
91 virtual smt_astt mk_smt_symbol(const std::string &name, const smt_sort *sort);
92 virtual smt_sort *mk_struct_sort(const type2tc &t);
93 virtual smt_ast *mk_extract(
94 const smt_ast *src,
95 unsigned int high,
96 unsigned int low,
97 const smt_sort *s);
98 virtual tvt l_get(const smt_ast *a);
99 virtual void assert_ast(const smt_ast *a);
100
101 // Some gunk
102 expr2tc get_bool(const smt_ast *a);
103 expr2tc get_bv(const type2tc &t, const smt_ast *a);
104
105 // Bitblasting utilities, mostly from CBMC.
106 bool process_clause(const bvt &bv, bvt &dest);
108 mk_ast_equality(const smt_ast *a, const smt_ast *b, const smt_sort *ressort);
109 virtual literalt land(const bvt &bv);
110 virtual literalt lor(const bvt &bv);
111 void eliminate_duplicates(const bvt &bv, bvt &dest);
112 void bvand(const bvt &bv0, const bvt &bv1, bvt &output);
113 void bvor(const bvt &bv0, const bvt &bv1, bvt &output);
114 void bvxor(const bvt &bv0, const bvt &bv1, bvt &output);
115 void bvnot(const bvt &bv0, bvt &output);
116 void full_adder(
117 const bvt &op0,
118 const bvt &op1,
119 bvt &output,
120 literalt carry_in,
123 literalt carry_out(const bvt &a, const bvt &b, literalt c);
124 literalt equal(const bvt &op0, const bvt &op1);
126 lt_or_le(bool or_equal, const bvt &bv0, const bvt &bv1, bool is_signed);
127 void invert(bvt &bv);
128 void barrel_shift(const bvt &op, const shiftt s, const bvt &dist, bvt &out);
129 void shift(const bvt &inp, const shiftt &s, unsigned long d, bvt &out);
130 literalt unsigned_less_than(const bvt &arg0, const bvt &arg1);
131 void unsigned_multiplier(const bvt &op0, const bvt &bv1, bvt &output);
132 void signed_multiplier(const bvt &op0, const bvt &bv1, bvt &output);
133 void cond_negate(const bvt &vals, bvt &out, literalt cond);
134 void negate(const bvt &inp, bvt &oup);
135 void incrementer(
136 const bvt &inp,
137 const literalt &carryin,
138 literalt carryout,
139 bvt &oup);
140 void signed_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem);
141 void unsigned_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem);
142 void unsigned_multiplier_no_overflow(const bvt &op0, const bvt &op1, bvt &r);
144 const bvt &op0,
145 const bvt &op1,
146 bvt &res,
147 bool subtract,
148 bool is_signed);
149 void adder_no_overflow(const bvt &op0, const bvt &op1, bvt &res);
150 bool is_constant(const bvt &bv);
151
153 {
154 return new bitblast_smt_ast(this, ressort);
155 }
156
157 // Members
159};
160
161#endif /* _ESBMC_SOLVERS_SMT_BITBLAST_CONV_H_ */
Definition bigint.hh:58
literalt carry(literalt a, literalt b, literalt c)
Definition bitblast_conv.cpp:559
virtual smt_astt mk_func_app(const smt_sort *ressort, smt_func_kind f, const smt_ast *const *args, unsigned int num)
Definition bitblast_conv.cpp:24
void signed_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem)
Definition bitblast_conv.cpp:670
void unsigned_multiplier_no_overflow(const bvt &op0, const bvt &op1, bvt &r)
Definition bitblast_conv.cpp:757
void negate(const bvt &inp, bvt &oup)
Definition bitblast_conv.cpp:641
literalt lt_or_le(bool or_equal, const bvt &bv0, const bvt &bv1, bool is_signed)
Definition bitblast_conv.cpp:891
void signed_multiplier(const bvt &op0, const bvt &bv1, bvt &output)
Definition bitblast_conv.cpp:607
void eliminate_duplicates(const bvt &bv, bvt &dest)
Definition bitblast_conv.cpp:525
virtual smt_ast * mk_smt_real(const std::string &value)
Create a real in a smt_ast.
Definition bitblast_conv.cpp:329
expr2tc get_bv(const type2tc &t, const smt_ast *a)
Definition bitblast_conv.cpp:462
void bvor(const bvt &bv0, const bvt &bv1, bvt &output)
Definition bitblast_conv.cpp:990
void barrel_shift(const bvt &op, const shiftt s, const bvt &dist, bvt &out)
Definition bitblast_conv.cpp:922
sat_iface * sat_api
Definition bitblast_conv.h:158
virtual smt_astt mk_smt_symbol(const std::string &name, const smt_sort *sort)
Definition bitblast_conv.cpp:362
virtual smt_ast * mk_smt_bool(bool boolval)
Create a boolean.
Definition bitblast_conv.cpp:352
shiftt
Definition bitblast_conv.h:50
@ LRIGHT
Definition bitblast_conv.h:52
@ LEFT
Definition bitblast_conv.h:51
@ ARIGHT
Definition bitblast_conv.h:53
literalt carry_out(const bvt &a, const bvt &b, literalt c)
Definition bitblast_conv.cpp:868
void bvxor(const bvt &bv0, const bvt &bv1, bvt &output)
Definition bitblast_conv.cpp:1002
expr2tc get_bool(const smt_ast *a)
Definition bitblast_conv.cpp:445
virtual literalt lor(const bvt &bv)
Definition bitblast_conv.cpp:1072
void bvand(const bvt &bv0, const bvt &bv1, bvt &output)
Definition bitblast_conv.cpp:978
void cond_negate(const bvt &vals, bvt &out, literalt cond)
Definition bitblast_conv.cpp:628
literalt equal(const bvt &op0, const bvt &op1)
Definition bitblast_conv.cpp:878
virtual smt_ast * mk_extract(const smt_ast *src, unsigned int high, unsigned int low, const smt_sort *s)
Definition bitblast_conv.cpp:397
bitblast_convt(bool int_encoding, const namespacet &_ns, sat_iface *sat_api)
Definition bitblast_conv.cpp:4
bool is_constant(const bvt &bv)
Definition bitblast_conv.cpp:860
void unsigned_multiplier(const bvt &op0, const bvt &bv1, bvt &output)
Definition bitblast_conv.cpp:576
literalt unsigned_less_than(const bvt &arg0, const bvt &arg1)
Definition bitblast_conv.cpp:569
virtual smt_sort * mk_struct_sort(const type2tc &t)
Definition bitblast_conv.cpp:392
bitblast_smt_ast * new_ast(smt_sortt ressort)
Definition bitblast_conv.h:152
void shift(const bvt &inp, const shiftt &s, unsigned long d, bvt &out)
Definition bitblast_conv.cpp:947
void adder_no_overflow(const bvt &op0, const bvt &op1, bvt &res, bool subtract, bool is_signed)
Definition bitblast_conv.cpp:800
virtual tvt l_get(const smt_ast *a)
Definition bitblast_conv.cpp:456
void unsigned_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem)
Definition bitblast_conv.cpp:715
void incrementer(const bvt &inp, const literalt &carryin, literalt carryout, bvt &oup)
Definition bitblast_conv.cpp:652
virtual void assert_ast(const smt_ast *a)
Definition bitblast_conv.cpp:16
void invert(bvt &bv)
Definition bitblast_conv.cpp:916
virtual literalt land(const bvt &bv)
Definition bitblast_conv.cpp:1024
virtual smt_ast * mk_smt_bvint(const BigInt &inval, bool sign, unsigned int w)
Definition bitblast_conv.cpp:336
void bvnot(const bvt &bv0, bvt &output)
Definition bitblast_conv.cpp:1013
bitblast_smt_ast * mk_ast_equality(const smt_ast *a, const smt_ast *b, const smt_sort *ressort)
Definition bitblast_conv.cpp:412
virtual smt_sort * mk_sort(smt_sort_kind k,...)
Definition bitblast_conv.cpp:285
bool process_clause(const bvt &bv, bvt &dest)
Definition bitblast_conv.cpp:492
virtual smt_ast * mk_smt_int(const BigInt &intval)
Create an integer smt_ast.
Definition bitblast_conv.cpp:323
~bitblast_convt()
Definition bitblast_conv.cpp:12
void full_adder(const bvt &op0, const bvt &op1, bvt &output, literalt carry_in, literalt &carry_out)
Definition bitblast_conv.cpp:538
Definition bitblast_conv.h:35
bvt bv
Definition bitblast_conv.h:43
bitblast_smt_ast(smt_solver_baset *ctx, const smt_sort *s)
Definition bitblast_conv.h:38
bitblast_smt_sort(smt_sort_kind i, unsigned long rangewidth, unsigned long domwidth)
Definition bitblast_conv.h:20
bitblast_smt_sort(smt_sort_kind i, unsigned int _width, bool _sign)
Definition bitblast_conv.h:16
virtual ~bitblast_smt_sort()
Definition bitblast_conv.h:29
bool sign
Definition bitblast_conv.h:28
bitblast_smt_sort(smt_sort_kind i)
Definition bitblast_conv.h:13
Definition literal.h:8
Definition namespace.h:10
Definition sat_iface.h:9
Definition smt_ast.h:33
smt_ast(smt_solver_baset *ctx, smt_sortt s)
Definition smt_solver.h:1270
The base SMT-conversion class/interface.
Definition smt_solver.h:170
smt_solver_baset(const namespacet &_ns, const optionst &_options)
Primary constructor.
Definition smt_solver.cpp:78
bool int_encoding
Whether we are encoding expressions in integer mode or not.
Definition smt_solver.h:1121
Definition smt_sort.h:40
smt_sort(smt_sort_kind i)
Definition smt_sort.h:47
Definition threeval.h:10
Definition toml.hpp:1531
pthread_cond_t cond
Definition cuda.h:50
irep_container< type2t > type2tc
Definition irep2.h:430
irep_container< expr2t > expr2tc
Definition irep2.h:431
std::vector< literalt > bvt
Definition minisat_conv.h:20
const smt_ast * smt_astt
Definition smt_ast.h:30
smt_sort_kind
Identifier for SMT sort kinds Each different kind of sort (i.e., arrays, bv's, bools,...
Definition smt_sort.h:11
const smt_sort * smt_sortt
Definition smt_sort.h:37
smt_func_kind
Identifiers for SMT functions.
Definition smtlib_conv.h:25
#define false
Definition stdbool.h:10
void subtract(int64_t *A, int64_t *B, int64_t *C, int64_t a_rows, int64_t a_cols, int64_t b_rows, int64_t b_cols)
Definition umath.c:75