CBMC
bitvector_types.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Pre-defined bitvector types
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "bitvector_types.h"
13 
14 #include "arith_tools.h"
15 #include "bv_arithmetic.h"
16 #include "std_expr.h"
17 #include "string2int.h"
18 
20 {
21  return constant_exprt{
22  make_bvrep(get_width(), [](std::size_t) { return false; }), *this};
23 }
24 
26 {
27  return constant_exprt{
28  make_bvrep(get_width(), [](std::size_t) { return true; }), *this};
29 }
30 
32 {
33  const irep_idt integer_bits = get(ID_integer_bits);
34  DATA_INVARIANT(!integer_bits.empty(), "integer bits should be set");
35  return unsafe_string2unsigned(id2string(integer_bits));
36 }
37 
38 std::size_t floatbv_typet::get_f() const
39 {
40  const irep_idt &f = get(ID_f);
41  DATA_INVARIANT(!f.empty(), "the mantissa should be set");
43 }
44 
46 {
47  return bv_spect(*this).min_value();
48 }
49 
51 {
52  return bv_spect(*this).max_value();
53 }
54 
56 {
57  return from_integer(0, *this);
58 }
59 
61 {
62  return from_integer(smallest(), *this);
63 }
64 
66 {
67  return from_integer(largest(), *this);
68 }
irep_idt make_bvrep(const std::size_t width, const std::function< bool(std::size_t)> f)
construct a bit-vector representation from a functor
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:99
Pre-defined bitvector types.
std::size_t get_width() const
Definition: std_types.h:925
mp_integer min_value() const
mp_integer max_value() const
constant_exprt all_ones_expr() const
constant_exprt all_zeros_expr() const
A constant literal expression.
Definition: std_expr.h:3000
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
bool empty() const
Definition: dstring.h:89
std::size_t get_integer_bits() const
std::size_t get_f() const
constant_exprt largest_expr() const
Return an expression representing the largest value of this type.
mp_integer largest() const
Return the largest value that can be represented using this type.
constant_exprt zero_expr() const
Return an expression representing the zero value of this type.
constant_exprt smallest_expr() const
Return an expression representing the smallest value of this type.
mp_integer smallest() const
Return the smallest value that can be represented using this type.
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:44
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
BigInt mp_integer
Definition: smt_terms.h:17
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:534
API to expression classes.
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:35