30 for(std::size_t i=0; i<dest.size(); ++i)
53 std::size_t address_val = numeric_cast_v<std::size_t>(address);
58 for(
size_t i=0; i<to_read; i++)
65 memory[numeric_cast_v<std::size_t>(address + i)];
73 dest.push_back(value);
99 if(cell.second.initialized==
113 if(ty.
id()==ID_struct)
125 else if(ty.
id()==ID_array)
129 evaluate(at.size(), array_size_vec);
130 if(array_size_vec.size()!=1)
135 result=array_size_vec[0]*subtype_count;
155 const typet &source_type,
159 if(source_type.
id()==ID_struct)
164 for(
const auto &comp : st.components())
170 if(!comp_offset.has_value() && !component_byte_size.has_value())
173 if(*comp_offset + *component_byte_size > offset)
177 comp.type(), offset - *comp_offset, subtype_result);
178 result=previous_member_offsets+subtype_result;
186 previous_member_offsets+=component_count;
192 else if(source_type.
id()==ID_array)
197 evaluate(at.size(), array_size_vec);
199 if(array_size_vec.size()!=1)
204 if(!elem_size_bytes.has_value() || *elem_size_bytes == 0)
211 mp_integer this_idx = offset / (*elem_size_bytes);
212 if(this_idx>=array_size_vec[0])
217 at.subtype(), offset % (*elem_size_bytes), subtype_result);
219 result=subtype_result+(elem_size_leaves*this_idx);
237 const typet &source_type,
241 if(source_type.
id()==ID_struct)
246 for(
const auto &comp : st.components())
251 if(component_count>cell_offset)
255 comp.type(), cell_offset, subtype_result);
256 const auto member_offset_result =
259 result = member_offset_result.value() + subtype_result;
264 cell_offset-=component_count;
270 else if(source_type.
id()==ID_array)
275 evaluate(at.size(), array_size_vec);
276 if(array_size_vec.size()!=1)
280 if(!elem_size.has_value())
287 mp_integer this_idx=full_cell_offset/elem_count;
288 if(this_idx>=array_size_vec[0])
295 full_cell_offset%elem_count,
297 result = subtype_result + ((*elem_size) * this_idx);
304 return full_cell_offset!=0;
315 if(expr.
id()==ID_constant)
317 if(expr.
type().
id()==ID_struct)
319 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
324 if(it->type().id()==ID_code)
334 if(tmp.size()==sub_size)
336 for(std::size_t i=0; i<tmp.size(); ++i)
337 dest.push_back(tmp[i]);
348 else if(expr.
type().
id() == ID_pointer)
353 if(
object.
id() == ID_address_of)
358 else if(
const auto i = numeric_cast<mp_integer>(
object))
368 if(i && i->is_zero())
375 else if(expr.
type().
id()==ID_floatbv)
379 dest.push_back(f.
pack());
382 else if(expr.
type().
id()==ID_fixedbv)
389 else if(expr.
type().
id()==ID_c_bool)
396 else if(expr.
type().
id()==ID_bool)
398 dest.push_back(expr.
is_true());
401 else if(expr.
type().
id()==ID_string)
405 warning() <<
"string decoding not fully implemented " 406 << value.size() + 1 <<
eom;
412 if(
const auto i = numeric_cast<mp_integer>(expr))
419 else if(expr.
id()==ID_struct)
422 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
428 if(it->type().id()==ID_code)
440 for(std::size_t i=0; i<tmp.size(); i++)
441 dest.push_back(tmp[i]);
452 else if(expr.
id()==ID_side_effect)
458 error() <<
"nondet not implemented" <<
eom;
464 error() <<
"heap memory allocation not fully implemented " 467 std::stringstream buffer;
474 dest.push_back(address);
478 error() <<
"side effect not implemented " 482 else if(expr.
id()==ID_bitor)
485 throw id2string(expr.
id())+
" expects at least two operands";
495 dest.push_back(
final);
498 else if(expr.
id()==ID_bitand)
501 throw id2string(expr.
id())+
" expects at least two operands";
511 dest.push_back(
final);
514 else if(expr.
id()==ID_bitxor)
517 throw id2string(expr.
id())+
" expects at least two operands";
527 dest.push_back(
final);
530 else if(expr.
id()==ID_bitnot)
544 else if(expr.
id()==ID_shl)
547 throw id2string(expr.
id())+
" expects two operands";
552 if(tmp0.size()==1 && tmp1.size()==1)
558 dest.push_back(
final);
562 else if((expr.
id()==ID_shr) || (expr.
id()==ID_lshr))
565 throw id2string(expr.
id())+
" expects two operands";
570 if(tmp0.size()==1 && tmp1.size()==1)
576 dest.push_back(
final);
580 else if(expr.
id()==ID_ashr)
583 throw id2string(expr.
id())+
" expects two operands";
588 if(tmp0.size()==1 && tmp1.size()==1)
594 dest.push_back(
final);
598 else if(expr.
id()==ID_ror)
601 throw id2string(expr.
id())+
" expects two operands";
606 if(tmp0.size()==1 && tmp1.size()==1)
611 dest.push_back(
final);
615 else if(expr.
id()==ID_rol)
618 throw id2string(expr.
id())+
" expects two operands";
623 if(tmp0.size()==1 && tmp1.size()==1)
628 dest.push_back(
final);
632 else if(expr.
id()==ID_equal ||
633 expr.
id()==ID_notequal ||
640 throw id2string(expr.
id())+
" expects two operands";
646 if(tmp0.size()==1 && tmp1.size()==1)
651 if(expr.
id()==ID_equal)
652 dest.push_back(op0==op1);
653 else if(expr.
id()==ID_notequal)
654 dest.push_back(op0!=op1);
655 else if(expr.
id()==ID_le)
656 dest.push_back(op0<=op1);
657 else if(expr.
id()==ID_ge)
658 dest.push_back(op0>=op1);
659 else if(expr.
id()==ID_lt)
660 dest.push_back(op0<op1);
661 else if(expr.
id()==ID_gt)
662 dest.push_back(op0>op1);
667 else if(expr.
id()==ID_or)
670 throw id2string(expr.
id())+
" expects at least one operand";
679 if(tmp.size()==1 && tmp.front()!=0)
690 else if(expr.
id()==ID_if)
693 throw "if expects three operands";
707 dest.push_back(tmp1.front());
711 else if(expr.
id()==ID_and)
714 throw id2string(expr.
id())+
" expects at least one operand";
723 if(tmp.size()==1 && tmp.front()==0)
734 else if(expr.
id()==ID_not)
743 dest.push_back(tmp.front()==0);
747 else if(expr.
id()==ID_plus)
762 else if(expr.
id()==ID_mult)
767 if(expr.
type().
id()==ID_fixedbv)
774 else if(expr.
type().
id()==ID_floatbv)
789 if(expr.
type().
id()==ID_fixedbv)
799 else if(expr.
type().
id()==ID_floatbv)
816 else if(expr.
id()==ID_minus)
819 throw "- expects two operands";
825 if(tmp0.size()==1 && tmp1.size()==1)
826 dest.push_back(tmp0.front()-tmp1.front());
829 else if(expr.
id()==ID_div)
832 throw "/ expects two operands";
838 if(tmp0.size()==1 && tmp1.size()==1)
839 dest.push_back(tmp0.front()/tmp1.front());
842 else if(expr.
id()==ID_unary_minus)
845 throw "unary- expects one operand";
851 dest.push_back(-tmp0.front());
854 else if(expr.
id()==ID_address_of)
857 throw "address_of expects one operand";
862 else if(expr.
id()==ID_pointer_offset)
865 throw "pointer_offset expects one operand";
867 throw "pointer_offset expects a pointer operand";
882 dest.push_back(byte_offset);
887 else if(expr.
id()==ID_byte_extract_little_endian ||
888 expr.
id()==ID_byte_extract_big_endian)
891 throw "byte_extract should have two operands";
896 if(extract_offset.size()==1 && extract_from.size()!=0)
909 target_type_leaves>0)
911 dest.insert(dest.end(),
912 extract_from.begin()+memory_offset.to_long(),
913 extract_from.begin()+(memory_offset+target_type_leaves).to_long());
919 else if(expr.
id()==ID_dereference ||
920 expr.
id()==ID_index ||
921 expr.
id()==ID_symbol ||
922 expr.
id()==ID_member)
927 if(address.is_zero())
932 if(expr.
id() == ID_index)
934 exprt evaluated_index = expr;
951 if(simplified.
id() == expr.
id())
959 else if(!address.is_zero())
963 dest.resize(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
973 else if(expr.
id()==ID_typecast)
976 throw "typecast expects one operand";
985 if(expr.
type().
id()==ID_pointer)
987 dest.push_back(value);
990 else if(expr.
type().
id()==ID_signedbv)
997 else if(expr.
type().
id()==ID_unsignedbv)
1004 else if((expr.
type().
id()==ID_bool) || (expr.
type().
id()==ID_c_bool))
1006 dest.push_back(value!=0);
1011 else if(expr.
id()==ID_array)
1019 else if(expr.
id()==ID_array_of)
1022 std::vector<mp_integer> size;
1023 if(ty.size().id()==ID_infinity)
1030 std::size_t size_int = numeric_cast_v<std::size_t>(size[0]);
1031 for(std::size_t i=0; i<size_int; ++i)
1036 else if(expr.
id()==ID_with)
1040 std::vector<mp_integer> where;
1041 std::vector<mp_integer> new_value;
1043 evaluate(wexpr.new_value(), new_value);
1045 if(!new_value.empty() && where.size()==1 && !
unbounded_size(subtype))
1053 mp_integer need_size=(where_idx+1)*subtype_size;
1055 if(dest.size()<need_size)
1056 dest.resize(numeric_cast_v<std::size_t>(need_size), 0);
1058 for(std::size_t i=0; i<new_value.size(); ++i)
1059 dest[numeric_cast_v<std::size_t>((where_idx * subtype_size) + i)] =
1065 else if(expr.
id()==ID_nil)
1070 else if(expr.
id()==ID_infinity)
1072 if(expr.
type().
id()==ID_signedbv)
1074 warning() <<
"Infinite size arrays not supported" <<
eom;
1078 error() <<
"!! failed to evaluate expression: " 1080 << expr.
id() <<
"[" << expr.
type().
id() <<
"]" 1088 if(expr.
id()==ID_symbol)
1094 interpretert::memory_mapt::const_iterator m_it1=
1098 return m_it1->second;
1102 interpretert::memory_mapt::const_iterator m_it2=
1106 return m_it2->second;
1112 else if(expr.
id()==ID_dereference)
1115 throw "dereference expects one operand";
1121 return tmp0.front();
1123 else if(expr.
id()==ID_index)
1126 throw "index expects two operands";
1135 return base+tmp1.front();
1138 else if(expr.
id()==ID_member)
1141 throw "member expects one operand";
1151 for(
const auto &comp : struct_type.
components())
1153 if(comp.get_name()==component_name)
1163 else if(expr.
id()==ID_byte_extract_little_endian ||
1164 expr.
id()==ID_byte_extract_big_endian)
1167 throw "byte_extract should have two operands";
1172 if(extract_offset.size()==1 && !extract_from.empty())
1176 extract_offset[0], memory_offset))
1180 else if(expr.
id()==ID_if)
1191 else if(expr.
id()==ID_typecast)
1194 throw "typecast expects one operand";
1200 error() <<
"!! failed to evaluate address: " 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', this yields the offset into that vector at which to find a value at byte address 'offset'.
The type of an expression, extends irept.
typet get_type(const irep_idt &id) const
returns the type object corresponding to id
const std::string & id2string(const irep_idt &d)
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 ...
irep_idt address_to_identifier(const mp_integer &address) const
void set_value(const mp_integer &_v)
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
exprt simplify_expr(const exprt &src, const namespacet &ns)
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
string_containert & get_string_container()
Get a reference to the global string container.
mp_integer::ullong_t integer2ulong(const mp_integer &n)
Deprecated expression utility functions.
void from_expr(const constant_exprt &expr)
std::vector< mp_integer > mp_vectort
mp_integer bitwise_xor(const mp_integer &a, const mp_integer &b)
bitwise 'xor' of two nonnegative integers
const irep_idt & get_identifier() const
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
const irep_idt & get_value() const
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 from_expr(const constant_exprt &expr)
const componentst & components() const
The trinary if-then-else operator.
bool is_true() const
Return whether the expression is a constant representing true.
typet & type()
Return the type of the expression.
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 ...
#define CHECK_RETURN(CONDITION)
Structure type, corresponds to C style structs.
const c_bool_typet & to_c_bool_type(const typet &type)
Cast a typet to a c_bool_typet.
side_effect_exprt & to_side_effect_expr(exprt &expr)
const mp_integer & get_value() const
mstreamt & warning() const
const irep_idt & id() const
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
Interpreter for GOTO Programs.
void unpack(const mp_integer &i)
goto_functionst::function_mapt::const_iterator function
optionalt< 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 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
void read(const mp_integer &address, mp_vectort &dest) const
Reads a memory address and loads it into the dest variable.
void read_unbounded(const mp_integer &address, mp_vectort &dest) const
void from_integer(const mp_integer &i)
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, hence the largest object size should be the largest available c++ integer size (currently long long)
mp_integer bitwise_and(const mp_integer &a, const mp_integer &b)
bitwise 'and' of two nonnegative integers
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 address_to_offset(const mp_integer &address) const
mp_integer get_size(const typet &type)
Retrieves the actual size of the provided structured type.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const irep_idt get_original_name() const
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 evaluate_address(const exprt &expr, bool fail_quietly=false)
mp_integer base_address_to_actual_size(const mp_integer &address) const
#define forall_operands(it, expr)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
void allocate(const mp_integer &address, const mp_integer &size)
reserves memory block of size at address
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
mp_integer bitwise_or(const mp_integer &a, const mp_integer &b)
bitwise 'or' of two nonnegative integers
Operator to return the address of an object.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
bool unbounded_size(const typet &)
void evaluate(const exprt &expr, mp_vectort &dest)
Evaluate an expression.
bool has_operands() const
Return true if there is at least one operand.
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
void clear_input_flags()
Clears memoy r/w flag initialization.
mstreamt & result() const
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Base class for all expressions.
void build_memory_map()
Creates a memory map of all static symbols in the program.
irep_idt get_component_name() const
bool is_ssa_expr(const exprt &expr)
void from_integer(const mp_integer &i)
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...
const typet & subtype() const
An expression containing a side effect.
const irep_idt & get_statement() const