cprover
Loading...
Searching...
No Matches
boolbv_replication.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "boolbv.h"
10
11#include <util/arith_tools.h>
12#include <util/bitvector_expr.h>
13
15{
16 std::size_t width=boolbv_width(expr.type());
17
18 if(width==0)
19 return conversion_failed(expr);
20
21 mp_integer times = numeric_cast_v<mp_integer>(expr.times());
22
23 bvt bv;
24 bv.resize(width);
25
26 const std::size_t u_times = numeric_cast_v<std::size_t>(times);
27 const bvt &op = convert_bv(expr.op());
28
30 op.size() * u_times == bv.size(),
31 "result bitvector width shall be equal to the operand bitvector width times"
32 "the number of replications");
33
34 std::size_t bit_idx = 0;
35
36 for(std::size_t i = 0; i < u_times; i++)
37 {
38 for(const auto &bit : op)
39 {
40 bv[bit_idx] = bit;
41 bit_idx++;
42 }
43 }
44
45 return bv;
46}
API to expression classes for bitvectors.
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition: boolbv.cpp:40
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
Definition: boolbv.cpp:84
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:99
virtual bvt convert_replication(const replication_exprt &expr)
typet & type()
Return the type of the expression.
Definition: expr.h:82
Bit-vector replication.
constant_exprt & times()
std::vector< literalt > bvt
Definition: literal.h:201
BigInt mp_integer
Definition: smt_terms.h:12
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:423