32 const typet &src_type,
const bvt &src,
54 std::size_t src_width=src.size();
57 if(dest_width==0 || src_width==0)
61 dest.reserve(dest_width);
63 if(dest_type.
id()==ID_complex)
65 if(src_type==dest_type.
subtype())
67 dest.insert(dest.end(), src.begin(), src.end());
70 for(std::size_t i=src.size(); i<dest_width; i++)
75 else if(src_type.
id()==ID_complex)
78 bvt lower, upper, lower_res, upper_res;
79 lower.assign(src.begin(), src.begin()+src.size()/2);
80 upper.assign(src.begin()+src.size()/2, src.end());
86 lower_res.size() + upper_res.size() == dest_width,
87 "lower result bitvector size plus upper result bitvector size shall "
88 "equal the destination bitvector size");
90 dest.insert(dest.end(), upper_res.begin(), upper_res.end());
95 if(src_type.
id()==ID_complex)
98 dest_type.
id() == ID_complex,
99 "destination type shall be of complex type when source type is of "
101 if(dest_type.
id()==ID_signedbv ||
102 dest_type.
id()==ID_unsignedbv ||
103 dest_type.
id()==ID_floatbv ||
104 dest_type.
id()==ID_fixedbv ||
105 dest_type.
id()==ID_c_enum ||
106 dest_type.
id()==ID_c_enum_tag ||
107 dest_type.
id()==ID_bool)
112 tmp_src.resize(src.size()/2);
119 case bvtypet::IS_RANGE:
120 if(src_bvtype==bvtypet::IS_UNSIGNED ||
121 src_bvtype==bvtypet::IS_SIGNED ||
122 src_bvtype==bvtypet::IS_C_BOOL)
129 dest.resize(dest_width);
130 for(std::size_t i=0; i<dest.size(); i++)
136 else if(src_bvtype==bvtypet::IS_RANGE)
141 if(dest_from==src_from)
161 case bvtypet::IS_FLOAT:
167 case bvtypet::IS_FLOAT:
172 case bvtypet::IS_SIGNED:
173 case bvtypet::IS_C_ENUM:
178 case bvtypet::IS_UNSIGNED:
179 case bvtypet::IS_C_BOOL:
186 src_width == dest_width,
187 "source bitvector size shall equal the destination bitvector size");
192 case bvtypet::IS_UNKNOWN:
193 case bvtypet::IS_RANGE:
194 case bvtypet::IS_VERILOG_UNSIGNED:
195 case bvtypet::IS_VERILOG_SIGNED:
196 case bvtypet::IS_FIXED:
197 if(src_type.
id()==ID_bool)
208 src_width == 1,
"bitvector of type boolean shall have width one");
210 for(
auto &literal : dest)
211 literal =
prop.
land(literal, src[0]);
219 case bvtypet::IS_FIXED:
220 if(src_bvtype==bvtypet::IS_FIXED)
224 std::size_t dest_fraction_bits=
226 std::size_t dest_int_bits=dest_width-dest_fraction_bits;
227 std::size_t op_fraction_bits=
229 std::size_t op_int_bits=src_width-op_fraction_bits;
231 dest.resize(dest_width);
236 for(std::size_t i=0; i<dest_fraction_bits; i++)
239 std::size_t p=dest_fraction_bits-i-1;
241 if(i<op_fraction_bits)
242 dest[p]=src[op_fraction_bits-i-1];
247 for(std::size_t i=0; i<dest_int_bits; i++)
250 std::size_t p=dest_fraction_bits+i;
251 INVARIANT(p < dest_width,
"bit index shall be within bounds");
254 dest[p]=src[i+op_fraction_bits];
256 dest[p]=src[src_width-1];
261 else if(src_bvtype==bvtypet::IS_BV)
264 src_width == dest_width,
265 "source bitvector width shall equal the destination bitvector width");
269 else if(src_bvtype==bvtypet::IS_UNSIGNED ||
270 src_bvtype==bvtypet::IS_SIGNED ||
271 src_bvtype==bvtypet::IS_C_BOOL ||
272 src_bvtype==bvtypet::IS_C_ENUM)
276 std::size_t dest_fraction_bits=
279 for(std::size_t i=0; i<dest_fraction_bits; i++)
282 for(std::size_t i=0; i<dest_width-dest_fraction_bits; i++)
290 if(src_bvtype==bvtypet::IS_SIGNED || src_bvtype==bvtypet::IS_C_ENUM)
301 else if(src_type.
id()==ID_bool)
304 std::size_t fraction_bits=
308 src_width == 1,
"bitvector of type boolean shall have width one");
310 for(std::size_t i=0; i<dest_width; i++)
313 dest.push_back(src[0]);
322 case bvtypet::IS_UNSIGNED:
323 case bvtypet::IS_SIGNED:
324 case bvtypet::IS_C_ENUM:
327 case bvtypet::IS_FLOAT:
332 case bvtypet::IS_FIXED:
334 std::size_t op_fraction_bits=
337 for(std::size_t i=0; i<dest_width; i++)
339 if(i<src_width-op_fraction_bits)
340 dest.push_back(src[i+op_fraction_bits]);
343 if(dest_bvtype==bvtypet::IS_SIGNED)
344 dest.push_back(src[src_width-1]);
353 bvt fraction_bits_bv=src;
354 fraction_bits_bv.resize(op_fraction_bits);
363 case bvtypet::IS_UNSIGNED:
364 case bvtypet::IS_SIGNED:
365 case bvtypet::IS_C_ENUM:
366 case bvtypet::IS_C_BOOL:
373 src_bvtype==bvtypet::IS_SIGNED || src_bvtype==bvtypet::IS_C_ENUM;
375 for(std::size_t i=0; i<dest_width; i++)
378 dest.push_back(src[i]);
379 else if(sign_extension)
380 dest.push_back(src[src_width-1]);
388 case bvtypet::IS_VERILOG_UNSIGNED:
390 for(std::size_t i=0; i<dest_width; i++)
392 std::size_t src_index=i*2;
394 if(src_index<src_width)
395 dest.push_back(src[src_index]);
404 case bvtypet::IS_VERILOG_SIGNED:
406 for(std::size_t i=0; i<dest_width; i++)
408 std::size_t src_index=i*2;
410 if(src_index<src_width)
411 dest.push_back(src[src_index]);
413 dest.push_back(src.back());
422 src_width == dest_width,
423 "source bitvector width shall equal the destination bitvector width");
427 case bvtypet::IS_RANGE:
429 case bvtypet::IS_UNKNOWN:
430 if(src_type.
id() == ID_bool)
435 src_width == 1,
"bitvector of type boolean shall have width one");
437 for(std::size_t i = 0; i < dest_width; i++)
440 dest.push_back(src[0]);
450 case bvtypet::IS_VERILOG_UNSIGNED:
451 if(src_bvtype==bvtypet::IS_UNSIGNED ||
452 src_bvtype==bvtypet::IS_C_BOOL ||
453 src_type.
id()==ID_bool)
455 for(std::size_t i=0, j=0; i<dest_width; i+=2, j++)
458 dest.push_back(src[j]);
467 else if(src_bvtype==bvtypet::IS_SIGNED)
469 for(std::size_t i=0, j=0; i<dest_width; i+=2, j++)
472 dest.push_back(src[j]);
474 dest.push_back(src.back());
481 else if(src_bvtype==bvtypet::IS_VERILOG_UNSIGNED)
486 if(dest_width<src_width)
487 dest.resize(dest_width);
491 while(dest.size()<dest_width)
503 src_width == dest_width,
504 "source bitvector width shall equal the destination bitvector width");
508 case bvtypet::IS_C_BOOL:
511 if(src_bvtype==bvtypet::IS_FLOAT)
514 dest[0]=!float_utils.
is_zero(src);
516 else if(src_bvtype==bvtypet::IS_C_BOOL)
524 case bvtypet::IS_UNKNOWN:
525 case bvtypet::IS_VERILOG_SIGNED:
526 if(dest_type.
id()==ID_array)
528 if(src_width==dest_width)
534 else if(
ns.
follow(dest_type).
id() == ID_struct)
557 typedef std::map<irep_idt, std::size_t> op_mapt;
560 for(std::size_t i=0; i<op_comp.size(); i++)
561 op_map[op_comp[i].get_name()]=i;
568 std::size_t offset=dest_offsets[i];
569 std::size_t comp_width=
boolbv_width(dest_comp[i].type());
573 op_mapt::const_iterator it=
574 op_map.find(dest_comp[i].get_name());
581 for(std::size_t j=0; j<comp_width; j++)
587 if(dest_comp[i].type()!=dest_comp[it->second].type())
590 for(std::size_t j=0; j<comp_width; j++)
595 std::size_t op_offset=op_offsets[it->second];
596 for(std::size_t j=0; j<comp_width; j++)
597 dest[offset+j]=src[op_offset+j];
613 if(expr.
op().
type().
id() == ID_range)
620 else if(from==0 && to==0)