35 for(std::size_t i=0; i<dest.size(); ++i)
42 memory[numeric_cast_v<std::size_t>(address + i)];
59 std::size_t address_val = numeric_cast_v<std::size_t>(address);
64 for(
size_t i=0; i<to_read; i++)
71 memory[numeric_cast_v<std::size_t>(address + i)];
79 dest.push_back(value);
105 if(cell.second.initialized==
119 if(ty.
id()==ID_struct)
127 result+=subtype_count;
131 else if(ty.
id()==ID_array)
135 evaluate(at.size(), array_size_vec);
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)
203 evaluate(at.size(), array_size_vec);
205 if(array_size_vec.size()!=1)
210 if(!elem_size_bytes.has_value() || *elem_size_bytes == 0)
217 mp_integer this_idx = offset / (*elem_size_bytes);
218 if(this_idx>=array_size_vec[0])
223 at.subtype(), offset % (*elem_size_bytes), subtype_result);
225 result=subtype_result+(elem_size_leaves*this_idx);
243 const typet &source_type,
247 if(source_type.
id()==ID_struct)
252 for(
const auto &comp : st.components())
257 if(component_count>cell_offset)
261 comp.type(), cell_offset, subtype_result);
262 const auto member_offset_result =
265 result = member_offset_result.value() + subtype_result;
270 cell_offset-=component_count;
276 else if(source_type.
id()==ID_array)
281 evaluate(at.size(), array_size_vec);
282 if(array_size_vec.size()!=1)
286 if(!elem_size.has_value())
293 mp_integer this_idx=full_cell_offset/elem_count;
294 if(this_idx>=array_size_vec[0])
301 full_cell_offset%elem_count,
303 result = subtype_result + ((*elem_size) * this_idx);
310 return full_cell_offset!=0;
321 if(expr.
id()==ID_constant)
323 if(expr.
type().
id()==ID_struct)
325 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
330 if(it->type().id()==ID_code)
340 if(tmp.size()==sub_size)
342 for(std::size_t i=0; i<tmp.size(); ++i)
343 dest.push_back(tmp[i]);
354 else if(expr.
type().
id() == ID_pointer)
359 if(
object.
id() == ID_address_of)
364 else if(
const auto i = numeric_cast<mp_integer>(
object))
373 const auto i = numeric_cast<mp_integer>(expr);
374 if(i && i->is_zero())
381 else if(expr.
type().
id()==ID_floatbv)
385 dest.push_back(f.
pack());
388 else if(expr.
type().
id()==ID_fixedbv)
395 else if(expr.
type().
id()==ID_c_bool)
402 else if(expr.
type().
id()==ID_bool)
404 dest.push_back(expr.
is_true());
407 else if(expr.
type().
id()==ID_string)
418 if(
const auto i = numeric_cast<mp_integer>(expr))
425 else if(expr.
id()==ID_struct)
428 dest.reserve(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
434 if(it->type().id()==ID_code)
446 for(std::size_t i=0; i<tmp.size(); i++)
447 dest.push_back(tmp[i]);
458 else if(expr.
id()==ID_side_effect)
470 output.
error() <<
"heap memory allocation not fully implemented "
472 std::stringstream buffer;
480 dest.push_back(address);
487 else if(expr.
id()==ID_bitor)
490 throw id2string(expr.
id())+
" expects at least two operands";
500 dest.push_back(
final);
503 else if(expr.
id()==ID_bitand)
506 throw id2string(expr.
id())+
" expects at least two operands";
516 dest.push_back(
final);
519 else if(expr.
id()==ID_bitxor)
522 throw id2string(expr.
id())+
" expects at least two operands";
532 dest.push_back(
final);
535 else if(expr.
id()==ID_bitnot)
548 else if(expr.
id()==ID_shl)
553 if(tmp0.size()==1 && tmp1.size()==1)
559 dest.push_back(
final);
563 else if(expr.
id() == ID_shr || expr.
id() == ID_lshr)
568 if(tmp0.size()==1 && tmp1.size()==1)
574 dest.push_back(
final);
578 else if(expr.
id()==ID_ashr)
583 if(tmp0.size()==1 && tmp1.size()==1)
589 dest.push_back(
final);
593 else if(expr.
id()==ID_ror)
598 if(tmp0.size()==1 && tmp1.size()==1)
604 dest.push_back(
final);
608 else if(expr.
id()==ID_rol)
613 if(tmp0.size()==1 && tmp1.size()==1)
619 dest.push_back(
final);
623 else if(expr.
id()==ID_equal ||
624 expr.
id()==ID_notequal ||
634 if(tmp0.size()==1 && tmp1.size()==1)
639 if(expr.
id()==ID_equal)
640 dest.push_back(op0==op1);
641 else if(expr.
id()==ID_notequal)
642 dest.push_back(op0!=op1);
643 else if(expr.
id()==ID_le)
644 dest.push_back(op0<=op1);
645 else if(expr.
id()==ID_ge)
646 dest.push_back(op0>=op1);
647 else if(expr.
id()==ID_lt)
648 dest.push_back(op0<op1);
649 else if(expr.
id()==ID_gt)
650 dest.push_back(op0>op1);
655 else if(expr.
id()==ID_or)
658 throw id2string(expr.
id())+
" expects at least one operand";
667 if(tmp.size()==1 && tmp.front()!=0)
674 dest.push_back(result);
678 else if(expr.
id()==ID_if)
688 evaluate(if_expr.true_case(), tmp1);
690 evaluate(if_expr.false_case(), tmp1);
694 dest.push_back(tmp1.front());
698 else if(expr.
id()==ID_and)
701 throw id2string(expr.
id())+
" expects at least one operand";
710 if(tmp.size()==1 && tmp.front()==0)
717 dest.push_back(result);
721 else if(expr.
id()==ID_not)
727 dest.push_back(tmp.front()==0);
731 else if(expr.
id()==ID_plus)
743 dest.push_back(result);
746 else if(expr.
id()==ID_mult)
751 if(expr.
type().
id()==ID_fixedbv)
758 else if(expr.
type().
id()==ID_floatbv)
773 if(expr.
type().
id()==ID_fixedbv)
783 else if(expr.
type().
id()==ID_floatbv)
797 dest.push_back(result);
800 else if(expr.
id()==ID_minus)
806 if(tmp0.size()==1 && tmp1.size()==1)
807 dest.push_back(tmp0.front()-tmp1.front());
810 else if(expr.
id()==ID_div)
816 if(tmp0.size()==1 && tmp1.size()==1)
817 dest.push_back(tmp0.front()/tmp1.front());
820 else if(expr.
id()==ID_unary_minus)
826 dest.push_back(-tmp0.front());
829 else if(expr.
id()==ID_address_of)
834 else if(expr.
id()==ID_pointer_offset)
837 throw "pointer_offset expects one operand";
840 throw "pointer_offset expects a pointer operand";
857 dest.push_back(byte_offset);
863 expr.
id() == ID_dereference || expr.
id() == ID_index ||
864 expr.
id() == ID_symbol || expr.
id() == ID_member ||
865 expr.
id() == ID_byte_extract_little_endian ||
866 expr.
id() == ID_byte_extract_big_endian)
872 if(address.is_zero())
877 if(expr.
id() == ID_index)
884 evaluated_index.
index() =
897 if(simplified.
id() == expr.
id())
905 else if(!address.is_zero())
908 expr.
id() == ID_byte_extract_little_endian ||
909 expr.
id() == ID_byte_extract_big_endian)
914 evaluate(byte_extract_expr.op(), extract_from);
916 !extract_from.empty(),
917 "evaluate_address should have returned address == 0");
924 target_type_leaves > 0)
928 extract_from.begin() + numeric_cast_v<std::size_t>(memory_offset),
929 extract_from.begin() +
930 numeric_cast_v<std::size_t>(memory_offset + target_type_leaves));
937 dest.resize(numeric_cast_v<std::size_t>(
get_size(expr.
type())));
948 else if(expr.
id()==ID_typecast)
957 if(expr.
type().
id()==ID_pointer)
959 dest.push_back(value);
962 else if(expr.
type().
id()==ID_signedbv)
969 else if(expr.
type().
id()==ID_unsignedbv)
976 else if((expr.
type().
id()==ID_bool) || (expr.
type().
id()==ID_c_bool))
978 dest.push_back(value!=0);
983 else if(expr.
id()==ID_array)
991 else if(expr.
id()==ID_array_of)
994 std::vector<mp_integer> size;
995 if(ty.size().id()==ID_infinity)
1002 std::size_t size_int = numeric_cast_v<std::size_t>(size[0]);
1003 for(std::size_t i=0; i<size_int; ++i)
1008 else if(expr.
id()==ID_with)
1012 std::vector<mp_integer> where;
1013 std::vector<mp_integer> new_value;
1015 evaluate(wexpr.new_value(), new_value);
1017 if(!new_value.empty() && where.size()==1 && !
unbounded_size(subtype))
1025 mp_integer need_size=(where_idx+1)*subtype_size;
1027 if(dest.size()<need_size)
1028 dest.resize(numeric_cast_v<std::size_t>(need_size), 0);
1030 for(std::size_t i=0; i<new_value.size(); ++i)
1031 dest[numeric_cast_v<std::size_t>((where_idx * subtype_size) + i)] =
1037 else if(expr.
id()==ID_nil)
1042 else if(expr.
id()==ID_infinity)
1044 if(expr.
type().
id()==ID_signedbv)
1050 output.
error() <<
"!! failed to evaluate expression: "
1052 << expr.
id() <<
"[" << expr.
type().
id() <<
"]"
1060 if(expr.
id()==ID_symbol)
1066 interpretert::memory_mapt::const_iterator m_it1=
1070 return m_it1->second;
1074 interpretert::memory_mapt::const_iterator m_it2=
1078 return m_it2->second;
1084 else if(expr.
id()==ID_dereference)
1090 return tmp0.front();
1092 else if(expr.
id()==ID_index)
1101 return base+tmp1.front();
1104 else if(expr.
id()==ID_member)
1114 for(
const auto &comp : struct_type.
components())
1116 if(comp.get_name()==component_name)
1126 else if(expr.
id()==ID_byte_extract_little_endian ||
1127 expr.
id()==ID_byte_extract_big_endian)
1131 evaluate(byte_extract_expr.op1(), extract_offset);
1133 evaluate(byte_extract_expr.op0(), extract_from);
1134 if(extract_offset.size()==1 && !extract_from.empty())
1138 byte_extract_expr.op0().type(), extract_offset[0], memory_offset))
1143 else if(expr.
id()==ID_if)
1152 if(result.size()==1)
1155 else if(expr.
id()==ID_typecast)
1162 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.
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.
typet & type()
Return the type of the expression.
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
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.
void evaluate(const exprt &expr, mp_vectort &dest)
Evaluate an expression.
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 typet & follow(const typet &) const
Resolve type symbol to the type it points 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 typet & subtype() const
#define forall_operands(it, expr)
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 dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
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.
optionalt< mp_integer > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
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.
string_containert & get_string_container()
Get a reference to the global string container.