@@ -93,32 +93,44 @@ constant_exprt lower_to_aval_bval(const constant_exprt &src)
9393
9494exprt aval (const exprt &src)
9595{
96- PRECONDITION (is_aval_bval (src.type ()));
97- auto width = aval_bval_width (src.type ());
98- return extractbits_exprt{
99- src, from_integer (0 , integer_typet ()), bv_typet{width}};
96+ if (is_aval_bval (src.type ()))
97+ {
98+ auto width = aval_bval_width (src.type ());
99+ return extractbits_exprt{src, 0 , bv_typet{width}};
100+ }
101+ else
102+ {
103+ auto width = to_bitvector_type (src.type ()).get_width ();
104+ return typecast_exprt::conditional_cast (src, bv_typet{width});
105+ }
100106}
101107
102108exprt bval (const exprt &src)
103109{
104- PRECONDITION (is_aval_bval (src.type ()));
105- auto width = aval_bval_width (src.type ());
106- return extractbits_exprt{
107- src, from_integer (width, integer_typet ()), bv_typet{width}};
110+ if (is_aval_bval (src.type ()))
111+ {
112+ auto width = aval_bval_width (src.type ());
113+ return extractbits_exprt{src, width, bv_typet{width}};
114+ }
115+ else
116+ {
117+ // zeros, signaling 0/1
118+ auto width = to_bitvector_type (src.type ()).get_width ();
119+ return bv_typet{width}.all_zeros_expr ();
120+ }
108121}
109122
110123static exprt adjust_size (const exprt &src, std::size_t dest_width)
111124{
112125 auto src_width = to_bv_type (src.type ()).get_width ();
113126 if (dest_width > src_width)
114127 {
115- auto zeros = from_integer ( 0 , bv_typet{dest_width - src_width});
128+ auto zeros = bv_typet{dest_width - src_width}. all_zeros_expr ( );
116129 return concatenation_exprt{{zeros, src}, bv_typet{dest_width}};
117130 }
118131 else if (dest_width < src_width)
119132 {
120- return extractbits_exprt{
121- src, from_integer (0 , integer_typet{}), bv_typet{dest_width}};
133+ return extractbits_exprt{src, 0 , bv_typet{dest_width}};
122134 }
123135 else
124136 return src;
@@ -152,3 +164,27 @@ exprt aval_bval_conversion(const exprt &src, const typet &dest)
152164 return combine_aval_bval (new_aval, new_bval, dest);
153165 }
154166}
167+
168+ static exprt concatenate (const exprt::operandst &operands)
169+ {
170+ std::size_t width = 0 ;
171+ for (auto &op : operands)
172+ width += to_bv_type (op.type ()).get_width ();
173+
174+ return concatenation_exprt{operands, bv_typet{width}};
175+ }
176+
177+ exprt aval_bval_concatenation (
178+ const exprt::operandst &operands,
179+ const typet &type)
180+ {
181+ exprt::operandst new_aval, new_bval;
182+
183+ for (auto &op : operands)
184+ {
185+ new_aval.push_back (aval (op));
186+ new_bval.push_back (bval (op));
187+ }
188+
189+ return combine_aval_bval (concatenate (new_aval), concatenate (new_bval), type);
190+ }
0 commit comments