72 const goto_functionst::function_mapt::const_iterator
76 throw "main not found";
80 if(!goto_function.body_available())
81 throw "main has no body";
83 pc=goto_function.body.instructions.begin();
119 <<
" ----------------------------------------------------\n";
121 if(
pc==
function->second.body.instructions.end())
123 output.
status() <<
"End of function '" <<
function->first <<
"'\n";
126 function->second.body.output_instruction(
149 <<
"h: display this menu\n"
150 <<
"j: output json trace\n"
151 <<
"m: output memory dump\n"
152 <<
"o: output goto trace\n"
154 <<
"r: run up to entry point\n"
155 <<
"s#: step a number of instructions\n"
156 <<
"sa: step across a function\n"
157 <<
"so: step out of a function\n"
158 <<
"se: step until end of program\n"
164 convert<json_arrayt>(
ns,
steps, json_steps);
205 else if((ch==
's') || (ch==0))
241 if(
pc==
function->second.body.instructions.end())
301 throw "RETURN without call";
303 if(
call_stack.top().return_value_address != 0)
310 next_pc=
function->second.body.instructions.end();
325 throw "START_THREAD not yet implemented";
328 throw "END_THREAD not yet implemented";
333 throw "ATOMIC_BEGIN not yet implemented";
337 throw "ATOMIC_END not yet implemented";
346 if(
pc==
function->second.body.instructions.end())
368 throw "encountered instruction with undefined instruction type";
378 if(
pc->targets.empty())
379 throw "taken goto without target";
381 if(
pc->targets.size()>=2)
382 throw "non-deterministic goto encountered";
391 const irep_idt &statement =
pc->get_other().get_statement();
392 if(statement==ID_expression)
395 pc->code.operands().size()==1,
396 "expression statement expected to have one operand");
400 else if(statement==ID_array_set)
406 while(rhs.size()<size) rhs.insert(rhs.end(), tmp.begin(), tmp.end());
408 output.
error() <<
"!! failed to obtain rhs (" << rhs.size() <<
" vs. "
421 throw "unexpected OTHER statement: "+
id2string(statement);
434 if(real_type.
id()!=ID_struct)
435 throw "request for member of non-struct";
442 for(
const auto &c : components)
450 throw "access out of struct bounds";
470 if(real_type.
id()==ID_struct)
477 result.reserve_operands(components.size());
481 for(
const auto &c : components)
486 result.copy_to_operands(operand);
489 return std::move(result);
491 else if(real_type.
id()==ID_array)
495 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
498 if(size_expr.id()!=ID_constant)
508 result.reserve_operands(numeric_cast_v<std::size_t>(count));
513 offset+i*subtype_size);
514 result.copy_to_operands(operand);
516 return std::move(result);
519 use_non_det &&
memory[numeric_cast_v<std::size_t>(offset)].initialized !=
525 rhs.push_back(
memory[numeric_cast_v<std::size_t>(offset)].value);
539 if(real_type.
id()==ID_struct)
546 result.reserve_operands(components.size());
554 result.copy_to_operands(operand);
556 return std::move(result);
558 else if(real_type.
id()==ID_array)
561 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
577 result.reserve_operands(numeric_cast_v<std::size_t>(count));
581 offset+i*subtype_size);
582 result.copy_to_operands(operand);
584 return std::move(result);
586 else if(real_type.
id()==ID_floatbv)
589 f.
unpack(rhs[numeric_cast_v<std::size_t>(offset)]);
592 else if(real_type.
id()==ID_fixedbv)
595 f.
from_integer(rhs[numeric_cast_v<std::size_t>(offset)]);
598 else if(real_type.
id()==ID_bool)
600 if(rhs[numeric_cast_v<std::size_t>(offset)] != 0)
605 else if(real_type.
id()==ID_c_bool)
608 rhs[numeric_cast_v<std::size_t>(offset)] != 0 ? 1 : 0, type);
610 else if(real_type.
id() == ID_pointer)
612 if(rhs[numeric_cast_v<std::size_t>(offset)] == 0)
615 if(rhs[numeric_cast_v<std::size_t>(offset)] <
memory.
size())
618 mp_integer address = rhs[numeric_cast_v<std::size_t>(offset)];
622 if(offset_from_address == 0)
626 symbol_expr.
type().
id() == ID_struct ||
627 symbol_expr.
type().
id() == ID_struct_tag)
639 << rhs[numeric_cast_v<std::size_t>(offset)]
642 throw "interpreter: reading from invalid pointer";
644 else if(real_type.
id()==ID_string)
649 numeric_cast_v<std::size_t>(rhs[numeric_cast_v<std::size_t>(offset)])),
654 return from_integer(rhs[numeric_cast_v<std::size_t>(offset)], type);
672 output.
error() <<
"!! failed to obtain rhs (" << rhs.size() <<
" vs. "
683 else if(code_assign.
rhs().
id()==ID_side_effect)
696 memory[numeric_cast_v<std::size_t>(address + i)].initialized =
719 <<
"]:=" << rhs[numeric_cast_v<std::size_t>(i)] <<
"\n"
722 cell.
value = rhs[numeric_cast_v<std::size_t>(i)];
732 throw "assumption failed";
740 output.
error() <<
"assertion failed at " <<
pc->location_number <<
"\n"
753 throw "function call to NULL";
755 throw "out-of-range function call";
766 const goto_functionst::function_mapt::const_iterator f_it=
770 throw "failed to find function "+
id2string(identifier);
776 return_value_address=
779 return_value_address=0;
782 std::vector<mp_vectort> argument_values;
784 argument_values.resize(function_call.
arguments().size());
786 for(std::size_t i=0; i<function_call.
arguments().size(); i++)
791 if(f_it->second.body_available())
802 std::set<irep_idt> locals;
805 for(
const auto &
id : locals)
812 const auto ¶meter_identifiers = f_it->second.parameter_identifiers;
813 if(argument_values.size() < parameter_identifiers.size())
814 throw "not enough arguments";
816 for(std::size_t i = 0; i < parameter_identifiers.size(); i++)
819 ns.
lookup(parameter_identifiers[i]).symbol_expr();
825 next_pc=f_it->second.body.instructions.begin();
836 PRECONDITION(!it->second.front().return_assignments.empty());
837 evaluate(it->second.front().return_assignments.back().value, value);
838 if(return_value_address>0)
840 assign(return_value_address, value);
842 it->second.pop_front();
874 if(symbol.
type.
id()==ID_code)
886 memory.
resize(numeric_cast_v<std::size_t>(address + size));
895 if(type.
id()==ID_array)
897 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
900 if(computed_size.size()==1 &&
903 output.
result() <<
"Concretized array with size " << computed_size[0]
932 if(size<=current_size)
943 memory.
resize(numeric_cast_v<std::size_t>(address + size));
947 std::pair<const irep_idt, typet>(symbol_expr.
get_identifier(), alloc_type));
954 if(type.
id()==ID_array)
957 if(size.
id()==ID_infinity)
961 else if(type.
id()==ID_struct)
964 if(st.components().empty())
980 if(type.
id()==ID_struct)
987 for(
const auto &comp : components)
989 const typet &sub_type=comp.type();
991 if(sub_type.
id()!=ID_code)
997 else if(type.
id()==ID_union)
1004 for(
const auto &comp : components)
1006 const typet &sub_type=comp.type();
1008 if(sub_type.
id()!=ID_code)
1009 max_size=std::max(max_size,
get_size(sub_type));
1014 else if(type.
id()==ID_array)
1016 const exprt &size_expr=
static_cast<const exprt &
>(type.
find(ID_size));
1027 const mp_integer size_mp = numeric_cast_v<mp_integer>(size_const);
1028 return subtype_size*size_mp;
1030 return subtype_size;
1032 else if(type.
id() == ID_struct_tag)
1062 for(
const auto &cell_address :
memory)
Operator to return the address of an object.
Array constructor from list of elements.
const exprt & size() const
A codet representing an assignment in the program.
codet representation of a function call statement.
A constant literal expression.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
typet & type()
Return the type of the expression.
The Boolean constant false.
void from_integer(const mp_integer &i)
constant_exprt to_expr() const
function_mapt function_map
::goto_functiont goto_functiont
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
Step of the trace of a GOTO program.
goto_programt::const_targett pc
goto_trace_stept & get_last_step()
Retrieves the final step in the trace for manipulation (used to fill a trace from code,...
void add_step(const goto_trace_stept &step)
Add a step at the end of the trace.
void output(const class namespacet &ns, std::ostream &out) const
Outputs the trace in ASCII to a given stream.
void unpack(const mp_integer &i)
constant_exprt to_expr() const
Unbounded, signed integers (mathematical integers, not bitvectors)
mp_integer old_stack_pointer
mp_integer return_value_address
goto_programt::const_targett return_pc
goto_functionst::function_mapt::const_iterator return_function
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
void execute_function_call()
mp_integer base_address_to_actual_size(const mp_integer &address) const
void print_memory(bool input_flags)
Prints the current state of the memory map Since messaget mdofifies class members,...
mp_integer evaluate_address(const exprt &expr, bool fail_quietly=false)
virtual void command()
reads a user command and executes it.
goto_functionst::function_mapt::const_iterator function
inverse_memory_mapt inverse_memory_map
symbol_exprt address_to_symbol(const mp_integer &address) const
void execute_goto()
executes a goto instruction
void build_memory_map()
Creates a memory map of all static symbols in the program.
std::vector< mp_integer > mp_vectort
void execute_assign()
executes the assign statement at the current pc value
list_input_varst function_input_vars
void assign(const mp_integer &address, const mp_vectort &rhs)
sets the memory at address with the given rhs value (up to sizeof(rhs))
std::stack< stack_framet > call_stackt
typet concretize_type(const typet &type)
turns a variable length array type into a fixed array type
mp_integer address_to_offset(const mp_integer &address) const
void step()
executes a single step and updates the program counter
struct_typet::componentt get_component(const typet &object_type, const mp_integer &offset)
Retrieves the member at offset of an object of type object_type.
mp_integer base_address_to_alloc_size(const mp_integer &address) const
goto_programt::const_targett next_pc
bool evaluate_boolean(const exprt &expr)
mp_integer get_size(const typet &type)
Retrieves the actual size of the provided structured type.
const symbol_tablet & symbol_table
void show_state()
displays the current position of the pc and corresponding code
void initialize(bool init)
Initializes the memory map of the interpreter and [optionally] runs up to the entry point (thus doing...
void evaluate(const exprt &expr, mp_vectort &dest)
Evaluate an expression.
bool unbounded_size(const typet &)
void execute_other()
executes side effects of 'other' instructions
goto_programt::const_targett pc
dynamic_typest dynamic_types
typet get_type(const irep_idt &id) const
returns the type object corresponding to id
const goto_functionst & goto_functions
const irept & find(const irep_namet &name) const
const irep_idt & id() const
void output(std::ostream &out) const
Extract member of struct or union.
mstreamt & warning() const
mstreamt & status() const
mstreamt & result() const
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.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The null pointer constant.
A side_effect_exprt that returns a non-deterministically chosen value.
An expression containing a side effect.
const irep_idt & get_statement() const
void resize(uint64_t new_size)
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 irep_idt & get_identifier() const
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
The Boolean constant true.
The type of an expression, extends irept.
const typet & subtype() const
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...
void interpreter(const goto_modelt &goto_model, message_handlert &message_handler)
Interpreter for GOTO Programs.
Interpreter for GOTO Programs.
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
Replace function returns by assignments to global variables.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
void stack_depth(goto_programt &goto_program, const symbol_exprt &symbol, const std::size_t i_depth, const exprt &max_depth)
side_effect_exprt & to_side_effect_expr(exprt &expr)
bool can_cast_expr< code_outputt >(const exprt &base)
const code_assignt & to_code_assign(const codet &code)
API to expression classes.
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 floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
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 pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
std::size_t unsafe_string2size_t(const std::string &str, int base)
string_containert & get_string_container()
Get a reference to the global string container.