@@ -44,19 +44,19 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)
4444 else if (type_id==ID_unsignedbv)
4545 {
4646 const auto width = to_unsignedbv_type (type).get_width ();
47- int_value = bv2integer ( id2string ( value) , width, false );
47+ int_value = bvrep2integer ( value, width, false );
4848 return false ;
4949 }
5050 else if (type_id==ID_signedbv)
5151 {
5252 const auto width = to_signedbv_type (type).get_width ();
53- int_value = bv2integer ( id2string ( value) , width, true );
53+ int_value = bvrep2integer ( value, width, true );
5454 return false ;
5555 }
5656 else if (type_id==ID_c_bool)
5757 {
5858 const auto width = to_c_bool_type (type).get_width ();
59- int_value = bv2integer ( id2string ( value) , width, false );
59+ int_value = bvrep2integer ( value, width, false );
6060 return false ;
6161 }
6262 else if (type_id==ID_c_enum)
@@ -65,13 +65,13 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)
6565 if (subtype.id ()==ID_signedbv)
6666 {
6767 const auto width = to_signedbv_type (type).get_width ();
68- int_value = bv2integer ( id2string ( value) , width, true );
68+ int_value = bvrep2integer ( value, width, true );
6969 return false ;
7070 }
7171 else if (subtype.id ()==ID_unsignedbv)
7272 {
7373 const auto width = to_unsignedbv_type (type).get_width ();
74- int_value = bv2integer ( id2string ( value) , width, false );
74+ int_value = bvrep2integer ( value, width, false );
7575 return false ;
7676 }
7777 }
@@ -83,17 +83,17 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)
8383
8484 if (subtype.id ()==ID_signedbv)
8585 {
86- int_value = bv2integer ( id2string ( value) , width, true );
86+ int_value = bvrep2integer ( value, width, true );
8787 return false ;
8888 }
8989 else if (subtype.id ()==ID_unsignedbv)
9090 {
91- int_value = bv2integer ( id2string ( value) , width, false );
91+ int_value = bvrep2integer ( value, width, false );
9292 return false ;
9393 }
9494 else if (subtype.id () == ID_c_bool)
9595 {
96- int_value = bv2integer ( id2string ( value) , width, false );
96+ int_value = bvrep2integer ( value, width, false );
9797 return false ;
9898 }
9999 }
@@ -136,28 +136,28 @@ constant_exprt from_integer(
136136 else if (type_id==ID_unsignedbv)
137137 {
138138 std::size_t width=to_unsignedbv_type (type).get_width ();
139- return constant_exprt (integer2bv (int_value, width), type);
139+ return constant_exprt (integer2bvrep (int_value, width), type);
140140 }
141141 else if (type_id==ID_bv)
142142 {
143143 std::size_t width=to_bv_type (type).get_width ();
144- return constant_exprt (integer2bv (int_value, width), type);
144+ return constant_exprt (integer2bvrep (int_value, width), type);
145145 }
146146 else if (type_id==ID_signedbv)
147147 {
148148 std::size_t width=to_signedbv_type (type).get_width ();
149- return constant_exprt (integer2bv (int_value, width), type);
149+ return constant_exprt (integer2bvrep (int_value, width), type);
150150 }
151151 else if (type_id==ID_c_enum)
152152 {
153153 const std::size_t width =
154154 to_c_enum_type (type).subtype ().get_size_t (ID_width);
155- return constant_exprt (integer2bv (int_value, width), type);
155+ return constant_exprt (integer2bvrep (int_value, width), type);
156156 }
157157 else if (type_id==ID_c_bool)
158158 {
159159 std::size_t width=to_c_bool_type (type).get_width ();
160- return constant_exprt (integer2bv (int_value, width), type);
160+ return constant_exprt (integer2bvrep (int_value, width), type);
161161 }
162162 else if (type_id==ID_bool)
163163 {
@@ -175,7 +175,7 @@ constant_exprt from_integer(
175175 else if (type_id==ID_c_bit_field)
176176 {
177177 std::size_t width=to_c_bit_field_type (type).get_width ();
178- return constant_exprt (integer2bv (int_value, width), type);
178+ return constant_exprt (integer2bvrep (int_value, width), type);
179179 }
180180 else if (type_id==ID_fixedbv)
181181 {
@@ -280,7 +280,7 @@ void mp_max(mp_integer &a, const mp_integer &b)
280280// / \param src: the bitvector representation
281281// / \param width: the number of bits in the bitvector
282282// / \param bit_index: index (0 is the least significant)
283- bool get_bitvector_bit (
283+ bool get_bvrep_bit (
284284 const irep_idt &src,
285285 std::size_t width,
286286 std::size_t bit_index)
@@ -314,14 +314,14 @@ make_bvrep(const std::size_t width, const std::function<bool(std::size_t)> f)
314314// / \param width: the width of the bit-vector
315315// / \param f: the functor
316316// / \returns new bitvector representation
317- irep_idt bitvector_bitwise_op (
317+ irep_idt bvrep_bitwise_op (
318318 const irep_idt &a,
319319 const irep_idt &b,
320320 const std::size_t width,
321321 const std::function<bool (bool , bool )> f)
322322{
323323 return make_bvrep (width, [&a, &b, &width, f](std::size_t i) {
324- return f (get_bitvector_bit (a, width, i), get_bitvector_bit (b, width, i));
324+ return f (get_bvrep_bit (a, width, i), get_bvrep_bit (b, width, i));
325325 });
326326}
327327
@@ -331,12 +331,25 @@ irep_idt bitvector_bitwise_op(
331331// / \param width: the width of the bit-vector
332332// / \param f: the functor
333333// / \returns new bitvector representation
334- irep_idt bitvector_bitwise_op (
334+ irep_idt bvrep_bitwise_op (
335335 const irep_idt &a,
336336 const std::size_t width,
337337 const std::function<bool (bool )> f)
338338{
339339 return make_bvrep (width, [&a, &width, f](std::size_t i) {
340- return f (get_bitvector_bit (a, width, i));
340+ return f (get_bvrep_bit (a, width, i));
341341 });
342342}
343+
344+ // / convert an integer to bit-vector representation with given width
345+ irep_idt integer2bvrep (const mp_integer &src, std::size_t width)
346+ {
347+ return integer2binary (src, width);
348+ }
349+
350+ // / convert a bit-vector representation (possibly signed) to integer
351+ mp_integer bvrep2integer (const irep_idt &src, std::size_t width, bool is_signed)
352+ {
353+ PRECONDITION (src.size () == width);
354+ return binary2integer (id2string (src), is_signed);
355+ }
0 commit comments