63 for(
const auto &label :
labels)
77 out <<
"NO INSTRUCTION TYPE SET" <<
'\n';
91 out <<
"(incomplete)";
99 out << (*gt_it)->target_number;
229 out <<
"SKIP" <<
'\n';
233 out <<
"END_FUNCTION" <<
'\n';
237 out <<
"LOCATION" <<
'\n';
247 for(
const auto &ex : exception_list)
248 out <<
" " << ex.id();
251 if(
code().operands().size() == 1)
259 if(
code().get_statement() == ID_exception_landingpad)
262 out <<
"EXCEPTION LANDING PAD (" <<
format(landingpad.catch_expr().type())
263 <<
' ' <<
format(landingpad.catch_expr()) <<
")";
265 else if(
code().get_statement() == ID_push_catch)
267 out <<
"CATCH-PUSH ";
273 targets.size() == exception_list.size(),
274 "unexpected discrepancy between sizes of instruction"
275 "targets and exception list");
276 for(instructiont::targetst::const_iterator gt_it =
targets.begin();
282 out << exception_list[i].id() <<
"->"
283 << (*gt_it)->target_number;
286 else if(
code().get_statement() == ID_pop_catch)
300 out <<
"ATOMIC_BEGIN" <<
'\n';
304 out <<
"ATOMIC_END" <<
'\n';
308 out <<
"START THREAD " <<
get_target()->target_number <<
'\n';
312 out <<
"END THREAD" <<
'\n';
324 if(instruction.is_decl())
327 instruction.code().get_statement() == ID_decl,
328 "expected statement to be declaration statement");
330 instruction.code().operands().size() == 1,
331 "declaration statement expects one operand");
332 decl_identifiers.insert(instruction.decl_symbol().get_identifier());
339 if(src.
id()==ID_dereference)
343 else if(src.
id()==ID_index)
346 dest.push_back(index_expr.index());
349 else if(src.
id()==ID_member)
353 else if(src.
id()==ID_if)
356 dest.push_back(if_expr.cond());
365 std::list<exprt> dest;
367 switch(instruction.
type())
381 dest.push_back(argument);
414 std::list<exprt> dest;
416 switch(instruction.
type())
420 dest.push_back(instruction.
call_lhs());
453 std::list<exprt> &dest)
455 if(src.
id()==ID_symbol)
457 else if(src.
id()==ID_address_of)
461 else if(src.
id()==ID_dereference)
465 dest.push_back(deref);
470 for(
const auto &op : src.
operands())
480 std::list<exprt> dest;
482 for(
const auto &expr : expressions)
490 std::list<exprt> &dest)
507 std::list<exprt> dest;
509 for(
const auto &expr : expressions)
525 return "(NO INSTRUCTION TYPE)";
535 for(goto_programt::instructiont::targetst::const_iterator
574 return "END_FUNCTION";
586 return "ATOMIC_BEGIN";
592 result+=
"START THREAD ";
615 if(i.is_backwards_goto())
632 instruction.output(out);
658 for(
const auto &t : i.targets)
672 i.target_number=++cnt;
674 i.target_number != 0,
"GOTO instruction target cannot be zero");
683 for(
const auto &t : i.targets)
688 t->target_number != 0,
"instruction's number cannot be zero");
691 "GOTO instruction target cannot be nil_target");
704 typedef std::map<const_targett, targett, target_less_than> targets_mappingt;
705 targets_mappingt targets_mapping;
711 for(instructionst::const_iterator
717 targets_mapping[it]=new_instruction;
718 *new_instruction=*it;
725 for(
auto &t : i.targets)
727 targets_mappingt::iterator
728 m_target_it=targets_mapping.find(t);
732 t=m_target_it->second;
745 if(i.is_assert() && !i.condition().is_true())
756 i.incoming_edges.clear();
759 for(instructionst::iterator
767 s->incoming_edges.insert(it);
776 _type == other.
_type &&
777 _code == other.
_code &&
779 targets.size() == other.
targets.size() &&
791 auto expr_symbol_finder = [&](
const exprt &e) {
795 for(
const auto &identifier : typetags)
799 !ns.
lookup(identifier, symbol),
805 auto ¤t_source_location = source_location();
807 [&ns, vm, ¤t_source_location](
const exprt &e) {
808 if(e.id() == ID_symbol)
811 const auto &goto_id = goto_symbol_expr.get_identifier();
814 if(!ns.
lookup(goto_id, table_symbol))
816 bool symbol_expr_type_matches_symbol_table =
817 goto_symbol_expr.
type() == table_symbol->
type;
820 !symbol_expr_type_matches_symbol_table &&
821 table_symbol->
type.
id() == ID_code)
828 goto_symbol_expr.type().source_location().get_file() !=
832 auto goto_symbol_expr_type =
836 goto_symbol_expr_type.return_type() =
837 table_symbol_type.return_type();
839 symbol_expr_type_matches_symbol_table =
840 goto_symbol_expr_type == table_symbol_type;
845 !symbol_expr_type_matches_symbol_table &&
846 goto_symbol_expr.type().id() == ID_array &&
852 if(table_symbol->
type.
id() == ID_array)
855 symbol_table_array_type.size() =
nil_exprt();
857 symbol_expr_type_matches_symbol_table =
858 goto_symbol_expr.type() == symbol_table_array_type;
864 symbol_expr_type_matches_symbol_table,
865 id2string(goto_id) +
" type inconsistency\n" +
866 "goto program type: " + goto_symbol_expr.type().id_string() +
867 "\n" +
"symbol table type: " + table_symbol->
type.
id_string(),
868 current_source_location);
882 "goto instruction expects at least one target",
887 get_target()->is_target() && get_target()->target_number != 0,
888 "goto target has to be a target",
895 "assume instruction should not have a target",
902 "assert instruction should not have a target",
905 expr_symbol_finder(
guard);
927 _code.get_statement() == ID_return,
928 "SET_RETURN_VALUE instruction should contain a return statement",
934 _code.get_statement() == ID_assign,
935 "assign instruction should contain an assign statement");
937 vm, targets.empty(),
"assign instruction should not have a target");
942 _code.get_statement() == ID_decl,
943 "declaration instructions should contain a declaration statement",
947 !ns.
lookup(decl_symbol().get_identifier(), table_symbol),
948 "declared symbols should be known",
949 id2string(decl_symbol().get_identifier()),
955 _code.get_statement() == ID_dead,
956 "dead instructions should contain a dead statement",
960 !ns.
lookup(dead_symbol().get_identifier(), table_symbol),
961 "removed symbols should be known",
962 id2string(dead_symbol().get_identifier()),
968 _code.get_statement() == ID_function_call,
969 "function call instruction should contain a call statement",
972 expr_symbol_finder(_code);
973 std::for_each(_code.depth_begin(), _code.depth_end(), type_finder);
985 std::function<std::optional<exprt>(
exprt)> f)
990 if(get_other().get_statement() == ID_expression)
993 if(new_expression.has_value())
996 new_other.expression() = *new_expression;
997 set_other(new_other);
1004 auto new_return_value = f(return_value());
1005 if(new_return_value.has_value())
1006 return_value() = *new_return_value;
1012 auto new_assign_lhs = f(assign_lhs());
1013 auto new_assign_rhs = f(assign_rhs());
1014 if(new_assign_lhs.has_value())
1015 assign_lhs_nonconst() = new_assign_lhs.value();
1016 if(new_assign_rhs.has_value())
1017 assign_rhs_nonconst() = new_assign_rhs.value();
1023 auto new_symbol = f(decl_symbol());
1024 if(new_symbol.has_value())
1031 auto new_symbol = f(dead_symbol());
1032 if(new_symbol.has_value())
1039 auto new_lhs = f(
as_const(*this).call_lhs());
1040 if(new_lhs.has_value())
1041 call_lhs() = *new_lhs;
1043 auto new_call_function = f(
as_const(*this).call_function());
1044 if(new_call_function.has_value())
1045 call_function() = *new_call_function;
1048 bool argument_changed =
false;
1050 for(
auto &a : new_arguments)
1053 if(new_a.has_value())
1056 argument_changed =
true;
1060 if(argument_changed)
1061 call_arguments() = std::move(new_arguments);
1081 auto new_condition = f(condition());
1082 if(new_condition.has_value())
1083 condition_nonconst() = new_condition.value();
1089 std::function<
void(
const exprt &)> f)
const
1094 if(get_other().get_statement() == ID_expression)
1117 for(
auto &a : call_arguments())
1148 if(!ins.equals(*other_it))
1152 auto other_target_it = other_it->targets.begin();
1153 for(
const auto &t : ins.targets)
1156 t->location_number - ins.location_number !=
1157 (*other_target_it)->location_number - other_it->location_number)
1177 out <<
"NO_INSTRUCTION_TYPE";
1201 out <<
"START_THREAD";
1204 out <<
"END_THREAD";
1210 out <<
"END_FUNCTION";
1213 out <<
"ATOMIC_BEGIN";
1216 out <<
"ATOMIC_END";
1219 out <<
"SET_RETURN_VALUE";
1225 out <<
"FUNCTION_CALL";
1234 out <<
"INCOMPLETE_GOTO";
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
static exprt guard(const exprt::operandst &guards, exprt cond)
bool is_incomplete() const
codet representation of a goto statement.
const irep_idt & get_statement() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
bool is_true() const
Return whether the expression is a constant representing true.
depth_iteratort depth_end()
depth_iteratort depth_begin()
This class represents an instruction in the GOTO intermediate representation.
unsigned target_number
A number to identify branch targets.
const exprt & condition() const
Get the condition of gotos, assume, assert.
const exprt & call_lhs() const
Get the lhs of a FUNCTION_CALL (may be nil)
bool is_target() const
Is this node a branch target?
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
goto_instruction_codet _code
Do not read or modify directly – use code() and code_nonconst() instead.
void apply(std::function< void(const exprt &)>) const
Apply given function to all expressions.
targetst targets
The list of successor instructions.
const exprt & return_value() const
Get the return value of a SET_RETURN_VALUE instruction.
const goto_instruction_codet & code() const
Get the code represented by this instruction.
goto_program_instruction_typet _type
const goto_instruction_codet & get_other() const
Get the statement for OTHER.
bool equals(const instructiont &other) const
Syntactic equality: two instructiont are equal if they have the same type, code, guard,...
void transform(std::function< std::optional< exprt >(exprt)>)
Apply given transformer to all expressions; no return value means no change needed.
unsigned location_number
A globally unique number to identify a program location.
static const unsigned nil_target
Uniquely identify an invalid target or location.
const exprt & assign_rhs() const
Get the rhs of the assignment for ASSIGN.
const source_locationt & source_location() const
std::ostream & output(std::ostream &) const
Output this instruction to the given stream.
const symbol_exprt & dead_symbol() const
Get the symbol for DEAD.
exprt guard
Guard for gotos, assume, assert Use condition() method to access.
const symbol_exprt & decl_symbol() const
Get the declared symbol for DECL.
bool is_incomplete_goto() const
const_targett get_target() const
Returns the first (and only) successor for the usual case of a single target.
const exprt & assign_lhs() const
Get the lhs of the assignment for ASSIGN.
goto_program_instruction_typet type() const
What kind of instruction?
void validate(const namespacet &ns, const validation_modet vm) const
Check that the instruction is well-formed.
const exprt::operandst & call_arguments() const
Get the arguments of a FUNCTION_CALL.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
void copy_from(const goto_programt &src)
Copy a full goto program, preserving targets.
void clear()
Clear the goto program.
void update()
Update all indices.
std::ostream & output(std::ostream &out) const
Output goto-program to given stream.
bool has_assertion() const
Does the goto program have an assertion?
instructionst::const_iterator const_targett
targett add_instruction()
Adds an instruction at the end.
void compute_incoming_edges()
Compute for each instruction the set of instructions it is a successor of.
std::set< irep_idt > decl_identifierst
void get_decl_identifiers(decl_identifierst &decl_identifiers) const
get the variables in decl statements
std::list< Target > get_successors(Target target) const
Get control-flow successors of a given instruction.
void compute_location_numbers()
Compute location numbers.
void compute_target_numbers()
Compute the target numbers.
bool equals(const goto_programt &other) const
Syntactic equality: two goto_programt are equal if, and only if, they have the same number of instruc...
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
void compute_loop_numbers()
Compute loop numbers.
bool get_bool(const irep_idt &name) const
const irept & find(const irep_idt &name) const
const std::string & id_string() const
const irep_idt & id() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const irep_idt & get_comment() const
const irep_idt & get_file() const
std::string as_string() const
typet type
Type of symbol.
The Boolean constant true.
const source_locationt & source_location() const
Forward depth-first search iterators These iterators' copy operations are expensive,...
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest, const std::vector< irep_idt > &subs_to_find)
Find identifiers with id ID_symbol of the sub expressions and the subs with ID in subs_to_find consid...
std::unordered_set< irep_idt > find_symbols_sett
void parse_lhs_read(const exprt &src, std::list< exprt > &dest)
std::list< exprt > expressions_written(const goto_programt::instructiont &instruction)
std::string as_string(const class namespacet &ns, const irep_idt &function, const goto_programt::instructiont &i)
void objects_read(const exprt &src, std::list< exprt > &dest)
std::ostream & operator<<(std::ostream &out, goto_program_instruction_typet t)
Outputs a string representation of a goto_program_instruction_typet
void objects_written(const exprt &src, std::list< exprt > &dest)
std::list< exprt > expressions_read(const goto_programt::instructiont &instruction)
goto_program_instruction_typet
The type of an instruction in a GOTO program.
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
bool is_true(const literalt &l)
API to expression classes for Pointers.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
static std::string comment(const rw_set_baset::entryt &entry, bool write)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
static code_landingpadt & to_code_landingpad(codet &code)
code_expressiont & to_code_expression(codet &code)
API to expression classes.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
#define DATA_CHECK_WITH_DIAGNOSTICS(vm, condition, message,...)
#define DATA_CHECK(vm, condition, message)
This macro takes a condition which denotes a well-formedness criterion on goto programs,...
void validate_full_code(const codet &code, const namespacet &ns, const validation_modet vm)
Check that the given code statement is well-formed (full check, including checks of all subexpression...
void validate_full_expr(const exprt &expr, const namespacet &ns, const validation_modet vm)
Check that the given expression is well-formed (full check, including checks of all subexpressions an...