36 for(std::size_t i=0; i<dest.size(); ++i)
43 memory[numeric_cast_v<std::size_t>(address + i)];
60 std::size_t address_val = numeric_cast_v<std::size_t>(address);
65 for(
size_t i=0; i<to_read; i++)
72 memory[numeric_cast_v<std::size_t>(address + i)];
80 dest.push_back(value);
106 if(cell.second.initialized==
120 if(ty.
id()==ID_struct)
128 result+=subtype_count;
132 else if(ty.
id()==ID_array)
136 if(array_size_vec.size()!=1)
141 result=array_size_vec[0]*subtype_count;
161 const typet &source_type,
165 if(source_type.
id()==ID_struct)
170 for(
const auto &comp : st.components())
176 if(!comp_offset.has_value() && !component_byte_size.has_value())
179 if(*comp_offset + *component_byte_size > offset)
183 comp.type(), offset - *comp_offset, subtype_result);
184 result=previous_member_offsets+subtype_result;
192 previous_member_offsets+=component_count;
198 else if(source_type.
id()==ID_array)
204 if(array_size_vec.size()!=1)
209 if(!elem_size_bytes.has_value() || *elem_size_bytes == 0)
216 mp_integer this_idx = offset / (*elem_size_bytes);
217 if(this_idx>=array_size_vec[0])
222 at.element_type(), offset % (*elem_size_bytes), subtype_result);
224 result=subtype_result+(elem_size_leaves*this_idx);
242 const typet &source_type,
246 if(source_type.
id()==ID_struct)
251 for(
const auto &comp : st.components())
256 if(component_count>cell_offset)
260 comp.type(), cell_offset, subtype_result);
261 const auto member_offset_result =
264 result = member_offset_result.value() + subtype_result;
269 cell_offset-=component_count;
275 else if(source_type.
id()==ID_array)
280 if(array_size_vec.size()!=1)
284 if(!elem_size.has_value())
291 mp_integer this_idx=full_cell_offset/elem_count;
292 if(this_idx>=array_size_vec[0])
297 at.element_type(), full_cell_offset % elem_count, subtype_result);
298 result = subtype_result + ((*elem_size) * this_idx);
305 return full_cell_offset!=0;
316 if(expr.
type().
id()==ID_struct)
319 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
322 for(
const auto &op : expr.
operands())
324 if(op.type().id() == ID_code)
333 if(tmp.size()==sub_size)
335 for(std::size_t i=0; i<tmp.size(); ++i)
336 dest.push_back(tmp[i]);
347 else if(expr.
type().
id() == ID_pointer)
352 if(
object.
id() == ID_address_of)
354 else if(
const auto i = numeric_cast<mp_integer>(
object))
360 const auto i = numeric_cast<mp_integer>(expr);
361 if(i && i->is_zero())
365 else if(expr.
type().
id()==ID_floatbv)
371 else if(expr.
type().
id()==ID_fixedbv)
377 else if(expr.
type().
id()==ID_c_bool)
387 else if(expr.
type().
id()==ID_string)
397 if(
const auto i = numeric_cast<mp_integer>(expr))
401 else if(expr.
id()==ID_struct)
406 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
410 for(
const auto &op : expr.
operands())
412 if(op.type().id() == ID_code)
423 for(std::size_t i=0; i<tmp.size(); i++)
424 dest.push_back(tmp[i]);
435 else if(expr.
id()==ID_side_effect)
447 output.
error() <<
"heap memory allocation not fully implemented "
450 std::stringstream buffer;
464 else if(expr.
id()==ID_bitor)
467 throw id2string(expr.
id())+
" expects at least two operands";
470 for(
const auto &op : expr.
operands())
478 else if(expr.
id()==ID_bitand)
481 throw id2string(expr.
id())+
" expects at least two operands";
484 for(
const auto &op : expr.
operands())
493 else if(expr.
id()==ID_bitxor)
496 throw id2string(expr.
id())+
" expects at least two operands";
499 for(
const auto &op : expr.
operands())
508 else if(expr.
id()==ID_bitnot)
520 else if(expr.
id()==ID_shl)
524 if(tmp0.size()==1 && tmp1.size()==1)
533 else if(expr.
id() == ID_shr || expr.
id() == ID_lshr)
537 if(tmp0.size()==1 && tmp1.size()==1)
546 else if(expr.
id()==ID_ashr)
550 if(tmp0.size()==1 && tmp1.size()==1)
559 else if(expr.
id()==ID_ror)
563 if(tmp0.size()==1 && tmp1.size()==1)
572 else if(expr.
id()==ID_rol)
576 if(tmp0.size()==1 && tmp1.size()==1)
585 else if(expr.
id()==ID_equal ||
586 expr.
id()==ID_notequal ||
595 if(tmp0.size()==1 && tmp1.size()==1)
600 if(expr.
id()==ID_equal)
602 else if(expr.
id()==ID_notequal)
604 else if(expr.
id()==ID_le)
606 else if(expr.
id()==ID_ge)
608 else if(expr.
id()==ID_lt)
610 else if(expr.
id()==ID_gt)
616 else if(expr.
id()==ID_or)
619 throw id2string(expr.
id())+
" expects at least one operand";
623 for(
const auto &op : expr.
operands())
627 if(tmp.size()==1 && tmp.front()!=0)
636 else if(expr.
id()==ID_if)
646 tmp1 =
evaluate(if_expr.true_case());
648 tmp1 =
evaluate(if_expr.false_case());
652 return {tmp1.front()};
656 else if(expr.
id()==ID_and)
659 throw id2string(expr.
id())+
" expects at least one operand";
663 for(
const auto &op : expr.
operands())
667 if(tmp.size()==1 && tmp.front()==0)
676 else if(expr.
id()==ID_not)
681 return {tmp.front() == 0};
685 else if(expr.
id()==ID_plus)
689 for(
const auto &op : expr.
operands())
698 else if(expr.
id()==ID_mult)
703 if(expr.
type().
id()==ID_fixedbv)
710 else if(expr.
type().
id()==ID_floatbv)
719 for(
const auto &op : expr.
operands())
724 if(expr.
type().
id()==ID_fixedbv)
734 else if(expr.
type().
id()==ID_floatbv)
750 else if(expr.
id()==ID_minus)
755 if(tmp0.size()==1 && tmp1.size()==1)
756 return {tmp0.front() - tmp1.front()};
759 else if(expr.
id()==ID_div)
764 if(tmp0.size()==1 && tmp1.size()==1)
765 return {tmp0.front() / tmp1.front()};
768 else if(expr.
id()==ID_unary_minus)
773 return {-tmp0.front()};
776 else if(expr.
id()==ID_address_of)
780 else if(expr.
id()==ID_pointer_offset)
783 throw "pointer_offset expects a pointer operand";
799 return {byte_offset};
805 expr.
id() == ID_dereference || expr.
id() == ID_index ||
806 expr.
id() == ID_symbol || expr.
id() == ID_member ||
807 expr.
id() == ID_byte_extract_little_endian ||
808 expr.
id() == ID_byte_extract_big_endian)
814 if(address.is_zero())
819 if(expr.
id() == ID_index)
825 evaluated_index.
index() =
839 if(simplified.
id() == expr.
id())
844 else if(!address.is_zero())
847 expr.
id() == ID_byte_extract_little_endian ||
848 expr.
id() == ID_byte_extract_big_endian)
854 !extract_from.empty(),
855 "evaluate_address should have returned address == 0");
862 target_type_leaves > 0)
867 extract_from.begin() + numeric_cast_v<std::size_t>(memory_offset),
868 extract_from.begin() +
869 numeric_cast_v<std::size_t>(memory_offset + target_type_leaves));
877 dest.resize(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
889 else if(expr.
id()==ID_typecast)
897 if(expr.
type().
id()==ID_pointer)
901 else if(expr.
type().
id()==ID_signedbv)
907 else if(expr.
type().
id()==ID_unsignedbv)
917 else if(expr.
id()==ID_array)
920 for(
const auto &op : expr.
operands())
923 dest.insert(dest.end(), tmp.begin(), tmp.end());
927 else if(expr.
id()==ID_array_of)
932 if(ty.size().id()==ID_infinity)
939 std::size_t size_int = numeric_cast_v<std::size_t>(size[0]);
942 for(std::size_t i=0; i<size_int; ++i)
943 dest.insert(dest.end(), tmp.begin(), tmp.end());
947 else if(expr.
id()==ID_with)
957 if(!new_value.empty() && where.size()==1 && !
unbounded_size(subtype))
965 mp_integer need_size=(where_idx+1)*subtype_size;
967 if(dest.size()<need_size)
968 dest.resize(numeric_cast_v<std::size_t>(need_size), 0);
970 for(std::size_t i=0; i<new_value.size(); ++i)
971 dest[numeric_cast_v<std::size_t>((where_idx * subtype_size) + i)] =
977 else if(expr.
id()==ID_nil)
981 else if(expr.
id()==ID_infinity)
983 if(expr.
type().
id()==ID_signedbv)
989 output.
error() <<
"!! failed to evaluate expression: "
991 << expr.
id() <<
"[" << expr.
type().
id() <<
"]"
1000 if(expr.
id()==ID_symbol)
1006 interpretert::memory_mapt::const_iterator m_it1=
1010 return m_it1->second;
1014 interpretert::memory_mapt::const_iterator m_it2=
1018 return m_it2->second;
1024 else if(expr.
id()==ID_dereference)
1029 return tmp0.front();
1031 else if(expr.
id()==ID_index)
1039 return base+tmp1.front();
1042 else if(expr.
id()==ID_member)
1052 for(
const auto &comp : struct_type.
components())
1054 if(comp.get_name()==component_name)
1064 else if(expr.
id()==ID_byte_extract_little_endian ||
1065 expr.
id()==ID_byte_extract_big_endian)
1070 if(extract_offset.size()==1 && !extract_from.empty())
1074 byte_extract_expr.op0().type(), extract_offset[0], memory_offset))
1079 else if(expr.
id()==ID_if)
1087 if(result.size()==1)
1090 else if(expr.
id()==ID_typecast)
1097 output.
error() <<
"!! failed to evaluate address: "
API to expression classes for bitvectors.
const shift_exprt & to_shift_expr(const exprt &expr)
Cast an exprt to a shift_exprt.
const bitnot_exprt & to_bitnot_expr(const exprt &expr)
Cast an exprt to a bitnot_exprt.
const shl_exprt & to_shl_expr(const exprt &expr)
Cast an exprt to a shl_exprt.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
Expression classes for byte-level operators.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
const c_bool_typet & to_c_bool_type(const typet &type)
Cast a typet to a c_bool_typet.
Operator to return the address of an object.
const typet & element_type() const
The type of the elements of the array.
std::size_t get_width() const
const irep_idt & get_value() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
bool has_operands() const
Return true if there is at least one operand.
bool is_true() const
Return whether the expression is a constant representing true.
bool is_boolean() const
Return whether the expression represents a Boolean.
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
void from_integer(const mp_integer &i)
void from_expr(const constant_exprt &expr)
void set_value(const mp_integer &_v)
const mp_integer & get_value() const
void unpack(const mp_integer &i)
void from_expr(const constant_exprt &expr)
void from_integer(const mp_integer &i)
The trinary if-then-else operator.
void clear_input_flags()
Clears memoy r/w flag initialization.
exprt get_value(const typet &type, const mp_integer &offset=0, bool use_non_det=false)
retrives the constant value at memory location offset as an object of type type
mp_integer base_address_to_actual_size(const mp_integer &address) const
mp_integer evaluate_address(const exprt &expr, bool fail_quietly=false)
bool byte_offset_to_memory_offset(const typet &source_type, const mp_integer &byte_offset, mp_integer &result)
Supposing the caller has an mp_vector representing a value with type 'source_type',...
goto_functionst::function_mapt::const_iterator function
symbol_exprt address_to_symbol(const mp_integer &address) const
void build_memory_map()
Creates a memory map of all static symbols in the program.
std::vector< mp_integer > mp_vectort
mp_vectort evaluate(const exprt &)
Evaluate an expression.
void allocate(const mp_integer &address, const mp_integer &size)
reserves memory block of size at address
void read(const mp_integer &address, mp_vectort &dest) const
Reads a memory address and loads it into the dest variable.
mp_integer address_to_offset(const mp_integer &address) const
bool count_type_leaves(const typet &source_type, mp_integer &result)
Count the number of leaf subtypes of ty, a leaf type is a type that is not an array or a struct.
mp_integer get_size(const typet &type)
Retrieves the actual size of the provided structured type.
bool unbounded_size(const typet &)
bool memory_offset_to_byte_offset(const typet &source_type, const mp_integer &cell_offset, mp_integer &result)
Similarly to the above, the interpreter's memory objects contain mp_integers that represent variable-...
void read_unbounded(const mp_integer &address, mp_vectort &dest) const
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irep_idt & id() const
irep_idt get_component_name() const
mstreamt & warning() const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
const typet & base_type() const
The type of the data what we point to.
An expression containing a side effect.
const irep_idt & get_statement() const
const irep_idt get_original_name() const
Structure type, corresponds to C style structs.
const componentst & components() const
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
The type of an expression, extends irept.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
Deprecated expression utility functions.
Interpreter for GOTO Programs.
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
mp_integer logic_right_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
logic right shift (loads 0 on MSB) bitwise operations only make sense on native objects,...
mp_integer arith_left_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
arithmetic left shift bitwise operations only make sense on native objects, hence the largest object ...
mp_integer arith_right_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
arithmetic right shift (loads sign on MSB) bitwise operations only make sense on native objects,...
mp_integer rotate_right(const mp_integer &a, const mp_integer &b, std::size_t true_size)
rotates right (MSB=LSB) bitwise operations only make sense on native objects, hence the largest objec...
mp_integer bitwise_and(const mp_integer &a, const mp_integer &b)
bitwise 'and' of two nonnegative integers
mp_integer bitwise_or(const mp_integer &a, const mp_integer &b)
bitwise 'or' of two nonnegative integers
mp_integer bitwise_xor(const mp_integer &a, const mp_integer &b)
bitwise 'xor' of two nonnegative integers
mp_integer rotate_left(const mp_integer &a, const mp_integer &b, std::size_t true_size)
rotate left (LSB=MSB) bitwise operations only make sense on native objects, hence the largest object ...
API to expression classes for Pointers.
const pointer_offset_exprt & to_pointer_offset_expr(const exprt &expr)
Cast an exprt to a pointer_offset_exprt.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
std::optional< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
std::optional< mp_integer > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
exprt simplify_expr(exprt src, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
bool is_ssa_expr(const exprt &expr)
side_effect_exprt & to_side_effect_expr(exprt &expr)
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
const unary_minus_exprt & to_unary_minus_expr(const exprt &expr)
Cast an exprt to a unary_minus_exprt.
const div_exprt & to_div_expr(const exprt &expr)
Cast an exprt to a div_exprt.
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
string_containert & get_string_container()
Get a reference to the global string container.