24 const exprt &bitvector_expr,
25 const typet &target_type,
38 std::size_t lower_bound,
39 std::size_t upper_bound)
42 result.
lb = lower_bound;
43 result.
ub = upper_bound;
51 if(result.
ub < result.
lb)
52 std::swap(result.
lb, result.
ub);
61 if(src.
id() == ID_unsignedbv)
63 else if(src.
id() == ID_signedbv)
65 else if(src.
id() == ID_bv)
67 else if(src.
id() == ID_c_enum)
69 else if(src.
id() == ID_c_bit_field)
79 const exprt &bitvector_expr,
87 operands.reserve(components.size());
89 for(
const auto &comp : components)
92 std::size_t component_bits;
93 if(component_bits_opt.has_value())
99 if(component_bits == 0)
118 if(component_bits_opt.has_value())
128 const exprt &bitvector_expr,
135 if(components.empty())
140 std::size_t component_bits;
141 if(widest_member.has_value())
146 if(component_bits == 0)
149 components.front().get_name(),
150 bv_to_expr(bitvector_expr, components.front().type(), endianness_map, ns),
154 const auto bounds =
map_bounds(endianness_map, 0, component_bits - 1);
156 const irep_idt &component_name = widest_member.has_value()
157 ? widest_member->first.get_name()
158 : components.front().get_name();
159 const typet &component_type = widest_member.has_value()
160 ? widest_member->first.type()
161 : components.front().type();
176 const exprt &bitvector_expr,
184 const std::size_t total_bits =
186 if(!num_elements.has_value())
188 if(!subtype_bits.has_value() || *subtype_bits == 0)
189 num_elements = total_bits;
194 !num_elements.has_value() || !subtype_bits.has_value() ||
195 *subtype_bits * *num_elements == total_bits,
196 "subtype width times array size should be total bitvector width");
199 operands.reserve(*num_elements);
200 for(std::size_t i = 0; i < *num_elements; ++i)
202 if(subtype_bits.has_value())
204 const std::size_t subtype_bits_int =
207 endianness_map, i * subtype_bits_int, ((i + 1) * subtype_bits_int) - 1);
213 bitvector_expr, bounds.ub, bounds.lb, std::move(type)},
221 bitvector_expr, array_type.
element_type(), endianness_map, ns));
225 return array_exprt{std::move(operands), array_type};
231 const exprt &bitvector_expr,
236 const std::size_t num_elements =
240 !subtype_bits.has_value() ||
241 *subtype_bits * num_elements ==
243 "subtype width times vector size should be total bitvector width");
246 operands.reserve(num_elements);
247 for(std::size_t i = 0; i < num_elements; ++i)
249 if(subtype_bits.has_value())
251 const std::size_t subtype_bits_int =
254 endianness_map, i * subtype_bits_int, ((i + 1) * subtype_bits_int) - 1);
260 bitvector_expr, bounds.ub, bounds.lb, std::move(type)},
268 bitvector_expr, vector_type.
element_type(), endianness_map, ns));
278 const exprt &bitvector_expr,
283 const std::size_t total_bits =
286 std::size_t subtype_bits;
287 if(subtype_bits_opt.has_value())
291 subtype_bits * 2 == total_bits,
292 "subtype width should be half of the total bitvector width");
295 subtype_bits = total_bits / 2;
297 const auto bounds_real =
map_bounds(endianness_map, 0, subtype_bits - 1);
298 const auto bounds_imag =
299 map_bounds(endianness_map, subtype_bits, subtype_bits * 2 - 1);
333 const exprt &bitvector_expr,
334 const typet &target_type,
340 if(target_type.
id() == ID_floatbv)
350 target_type.
id() == ID_c_enum || target_type.
id() == ID_c_enum_tag ||
351 target_type.
id() == ID_string)
357 if(target_type.
id() == ID_struct)
362 else if(target_type.
id() == ID_struct_tag)
369 result.
type() = target_type;
370 return std::move(result);
372 else if(target_type.
id() == ID_union)
375 bitvector_expr,
to_union_type(target_type), endianness_map, ns);
377 else if(target_type.
id() == ID_union_tag)
384 result.
type() = target_type;
387 else if(target_type.
id() == ID_array)
390 bitvector_expr,
to_array_type(target_type), endianness_map, ns);
392 else if(target_type.
id() == ID_vector)
397 else if(target_type.
id() == ID_complex)
405 false,
"bv_to_expr does not yet support ", target_type.
id_string());
414 const std::size_t bits_per_byte,
416 bool unpack_byte_array =
false);
427 std::size_t lower_bound,
428 std::size_t upper_bound,
429 const std::size_t bits_per_byte,
434 if(src.
id() == ID_array)
442 const typet &element_type = src.
type().
id() == ID_array
452 bytes.reserve(upper_bound - lower_bound);
453 for(std::size_t i = lower_bound; i < upper_bound; ++i)
471 std::size_t el_bytes,
473 const std::size_t bits_per_byte,
482 static std::size_t array_comprehension_index_counter = 0;
483 ++array_comprehension_index_counter;
485 "$array_comprehension_index_a_v" +
486 std::to_string(array_comprehension_index_counter),
494 unpack_rec(element, little_endian, {}, {}, bits_per_byte, ns,
false);
498 exprt body = sub_operands.front();
500 array_comprehension_index,
501 from_integer(el_bytes, array_comprehension_index.type())};
502 for(std::size_t i = 1; i < el_bytes; ++i)
510 const exprt array_vector_size = src.
type().
id() == ID_vector
515 std::move(array_comprehension_index),
545 const std::size_t bits_per_byte,
549 (element_bits + bits_per_byte - 1) / bits_per_byte);
551 if(!src_size.has_value() && !max_bytes.has_value())
554 el_bytes > 0 && element_bits % bits_per_byte == 0,
555 "unpacking of arrays with non-byte-aligned elements is not supported");
557 src, el_bytes, little_endian, bits_per_byte, ns);
566 if(element_bits > 0 && element_bits % bits_per_byte == 0)
568 if(!num_elements.has_value())
571 num_elements = (*max_bytes + el_bytes - 1) / el_bytes;
574 if(offset_bytes.has_value())
577 first_element = *offset_bytes / el_bytes;
579 byte_operands.resize(
581 *offset_bytes - (*offset_bytes % el_bytes),
582 *num_elements * el_bytes)),
591 num_elements = *max_bytes;
598 for(
mp_integer i = first_element; i < *num_elements; ++i)
603 (src_simp.
id() == ID_array || src_simp.
id() == ID_vector) &&
607 element = src_simp.
operands()[index_int];
619 ? std::min(
mp_integer{el_bytes}, *max_bytes - byte_operands.size())
621 const std::size_t element_max_bytes_int =
626 element, little_endian, {}, element_max_bytes, bits_per_byte, ns,
true);
629 byte_operands.insert(
630 byte_operands.end(), sub_operands.begin(), sub_operands.end());
632 if(max_bytes && byte_operands.size() >= *max_bytes)
636 const std::size_t size = byte_operands.size();
638 std::move(byte_operands),
655 std::size_t total_bits,
660 const std::size_t bits_per_byte,
664 std::move(bit_fields),
bv_typet{total_bits}};
677 std::make_move_iterator(sub.
operands().begin()),
678 std::make_move_iterator(sub.
operands().end()));
696 const std::size_t bits_per_byte,
708 for(
auto it = components.begin(); it != components.end(); ++it)
710 const auto &comp = *it;
719 component_bits.has_value() ||
720 (std::next(it) == components.end() && !bit_fields.has_value()),
721 "members of non-constant width should come last in a struct");
724 if(src.
id() == ID_struct)
730 if(bit_fields.has_value())
733 std::move(bit_fields->first),
744 if(offset_bytes.has_value())
749 if(*offset_in_member < 0)
750 offset_in_member.reset();
753 if(max_bytes.has_value())
756 if(*max_bytes_left < 0)
763 (component_bits.has_value() && *component_bits % bits_per_byte != 0))
765 if(!bit_fields.has_value())
769 bit_fields->first.insert(
770 little_endian ? bit_fields->first.begin() : bit_fields->first.end(),
772 bit_fields->second += bits_int;
780 !bit_fields.has_value(),
781 "all preceding members should have been processed");
784 component_bits.has_value() && offset_in_member.has_value() &&
785 *offset_in_member * bits_per_byte >= *component_bits)
789 byte_operands.resize(
790 byte_operands.size() +
805 byte_operands.insert(
807 std::make_move_iterator(sub.
operands().begin()),
808 std::make_move_iterator(sub.
operands().end()));
811 if(component_bits.has_value())
816 if(bit_fields.has_value())
819 std::move(bit_fields->first),
829 const std::size_t size = byte_operands.size();
831 std::move(byte_operands),
844 const std::size_t bits_per_byte,
858 *subtype_bits / bits_per_byte,
868 *subtype_bits / bits_per_byte,
872 byte_operands.insert(
874 std::make_move_iterator(sub_imag.
operands().begin()),
875 std::make_move_iterator(sub_imag.
operands().end()));
877 const std::size_t size = byte_operands.size();
879 std::move(byte_operands),
900 const std::size_t bits_per_byte,
902 bool unpack_byte_array)
904 if(src.
type().
id() == ID_array)
913 !unpack_byte_array && *element_bits == bits_per_byte &&
930 else if(src.
type().
id() == ID_vector)
939 !unpack_byte_array && *element_bits == bits_per_byte &&
955 else if(src.
type().
id() == ID_complex)
959 else if(src.
type().
id() == ID_struct || src.
type().
id() == ID_struct_tag)
962 src, little_endian, offset_bytes, max_bytes, bits_per_byte, ns);
964 else if(src.
type().
id() == ID_union || src.
type().
id() == ID_union_tag)
970 if(widest_member.has_value())
973 src, widest_member->first.get_name(), widest_member->first.
type()};
978 widest_member->second,
996 else if(src.
type().
id() == ID_pointer)
1007 else if(src.
id() == ID_string_constant)
1029 else if(src.
type().
id() != ID_empty)
1034 DATA_INVARIANT(bits_opt.has_value(),
"basic type should have a fixed size");
1040 if(max_bytes.has_value())
1042 const auto max_bits = *max_bytes * bits_per_byte;
1045 last_bit = std::min(last_bit, max_bits);
1049 bit_offset = std::max(
mp_integer{0}, last_bit - max_bits);
1055 auto const byte_type =
bv_typet{bits_per_byte};
1060 for(; bit_offset < last_bit; bit_offset += bits_per_byte)
1066 from_integer(bit_offset + bits_per_byte - 1, array_type.index_type()),
1074 byte_operands.push_back(extractbits);
1076 byte_operands.insert(byte_operands.begin(), extractbits);
1079 const std::size_t size = byte_operands.size();
1081 return array_exprt{std::move(byte_operands), std::move(array_type)};
1101 const typet &subtype,
1106 if(src.
type().
id() == ID_array)
1111 if(num_elements.has_value())
1115#pragma GCC diagnostic push
1117# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1119 operands.reserve(*num_elements);
1120 for(std::size_t i = 0; i < *num_elements; ++i)
1121#pragma GCC diagnostic pop
1130 tmp.
type() = subtype;
1131 tmp.
offset() = new_offset;
1137 if(src.
type().
id() == ID_array)
1150 static std::size_t array_comprehension_index_counter = 0;
1151 ++array_comprehension_index_counter;
1153 "$array_comprehension_index_a" +
1154 std::to_string(array_comprehension_index_counter),
1161 array_comprehension_index,
1164 array_comprehension_index.type())},
1168 body.
type() = subtype;
1169 body.
offset() = std::move(new_offset);
1172 std::move(array_comprehension_index),
1199 real.
type() = subtype;
1206 imag.
type() = subtype;
1265 src.
id() == ID_byte_extract_little_endian ||
1266 src.
id() == ID_byte_extract_big_endian);
1267 const bool little_endian = src.
id() == ID_byte_extract_little_endian;
1271 if(upper_bound_opt.has_value())
1275 upper_bound_opt.value(),
1277 src.
offset(), upper_bound_opt.value().
type())),
1280 else if(src.
type().
id() == ID_empty)
1284 const auto upper_bound_int_opt =
1291 lower_bound_int_opt,
1292 upper_bound_int_opt,
1299 if(src.
type().
id() == ID_array || src.
type().
id() == ID_vector)
1308 element_bits.has_value() && *element_bits >= 1 &&
1312 src, unpacked, subtype, *element_bits, ns);
1315 else if(src.
type().
id() == ID_complex)
1318 if(result.has_value())
1319 return std::move(*result);
1323 else if(src.
type().
id() == ID_struct || src.
type().
id() == ID_struct_tag)
1331 for(
const auto &comp : components)
1337 !component_bits.has_value() ||
1344 auto member_offset_opt =
1347 if(!member_offset_opt.has_value())
1356 member_offset_opt.value(), unpacked.
offset().
type()));
1359 tmp.
type() = comp.type();
1360 tmp.
offset() = new_offset;
1368 else if(src.
type().
id() == ID_union || src.
type().
id() == ID_union_tag)
1374 if(widest_member.has_value())
1377 tmp.
type() = widest_member->first.type();
1380 widest_member->first.get_name(),
1386 const exprt &root = unpacked.
op();
1391 if(root.
type().
id() == ID_vector)
1406 "offset bits are byte aligned");
1409 if(!size_bits.has_value())
1414 op0_bits.has_value(),
1415 "the extracted width or the source width must be known");
1416 size_bits = op0_bits;
1426 op.reserve(width_bytes);
1428 for(std::size_t i = 0; i < width_bytes; i++)
1431 std::size_t offset_int = little_endian ? (width_bytes - i - 1) : i;
1440 offset_i.is_constant() &&
1441 (root.
id() == ID_array || root.
id() == ID_vector) &&
1443 index < root.
operands().size() && index >= 0)
1454 if(width_bytes == 1)
1472 const exprt &value_as_byte_array,
1487 const typet &subtype,
1488 const exprt &value_as_byte_array,
1489 const exprt &non_const_update_bound,
1494 static std::size_t array_comprehension_index_counter = 0;
1495 ++array_comprehension_index_counter;
1497 "$array_comprehension_index_u_a_v" +
1498 std::to_string(array_comprehension_index_counter),
1503 array_comprehension_index, src.
offset().
type()),
1508 array_comprehension_index, non_const_update_bound.
type()),
1512 src.
offset(), non_const_update_bound.
type()),
1513 non_const_update_bound}};
1516 src.
id() == ID_byte_update_little_endian ||
1517 src.
id() == ID_byte_update_big_endian);
1518 const bool little_endian = src.
id() == ID_byte_update_little_endian;
1524 or_exprt{std::move(lower_bound), std::move(upper_bound)},
1528 value_as_byte_array,
1530 array_comprehension_index,
1532 src.
offset(), array_comprehension_index.
type())}},
1539 array_comprehension_index,
1540 std::move(array_comprehension_body),
1556 const typet &subtype,
1562 src.
id() == ID_byte_update_little_endian ||
1563 src.
id() == ID_byte_update_big_endian);
1564 const bool little_endian = src.
id() == ID_byte_update_little_endian;
1573 for(std::size_t i = 0; i < value_as_byte_array.
operands().size(); ++i)
1586 if(e.id() == ID_index)
1589 if(index_expr.
array() == src.
op() && index_expr.
index() == where)
1595 if(non_const_update_bound.has_value())
1601 *non_const_update_bound},
1606 if(result.
id() != ID_with)
1607 result =
with_exprt{result, std::move(where), std::move(update_value)};
1632 const typet &subtype,
1633 const exprt &subtype_size,
1634 const exprt &value_as_byte_array,
1635 const exprt &non_const_update_bound,
1636 const exprt &initial_bytes,
1637 const exprt &first_index,
1638 const exprt &first_update_value,
1641 const irep_idt extract_opcode = src.
id() == ID_byte_update_little_endian
1642 ? ID_byte_extract_little_endian
1643 : ID_byte_extract_big_endian;
1647 static std::size_t array_comprehension_index_counter = 0;
1648 ++array_comprehension_index_counter;
1650 "$array_comprehension_index_u_a_v_u" +
1651 std::to_string(array_comprehension_index_counter),
1663 array_comprehension_index, first_index.
type()),
1674 array_comprehension_index, first_index.
type()),
1679 value_as_byte_array,
1680 std::move(offset_expr),
1692 non_const_update_bound, subtype_size.
type()),
1707 non_const_update_bound, initial_bytes.
type()),
1709 subtype_size.
type()),
1716 array_comprehension_index, last_index.type()),
1731 value_as_byte_array,
1736 or_exprt{std::move(lower_bound), std::move(upper_bound)},
1741 array_comprehension_index, first_index.
type()),
1747 array_comprehension_index, last_index.type()),
1749 std::move(last_update_value),
1750 std::move(update_value)}}};
1754 array_comprehension_index,
1755 std::move(array_comprehension_body),
1772 const typet &subtype,
1773 const exprt &value_as_byte_array,
1784 subtype_size_opt.value(), src.
offset().
type()),
1799 const exprt update_size =
1803 if(non_const_update_bound.has_value())
1806 *non_const_update_bound, subtype_size.
type());
1811 value_as_byte_array.
id() == ID_array,
1812 "value should be an array expression if the update bound is constant");
1813 update_bound = update_size;
1829 value_as_byte_array,
1833 if(value_as_byte_array.
id() != ID_array)
1839 value_as_byte_array,
1840 *non_const_update_bound,
1852 std::size_t step_size = 1;
1859 std::size_t offset = 0;
1863 with_exprt result{src.
op(), first_index, first_update_value};
1865 auto lower_byte_update_array_vector_non_const_one_element =
1870 &value_as_byte_array,
1872 &result](std::size_t i) ->
void {
1887 value_as_byte_array,
1895 for(; offset + step_size <= value_as_byte_array.
operands().size();
1896 offset += step_size, ++i)
1898 lower_byte_update_array_vector_non_const_one_element(i);
1902 if(offset < value_as_byte_array.
operands().size())
1903 lower_byte_update_array_vector_non_const_one_element(i);
1923 const exprt &element_to_update,
1926 const exprt &value_as_byte_array,
1935 std::size_t first = 0;
1942 mp_integer offset_bits_in_target_element = offset_bits - bits_already_set;
1944 if(offset_bits_in_target_element < 0)
1947 value_as_byte_array.
id() != ID_array ||
1949 -offset_bits_in_target_element,
1950 "indices past the update should be handled below");
1953 offset_bits_in_target_element +=
1956 if(offset_bits_in_target_element < 0)
1963 update_elements > 0,
"indices before the update should be handled above");
1967 if(value_as_byte_array.
id() == ID_array)
1968 end = std::min(end, value_as_byte_array.
operands().size());
1971 const std::size_t update_size = update_values.size();
1980 offset_bits_in_target_element >= 0 &&
1983 new_value =
array_exprt{update_values, update_type};
1987 if(src.
id() == ID_byte_update_little_endian)
1988 std::reverse(update_values.begin(), update_values.end());
1989 if(offset_bits_in_target_element < 0)
1991 if(src.
id() == ID_byte_update_little_endian)
2008 const std::size_t offset_bits_int =
2010 const std::size_t subtype_bits_int =
2015 subtype_bits_int - 1,
2016 subtype_bits_int - offset_bits_int,
2029 const irep_idt extract_opcode = src.
id() == ID_byte_update_little_endian
2030 ? ID_byte_extract_little_endian
2031 : ID_byte_extract_big_endian;
2042 offset_bits_in_target_element = 0;
2058 if(non_const_update_bound.has_value())
2066 *non_const_update_bound,
2070 *non_const_update_bound,
2080 remaining_update_bytes},
2099 const typet &subtype,
2101 const exprt &value_as_byte_array,
2105 const bool is_array = src.
type().
id() == ID_array;
2122 !subtype_bits.has_value() || value_as_byte_array.
id() != ID_array)
2125 src, subtype, value_as_byte_array, non_const_update_bound, ns);
2128 std::size_t num_elements =
2135 elements.reserve(num_elements);
2139 for(; i < num_elements && (i + 1) * *subtype_bits <= offset_bits; ++i)
2145 i * *subtype_bits < offset_bits + value_as_byte_array.operands().size() *
2146 src.get_bits_per_byte();
2155 value_as_byte_array,
2156 non_const_update_bound,
2161 for(; i < num_elements; ++i)
2184 const exprt &value_as_byte_array,
2189 elements.reserve(struct_type.
components().size());
2192 for(
const auto &comp : struct_type.
components())
2206 if(!offset_bits.has_value() || !element_width.has_value())
2213 const irep_idt extract_opcode = src.
id() == ID_byte_update_little_endian
2214 ? ID_byte_extract_little_endian
2215 : ID_byte_extract_big_endian;
2235 bu, value_as_byte_array, non_const_update_bound, ns),
2250 *offset_bits >= *element_width ||
2251 (value_as_byte_array.
id() == ID_array && *offset_bits < 0 &&
2255 elements.push_back(member);
2266 value_as_byte_array,
2267 non_const_update_bound,
2288 const exprt &value_as_byte_array,
2295 widest_member.has_value(),
2296 "lower_byte_update of union of unknown size is not supported");
2300 src.
op(), widest_member->first.get_name(), widest_member->first.
type()});
2301 bu.
type() = widest_member->first.type();
2304 widest_member->first.get_name(),
2319 const exprt &value_as_byte_array,
2323 if(src.
type().
id() == ID_array || src.
type().
id() == ID_vector)
2326 if(src.
type().
id() == ID_vector)
2335 if(value_as_byte_array.
id() != ID_array)
2338 non_const_update_bound.has_value(),
2339 "constant update bound should yield an array expression");
2341 src, *subtype, value_as_byte_array, *non_const_update_bound, ns);
2348 non_const_update_bound,
2357 value_as_byte_array,
2358 non_const_update_bound,
2362 else if(src.
type().
id() == ID_struct || src.
type().
id() == ID_struct_tag)
2367 value_as_byte_array,
2368 non_const_update_bound,
2373 else if(src.
type().
id() == ID_union || src.
type().
id() == ID_union_tag)
2378 value_as_byte_array,
2379 non_const_update_bound,
2386 src.
type().
id() == ID_c_enum || src.
type().
id() == ID_c_enum_tag)
2391 CHECK_RETURN(type_width.has_value() && *type_width > 0);
2395 if(value_as_byte_array.
id() == ID_array)
2396 update_bytes = value_as_byte_array.
operands();
2400 value_as_byte_array,
2407 const std::size_t update_size_bits =
2409 const std::size_t bit_width = std::max(type_bits, update_size_bits);
2411 const bool is_little_endian = src.
id() == ID_byte_update_little_endian;
2415 if(bit_width > type_bits)
2422 if(!is_little_endian)
2428 if(non_const_update_bound.has_value())
2432 src.
id() == ID_byte_update_little_endian,
2439 for(std::size_t i = 0; i < update_bytes.size(); ++i)
2445 *non_const_update_bound},
2453 if(is_little_endian)
2458 power(2, bit_width) -
power(2, bit_width - update_size_bits),
2473 if(!is_little_endian)
2475 mask_shifted.true_case().
swap(mask_shifted.false_case());
2486 if(is_little_endian)
2487 std::reverse(value.operands().begin(), value.operands().end());
2489 exprt zero_extended;
2490 if(bit_width > update_size_bits)
2497 if(!is_little_endian)
2503 zero_extended = value;
2508 shl_exprt{zero_extended, offset_in_bits},
2510 if(!is_little_endian)
2512 value_shifted.true_case().
swap(value_shifted.false_case());
2519 bitor_exprt bitor_expr{bitand_expr, value_shifted};
2521 if(bit_width > type_bits)
2524 bitor_expr.type(), src.
id() == ID_byte_update_little_endian, ns);
2525 const auto bounds =
map_bounds(endianness_map, 0, type_bits - 1);
2531 bitor_expr, bounds.ub, bounds.lb,
bv_typet{type_bits}},
2542 false,
"lower_byte_update does not yet support ", src.
type().
id_string());
2549 src.
id() == ID_byte_update_little_endian ||
2550 src.
id() == ID_byte_update_big_endian,
2551 "byte update expression should either be little or big endian");
2572 simplify(update_size_expr_opt.value(), ns);
2574 const irep_idt extract_opcode = src.
id() == ID_byte_update_little_endian
2575 ? ID_byte_extract_little_endian
2576 : ID_byte_extract_big_endian;
2579 if(!update_size_expr_opt.value().is_constant())
2580 non_const_update_bound = *update_size_expr_opt;
2588 update_bits.has_value(),
"constant size-of should imply fixed bit width");
2591 if(update_bits_int % bits_per_byte != 0)
2595 "non-byte aligned type expected to be a bitvector type");
2606 const exprt overlapping_byte =
2609 size_t n_extra_bits = bits_per_byte - update_bits_int % bits_per_byte;
2611 overlapping_byte, n_extra_bits - 1, 0,
bv_typet{n_extra_bits}};
2615 update_value,
bv_typet{update_bits_int}),
2622 update_bits_int / bits_per_byte, update_size_expr_opt->type());
2651 src.
id() == ID_byte_update_little_endian ||
2652 src.
id() == ID_byte_update_big_endian)
2657 src.
id() == ID_byte_extract_little_endian ||
2658 src.
id() == ID_byte_extract_big_endian)
API to expression classes for bitvectors.
const shift_exprt & to_shift_expr(const exprt &expr)
Cast an exprt to a shift_exprt.
const concatenation_exprt & to_concatenation_expr(const exprt &expr)
Cast an exprt to a concatenation_exprt.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
Expression classes for byte-level operators.
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
bitvector_typet index_type()
unsignedbv_typet size_type()
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Expression to define a mapping from an argument (index) to elements.
Array constructor from list of elements.
typet index_type() const
The type of the index expressions into any instance of this type.
const exprt & size() const
const typet & element_type() const
The type of the elements of the array.
A base class for expressions that are predicates, i.e., Boolean-typed, and that take exactly two argu...
Bit-wise negation of bit-vectors.
Base class of fixed-width bit-vector types.
std::size_t get_width() const
Fixed-width bit-vector without numerical interpretation.
Expression corresponding to op() where the bytes starting at position offset (given in number of byte...
const exprt & offset() const
std::size_t get_bits_per_byte() const
const exprt & value() const
Type for C bit fields These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (...
Complex constructor from a pair of numbers.
Imaginary part of the expression describing a complex number.
Real part of the expression describing a complex number.
Complex numbers made of pair of given subtype.
Concatenation of bit-vector operands.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Union constructor to support unions without any member (a GCC/Clang feature).
Maps a big-endian offset to a little-endian offset.
size_t number_of_bits() const
size_t map_bit(size_t bit) const
Base class for all expressions.
std::vector< exprt > operandst
bool is_constant() const
Return whether the expression is a constant.
typet & type()
Return the type of the expression.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
The trinary if-then-else operator.
const std::string & id_string() const
const irep_idt & id() const
Extract member of struct or union.
Modulo defined as lhs-(rhs * truncate(lhs/rhs)).
Binary multiplication Associativity is not specified.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The plus expression Associativity is not specified.
Fixed-width bit-vector with two's complement interpretation.
Struct constructor from list of elements.
Structure type, corresponds to C style structs.
const componentst & components() const
std::vector< componentt > componentst
Expression to hold a symbol (variable)
const typet & subtype() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
The unary minus expression.
Union constructor from single element.
optionalt< std::pair< struct_union_typet::componentt, mp_integer > > find_widest_union_component(const namespacet &ns) const
Determine the member of maximum bit width in a union type.
Fixed-width bit-vector with unsigned binary interpretation.
Vector constructor from list of elements.
const constant_exprt & size() const
typet index_type() const
The type of any index expression into an instance of this type.
const typet & element_type() const
The type of the elements of the vector.
Operator to update elements in structs and arrays.
#define Forall_operands(it, expr)
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
Deprecated expression utility functions.
static exprt lower_byte_update_byte_array_vector(const byte_update_exprt &src, const typet &subtype, const array_exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src to an array/vector of bytes using the byte array value_as_byte_array as updat...
static exprt unpack_array_vector(const exprt &src, const optionalt< mp_integer > &src_size, const mp_integer &element_bits, bool little_endian, const optionalt< mp_integer > &offset_bytes, const optionalt< mp_integer > &max_bytes, const std::size_t bits_per_byte, const namespacet &ns)
Rewrite an array or vector into its individual bytes.
static exprt bv_to_expr(const exprt &bitvector_expr, const typet &target_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to an expression of type target_type.
static exprt bv_to_union_expr(const exprt &bitvector_expr, const union_typet &union_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to a union-typed expression.
static complex_exprt bv_to_complex_expr(const exprt &bitvector_expr, const complex_typet &complex_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to a complex-typed expression.
static exprt lower_byte_update_struct(const byte_update_exprt &src, const struct_typet &struct_type, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src to a struct typed operand using the byte array value_as_byte_array as update ...
static exprt unpack_rec(const exprt &src, bool little_endian, const optionalt< mp_integer > &offset_bytes, const optionalt< mp_integer > &max_bytes, const std::size_t bits_per_byte, const namespacet &ns, bool unpack_byte_array=false)
Rewrite an object into its individual bytes.
static exprt::operandst instantiate_byte_array(const exprt &src, std::size_t lower_bound, std::size_t upper_bound, const std::size_t bits_per_byte, const namespacet &ns)
Build the individual bytes to be used in an update.
exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
rewrite byte extraction from an array to byte extraction from a concatenation of array index expressi...
static optionalt< exprt > lower_byte_extract_complex(const byte_extract_exprt &src, const byte_extract_exprt &unpacked, const namespacet &ns)
Rewrite a byte extraction of a complex-typed result to byte extraction of the individual components t...
static exprt lower_byte_update_array_vector(const byte_update_exprt &src, const typet &subtype, const optionalt< mp_integer > &subtype_bits, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src to an array/vector typed operand using the byte array value_as_byte_array as ...
bitvector_typet adjust_width(const typet &src, std::size_t new_width)
changes the width of the given bitvector type
static vector_exprt bv_to_vector_expr(const exprt &bitvector_expr, const vector_typet &vector_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to a vector-typed expression.
static exprt lower_byte_update_array_vector_non_const(const byte_update_exprt &src, const typet &subtype, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src to an array/vector typed operand, using the byte array value_as_byte_array as...
static struct_exprt bv_to_struct_expr(const exprt &bitvector_expr, const struct_typet &struct_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to a struct-typed expression.
static array_exprt unpack_complex(const exprt &src, bool little_endian, const std::size_t bits_per_byte, const namespacet &ns)
Rewrite a complex_exprt into its individual bytes.
static exprt unpack_array_vector_no_known_bounds(const exprt &src, std::size_t el_bytes, bool little_endian, const std::size_t bits_per_byte, const namespacet &ns)
Rewrite an array or vector into its individual bytes when no maximum number of bytes is known.
static exprt lower_byte_update_single_element(const byte_update_exprt &src, const mp_integer &offset_bits, const exprt &element_to_update, const mp_integer &subtype_bits, const mp_integer &bits_already_set, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Byte update a struct/array/vector element.
static array_exprt bv_to_array_expr(const exprt &bitvector_expr, const array_typet &array_type, const endianness_mapt &endianness_map, const namespacet &ns)
Convert a bitvector-typed expression bitvector_expr to an array-typed expression.
static boundst map_bounds(const endianness_mapt &endianness_map, std::size_t lower_bound, std::size_t upper_bound)
Map bit boundaries according to endianness.
static exprt lower_byte_update_union(const byte_update_exprt &src, const union_typet &union_type, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src to a union typed operand using the byte array value_as_byte_array as update v...
exprt lower_byte_operators(const exprt &src, const namespacet &ns)
Rewrite an expression possibly containing byte-extract or -update expressions to more fundamental ope...
static exprt lower_byte_extract_array_vector(const byte_extract_exprt &src, const byte_extract_exprt &unpacked, const typet &subtype, const mp_integer &element_bits, const namespacet &ns)
Rewrite a byte extraction of an array/vector-typed result to byte extraction of the individual compon...
static void process_bit_fields(exprt::operandst &&bit_fields, std::size_t total_bits, exprt::operandst &dest, bool little_endian, const optionalt< mp_integer > &offset_bytes, const optionalt< mp_integer > &max_bytes, const std::size_t bits_per_byte, const namespacet &ns)
Extract bytes from a sequence of bitvector-typed elements.
static array_exprt unpack_struct(const exprt &src, bool little_endian, const optionalt< mp_integer > &offset_bytes, const optionalt< mp_integer > &max_bytes, const std::size_t bits_per_byte, const namespacet &ns)
Rewrite a struct-typed expression into its individual bytes.
static exprt lower_byte_update_byte_array_vector_non_const(const byte_update_exprt &src, const typet &subtype, const exprt &value_as_byte_array, const exprt &non_const_update_bound, const namespacet &ns)
Apply a byte update src to an array/vector of bytes using the byte-array typed expression value_as_by...
static exprt lower_byte_update(const byte_update_exprt &src, const exprt &value_as_byte_array, const optionalt< exprt > &non_const_update_bound, const namespacet &ns)
Apply a byte update src using the byte array value_as_byte_array as update value.
static exprt lower_byte_update_array_vector_unbounded(const byte_update_exprt &src, const typet &subtype, const exprt &subtype_size, const exprt &value_as_byte_array, const exprt &non_const_update_bound, const exprt &initial_bytes, const exprt &first_index, const exprt &first_update_value, const namespacet &ns)
Apply a byte update src to an array/vector typed operand, using the byte array value_as_byte_array as...
output_type narrow_cast(input_type value)
Alias for static_cast intended to be used for numeric casting Rationale: Easier to grep than static_c...
nonstd::optional< T > optionalt
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
optionalt< mp_integer > member_offset_bits(const struct_typet &type, const irep_idt &member, const namespacet &ns)
optionalt< exprt > member_offset_expr(const member_exprt &member_expr, const namespacet &ns)
optionalt< exprt > size_of_expr(const typet &type, const namespacet &ns)
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
bool simplify(exprt &expr, const namespacet &ns)
exprt simplify_expr(exprt src, const namespacet &ns)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
#define CHECK_RETURN(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool can_cast_type< bitvector_typet >(const typet &type)
Check whether a reference to a typet is a bitvector_typet.
const string_constantt & to_string_constant(const exprt &expr)
static bool failed(bool error_indicator)
const type_with_subtypet & to_type_with_subtype(const typet &type)