cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
bv_arithmetic.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
10
#ifndef CPROVER_UTIL_BV_ARITHMETIC_H
11
#define CPROVER_UTIL_BV_ARITHMETIC_H
12
13
#include <iosfwd>
14
15
#include "
mp_arith.h
"
16
#include "
format_spec.h
"
17
18
class
constant_exprt
;
19
class
typet
;
20
21
class
bv_spect
22
{
23
public
:
24
std::size_t
width
;
25
bool
is_signed
;
26
27
explicit
bv_spect
(
const
typet
&type)
28
{
29
from_type
(type);
30
}
31
32
void
from_type
(
const
typet
&type);
33
34
bv_spect
():
width
(0),
is_signed
(false)
35
{
36
}
37
38
mp_integer
max_value
()
const
;
39
mp_integer
min_value
()
const
;
40
41
typet
to_type
()
const
;
42
43
bool
operator==
(
const
bv_spect
&other)
const
44
{
45
return
width
==other.
width
&&
is_signed
==other.
is_signed
;
46
}
47
};
48
49
class
bv_arithmetict
50
{
51
public
:
52
bv_spect
spec
;
53
54
explicit
bv_arithmetict
(
const
bv_spect
&_spec):
55
spec
(_spec),
value
(0)
56
{
57
}
58
59
bv_arithmetict
():
value
(0)
60
{
61
}
62
63
explicit
bv_arithmetict
(
const
constant_exprt
&expr)
64
{
65
from_expr
(expr);
66
}
67
68
void
negate
();
69
70
void
make_zero
()
71
{
72
value
=0;
73
}
74
75
bool
is_zero
()
const
{
return
value
==0; }
76
77
// performs conversion to bit-vector format
78
void
from_integer
(
const
mp_integer
&i);
79
80
// performs conversion from ieee floating point format
81
void
change_spec
(
const
bv_spect
&dest_spec);
82
mp_integer
to_integer
()
const
{
return
value
; }
83
84
void
print
(std::ostream &out)
const
;
85
86
std::string
to_ansi_c_string
()
const
87
{
88
return
format
(
format_spect
());
89
}
90
91
std::string
format
(
const
format_spect
&format_spec)
const
;
92
93
// expressions
94
constant_exprt
to_expr
()
const
;
95
void
from_expr
(
const
constant_exprt
&expr);
96
97
bv_arithmetict
&
operator/=
(
const
bv_arithmetict
&other);
98
bv_arithmetict
&
operator*=
(
const
bv_arithmetict
&other);
99
bv_arithmetict
&
operator+=
(
const
bv_arithmetict
&other);
100
bv_arithmetict
&
operator-=
(
const
bv_arithmetict
&other);
101
bv_arithmetict
&
operator%=
(
const
bv_arithmetict
&other);
102
103
bool
operator<
(
const
bv_arithmetict
&other);
104
bool
operator<=
(
const
bv_arithmetict
&other);
105
bool
operator>
(
const
bv_arithmetict
&other);
106
bool
operator>=
(
const
bv_arithmetict
&other);
107
bool
operator==
(
const
bv_arithmetict
&other);
108
bool
operator!=
(
const
bv_arithmetict
&other);
109
bool
operator==
(
int
i);
110
111
std::ostream &
operator<<
(std::ostream &out)
112
{
113
return
out <<
to_ansi_c_string
();
114
}
115
116
// turn into natural number representation
117
void
unpack
(
const
mp_integer
&i) {
value
=i;
adjust
(); }
118
mp_integer
pack
()
const
;
119
120
protected
:
121
// we store negative numbers as such
122
mp_integer
value
;
123
124
// puts the value back into its range
125
void
adjust
();
126
};
127
128
#endif
// CPROVER_UTIL_BV_ARITHMETIC_H
bv_arithmetict
Definition
bv_arithmetic.h:50
bv_arithmetict::bv_arithmetict
bv_arithmetict(const bv_spect &_spec)
Definition
bv_arithmetic.h:54
bv_arithmetict::to_integer
mp_integer to_integer() const
Definition
bv_arithmetic.h:82
bv_arithmetict::operator==
bool operator==(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:159
bv_arithmetict::operator>=
bool operator>=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:154
bv_arithmetict::value
mp_integer value
Definition
bv_arithmetic.h:122
bv_arithmetict::bv_arithmetict
bv_arithmetict()
Definition
bv_arithmetic.h:59
bv_arithmetict::operator<
bool operator<(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:139
bv_arithmetict::change_spec
void change_spec(const bv_spect &dest_spec)
Definition
bv_arithmetic.cpp:174
bv_arithmetict::unpack
void unpack(const mp_integer &i)
Definition
bv_arithmetic.h:117
bv_arithmetict::to_expr
constant_exprt to_expr() const
Definition
bv_arithmetic.cpp:82
bv_arithmetict::from_integer
void from_integer(const mp_integer &i)
Definition
bv_arithmetic.cpp:60
bv_arithmetict::operator*=
bv_arithmetict & operator*=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:99
bv_arithmetict::spec
bv_spect spec
Definition
bv_arithmetic.h:52
bv_arithmetict::operator<=
bool operator<=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:144
bv_arithmetict::operator<<
std::ostream & operator<<(std::ostream &out)
Definition
bv_arithmetic.h:111
bv_arithmetict::print
void print(std::ostream &out) const
Definition
bv_arithmetic.cpp:46
bv_arithmetict::format
std::string format(const format_spect &format_spec) const
Definition
bv_arithmetic.cpp:51
bv_arithmetict::adjust
void adjust()
Definition
bv_arithmetic.cpp:66
bv_arithmetict::is_zero
bool is_zero() const
Definition
bv_arithmetic.h:75
bv_arithmetict::operator+=
bv_arithmetict & operator+=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:109
bv_arithmetict::operator!=
bool operator!=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:169
bv_arithmetict::from_expr
void from_expr(const constant_exprt &expr)
Definition
bv_arithmetic.cpp:180
bv_arithmetict::bv_arithmetict
bv_arithmetict(const constant_exprt &expr)
Definition
bv_arithmetic.h:63
bv_arithmetict::operator%=
bv_arithmetict & operator%=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:129
bv_arithmetict::make_zero
void make_zero()
Definition
bv_arithmetic.h:70
bv_arithmetict::operator-=
bv_arithmetict & operator-=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:119
bv_arithmetict::negate
void negate()
bv_arithmetict::to_ansi_c_string
std::string to_ansi_c_string() const
Definition
bv_arithmetic.h:86
bv_arithmetict::operator/=
bv_arithmetict & operator/=(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:87
bv_arithmetict::operator>
bool operator>(const bv_arithmetict &other)
Definition
bv_arithmetic.cpp:149
bv_arithmetict::pack
mp_integer pack() const
Definition
bv_arithmetic.cpp:75
bv_spect
Definition
bv_arithmetic.h:22
bv_spect::width
std::size_t width
Definition
bv_arithmetic.h:24
bv_spect::bv_spect
bv_spect(const typet &type)
Definition
bv_arithmetic.h:27
bv_spect::bv_spect
bv_spect()
Definition
bv_arithmetic.h:34
bv_spect::operator==
bool operator==(const bv_spect &other) const
Definition
bv_arithmetic.h:43
bv_spect::is_signed
bool is_signed
Definition
bv_arithmetic.h:25
bv_spect::from_type
void from_type(const typet &type)
Definition
bv_arithmetic.cpp:34
bv_spect::min_value
mp_integer min_value() const
Definition
bv_arithmetic.cpp:28
bv_spect::to_type
typet to_type() const
Definition
bv_arithmetic.cpp:15
bv_spect::max_value
mp_integer max_value() const
Definition
bv_arithmetic.cpp:22
constant_exprt
A constant literal expression.
Definition
std_expr.h:2997
format_spect
Definition
format_spec.h:16
typet
The type of an expression, extends irept.
Definition
type.h:29
format_spec.h
mp_arith.h
mp_integer
BigInt mp_integer
Definition
smt_terms.h:17
util
bv_arithmetic.h
Generated by
1.17.0