Go to the documentation of this file.
68 const goto_functionst::function_mapt::const_iterator
72 throw "main not found";
76 if(!goto_function.body_available())
77 throw "main has no body";
79 pc=goto_function.body.instructions.begin();
110 <<
" ----------------------------------------------------\n";
112 if(
pc==
function->second.body.instructions.end())
114 status() <<
"End of function `" <<
function->first <<
"'\n";
117 function->second.body.output_instruction(
143 <<
"Interpreter help\n"
144 <<
"h: display this menu\n"
145 <<
"j: output json trace\n"
146 <<
"m: output memory dump\n"
147 <<
"o: output goto trace\n"
149 <<
"r: run until completion\n"
150 <<
"s#: step a number of instructions\n"
151 <<
"sa: step across a function\n"
152 <<
"so: step out of a function\n"
158 convert<json_arrayt>(
ns,
steps, json_steps);
199 else if((ch==
's') || (ch==0))
235 if(
pc==
function->second.body.instructions.end())
295 throw "RETURN without call";
297 if(
pc->code.operands().size()==1 &&
305 next_pc=
function->second.body.instructions.end();
320 throw "START_THREAD not yet implemented";
323 throw "END_THREAD not yet implemented";
328 throw "ATOMIC_BEGIN not yet implemented";
332 throw "ATOMIC_END not yet implemented";
341 if(
pc==
function->second.body.instructions.end())
362 throw "encountered instruction with undefined instruction type";
372 if(
pc->targets.empty())
373 throw "taken goto without target";
375 if(
pc->targets.size()>=2)
376 throw "non-deterministic goto encountered";
385 const irep_idt &statement=
pc->code.get_statement();
386 if(statement==ID_expression)
389 pc->code.operands().size()==1,
390 "expression statement expected to have one operand");
394 else if(statement==ID_array_set)
400 while(rhs.size()<size) rhs.insert(rhs.end(), tmp.begin(), tmp.end());
402 error() <<
"!! failed to obtain rhs (" << rhs.size() <<
" vs. "
403 << size <<
")\n" <<
eom;
409 else if(statement==ID_output)
414 throw "unexpected OTHER statement: "+
id2string(statement);
430 if(real_type.
id()!=ID_struct)
431 throw "request for member of non-struct";
438 for(
const auto &c : components)
446 throw "access out of struct bounds";
466 if(real_type.
id()==ID_struct)
473 result.reserve_operands(components.size());
477 for(
const auto &c : components)
482 result.copy_to_operands(operand);
487 else if(real_type.
id()==ID_array)
491 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
494 if(size_expr.
id()!=ID_constant)
500 count = numeric_cast_v<mp_integer>(size_expr);
504 result.reserve_operands(numeric_cast_v<std::size_t>(count));
509 offset+i*subtype_size);
510 result.copy_to_operands(operand);
533 if(real_type.
id()==ID_struct)
540 result.reserve_operands(components.size());
548 result.copy_to_operands(operand);
552 else if(real_type.
id()==ID_array)
555 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
567 count = numeric_cast_v<mp_integer>(size_expr);
571 result.reserve_operands(numeric_cast_v<std::size_t>(count));
575 offset+i*subtype_size);
576 result.copy_to_operands(operand);
580 else if(real_type.
id()==ID_floatbv)
583 f.
unpack(rhs[numeric_cast_v<std::size_t>(offset)]);
586 else if(real_type.
id()==ID_fixedbv)
589 f.
from_integer(rhs[numeric_cast_v<std::size_t>(offset)]);
592 else if(real_type.
id()==ID_bool)
594 if(rhs[numeric_cast_v<std::size_t>(offset)] != 0)
599 else if(real_type.
id()==ID_c_bool)
602 rhs[numeric_cast_v<std::size_t>(offset)] != 0 ? 1 : 0, type);
604 else if(real_type.
id() == ID_pointer)
606 if(rhs[numeric_cast_v<std::size_t>(offset)] == 0)
609 if(rhs[numeric_cast_v<std::size_t>(offset)] <
memory.
size())
612 mp_integer address = rhs[numeric_cast_v<std::size_t>(offset)];
632 return std::move(index_expr);
635 error() <<
"interpreter: invalid pointer "
636 << rhs[numeric_cast_v<std::size_t>(offset)] <<
" > object count "
639 throw "interpreter: reading from invalid pointer";
641 else if(real_type.
id()==ID_string)
646 numeric_cast_v<std::size_t>(rhs[numeric_cast_v<std::size_t>(offset)])),
669 error() <<
"!! failed to obtain rhs ("
670 << rhs.size() <<
" vs. "
681 else if(code_assign.
rhs().
id()==ID_side_effect)
717 <<
"]:=" << rhs[numeric_cast_v<std::size_t>(i)] <<
"\n"
720 cell.
value = rhs[numeric_cast_v<std::size_t>(i)];
730 throw "assumption failed";
738 throw "program assertion reached";
740 error() <<
"assertion failed at " <<
pc->location_number
754 throw "function call to NULL";
756 throw "out-of-range function call";
767 const goto_functionst::function_mapt::const_iterator f_it=
771 throw "failed to find function "+
id2string(identifier);
777 return_value_address=
780 return_value_address=0;
783 std::vector<mp_vectort> argument_values;
785 argument_values.resize(function_call.
arguments().size());
787 for(std::size_t i=0; i<function_call.
arguments().size(); i++)
792 if(f_it->second.body_available())
803 std::set<irep_idt> locals;
806 for(
const auto &
id : locals)
816 if(argument_values.size()<parameters.size())
817 throw "not enough arguments";
819 for(std::size_t i=0; i<parameters.size(); i++)
828 next_pc=f_it->second.body.instructions.begin();
839 PRECONDITION(!it->second.front().return_assignments.empty());
840 evaluate(it->second.front().return_assignments.back().value, value);
841 if(return_value_address>0)
843 assign(return_value_address, value);
845 it->second.pop_front();
876 if(symbol.
type.
id()==ID_code)
897 if(type.
id()==ID_array)
899 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
902 if(computed_size.size()==1 &&
905 result() <<
"Concretized array with size " << computed_size[0]
914 warning() <<
"Failed to concretize variable array" <<
eom;
935 if(size<=current_size)
949 dynamic_types.insert(std::pair<const irep_idt, typet>(
id, alloc_type));
956 if(type.
id()==ID_array)
959 if(size.
id()==ID_infinity)
963 else if(type.
id()==ID_struct)
966 if(st.components().empty())
982 if(type.
id()==ID_struct)
989 for(
const auto &comp : components)
991 const typet &sub_type=comp.type();
993 if(sub_type.
id()!=ID_code)
999 else if(type.
id()==ID_union)
1006 for(
const auto &comp : components)
1008 const typet &sub_type=comp.type();
1010 if(sub_type.
id()!=ID_code)
1011 max_size=std::max(max_size,
get_size(sub_type));
1016 else if(type.
id()==ID_array)
1018 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
1029 const mp_integer size_mp = numeric_cast_v<mp_integer>(size_const);
1030 return subtype_size*size_mp;
1032 return subtype_size;
1034 else if(type.
id() == ID_symbol_type || type.
id() == ID_struct_tag)
1064 for(
const auto &cell_address :
memory)
1070 debug() << identifier <<
"[" << offset <<
"]"
mp_integer base_address_to_actual_size(const mp_integer &address) const
const componentst & components() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
#define PRECONDITION(CONDITION)
void show_state()
displays the current position of the pc and corresponding code
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const typet & subtype() const
void from_integer(const mp_integer &i)
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
void output(std::ostream &out) const
The type of an expression, extends irept.
std::vector< parametert > parameterst
mstreamt & status() const
void execute_goto()
executes a goto instruction
goto_programt::const_targett pc
typet type
Type of symbol.
const symbol_tablet & symbol_table
void assign(const mp_integer &address, const mp_vectort &rhs)
sets the memory at address with the given rhs value (up to sizeof(rhs))
mp_integer::ullong_t integer2ulong(const mp_integer &n)
const irept & find(const irep_namet &name) const
void unpack(const mp_integer &i)
bool evaluate_boolean(const exprt &expr)
Unbounded, signed integers (mathematical integers, not bitvectors)
bool unbounded_size(const typet &)
struct_typet::componentt get_component(const irep_idt &object, const mp_integer &offset)
retrieves the member at offset
Base class for all expressions.
std::vector< componentt > componentst
goto_programt::const_targett next_pc
side_effect_exprt & to_side_effect_expr(exprt &expr)
function_mapt function_map
Expression to hold a symbol (variable)
void interpreter(const goto_modelt &goto_model, message_handlert &message_handler)
constant_exprt to_expr() const
std::size_t safe_string2size_t(const std::string &str, int base)
void print_memory(bool input_flags)
Prints the current state of the memory map Since messaget mdofifies class members,...
dynamic_typest dynamic_types
void build_memory_map()
Creates a memory map of all static symbols in the program.
mp_integer base_address_to_alloc_size(const mp_integer &address) const
Struct constructor from list of elements.
const exprt & size() const
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
codet representation of a function call statement.
goto_functionst::function_mapt::const_iterator function
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
mstreamt & result() const
mp_integer get_size(const typet &type)
Retrieves the actual size of the provided structured type.
void execute_other()
executes side effects of 'other' instructions
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
virtual void command()
reads a user command and executes it.
The null pointer constant.
const std::string & id2string(const irep_idt &d)
void step()
executes a single step and updates the program counter
const irep_idt & get_identifier() const
goto_programt::const_targett pc
mp_integer old_stack_pointer
void execute_function_call()
const goto_functionst & goto_functions
void output(const class namespacet &ns, std::ostream &out) const
outputs the trace in ASCII to a given stream
typet get_type(const irep_idt &id) const
returns the type object corresponding to id
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
void resize(uint64_t new_size)
const irep_idt & id() const
const code_function_callt & to_code_function_call(const codet &code)
std::vector< mp_integer > mp_vectort
The Boolean constant false.
void get_local_identifiers(const goto_functiont &goto_function, std::set< irep_idt > &dest)
Return in dest the identifiers of the local variables declared in the goto_function and the identifie...
const parameterst & parameters() const
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
typet concretize_type(const typet &type)
turns a variable length array type into a fixed array type
const irep_idt & get_statement() const
void execute_assign()
executes the assign statement at the current pc value
A side_effect_exprt that returns a non-deterministically chosen value.
::goto_functiont goto_functiont
void evaluate(const exprt &expr, mp_vectort &dest)
Evaluate an expression.
Extract member of struct or union.
irep_idt address_to_identifier(const mp_integer &address) const
Structure type, corresponds to C style structs.
goto_functionst goto_functions
GOTO functions.
const code_assignt & to_code_assign(const codet &code)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
mp_integer return_value_address
const irep_idt & get_identifier() const
inverse_memory_mapt inverse_memory_map
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
void clear_input_flags()
Clears memoy r/w flag initialization.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
constant_exprt to_expr() const
mp_integer address_to_offset(const mp_integer &address) const
goto_trace_stept & get_last_step()
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
goto_functionst::function_mapt::const_iterator return_function
Operator to return the address of an object.
A codet representing an assignment in the program.
The Boolean constant true.
A constant literal expression.
list_input_varst function_input_vars
mstreamt & warning() const
goto_programt::const_targett target_assert
symbol_tablet symbol_table
Symbol table.
Array constructor from list of elements.
irep_idt name
The unique identifier.
An expression containing a side effect.
void add_step(const goto_trace_stept &step)
goto_programt::const_targett return_pc
mp_integer evaluate_address(const exprt &expr, bool fail_quietly=false)
string_containert & get_string_container()
Get a reference to the global string container.
void initialize(bool init)
Initializes the memory map of the interpreter and [optionally] runs up to the entry point (thus doing...