本文整理汇总了C++中goto_programt类的典型用法代码示例。如果您正苦于以下问题:C++ goto_programt类的具体用法?C++ goto_programt怎么用?C++ goto_programt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了goto_programt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_globals
void invariant_propagationt::add_objects(
const goto_programt &goto_program)
{
// get the globals
object_listt globals;
get_globals(globals);
// get the locals
goto_programt::decl_identifierst locals;
goto_program.get_decl_identifiers(locals);
// cache the list for the locals to speed things up
typedef hash_map_cont<irep_idt, object_listt, irep_id_hash> object_cachet;
object_cachet object_cache;
for(goto_programt::instructionst::const_iterator
i_it=goto_program.instructions.begin();
i_it!=goto_program.instructions.end();
i_it++)
{
#if 0
invariant_sett &is=(*this)[i_it].invariant_set;
is.add_objects(globals);
#endif
for(goto_programt::decl_identifierst::const_iterator
l_it=locals.begin();
l_it!=locals.end();
l_it++)
{
// cache hit?
object_cachet::const_iterator e_it=object_cache.find(*l_it);
if(e_it==object_cache.end())
{
const symbolt &symbol=ns.lookup(*l_it);
object_listt &objects=object_cache[*l_it];
get_objects(symbol, objects);
#if 0
is.add_objects(objects);
#endif
}
#if 0
else
is.add_objects(e_it->second);
#endif
}
}
}
示例2: do_function_call
void string_instrumentationt::do_function_call(
goto_programt &dest,
goto_programt::targett target)
{
code_function_callt &call=
to_code_function_call(target->code);
exprt &function=call.function();
//const exprt &lhs=call.lhs();
if(function.id()==ID_symbol)
{
const irep_idt &identifier=
to_symbol_expr(function).get_identifier();
if(identifier=="strcoll")
{
}
else if(identifier=="strncmp")
do_strncmp(dest, target, call);
else if(identifier=="strxfrm")
{
}
else if(identifier=="strchr")
do_strchr(dest, target, call);
else if(identifier=="strcspn")
{
}
else if(identifier=="strpbrk")
{
}
else if(identifier=="strrchr")
do_strrchr(dest, target, call);
else if(identifier=="strspn")
{
}
else if(identifier=="strerror")
do_strerror(dest, target, call);
else if(identifier=="strstr")
do_strstr(dest, target, call);
else if(identifier=="strtok")
do_strtok(dest, target, call);
else if(identifier=="sprintf")
do_sprintf(dest, target, call);
else if(identifier=="snprintf")
do_snprintf(dest, target, call);
else if(identifier=="fscanf")
do_fscanf(dest, target, call);
dest.update();
}
}
示例3: stack_depth
void stack_depth(
goto_programt &goto_program,
const symbol_exprt &symbol,
const int i_depth,
const exprt &max_depth)
{
assert(!goto_program.instructions.empty());
goto_programt::targett first=goto_program.instructions.begin();
binary_relation_exprt guard(symbol, ID_le, max_depth);
goto_programt::targett assert_ins=goto_program.insert_before(first);
assert_ins->make_assertion(guard);
assert_ins->location=first->location;
assert_ins->function=first->function;
assert_ins->location.set_comment("Stack depth exceeds "+i2string(i_depth));
assert_ins->location.set_property("stack-depth");
goto_programt::targett plus_ins=goto_program.insert_before(first);
plus_ins->make_assignment();
plus_ins->code=code_assignt(symbol,
plus_exprt(symbol, from_integer(1, symbol.type())));
plus_ins->location=first->location;
plus_ins->function=first->function;
goto_programt::targett last=--goto_program.instructions.end();
assert(last->is_end_function());
goto_programt::instructiont minus_ins;
minus_ins.make_assignment();
minus_ins.code=code_assignt(symbol,
minus_exprt(symbol, from_integer(1, symbol.type())));
minus_ins.location=last->location;
minus_ins.function=last->function;
goto_program.insert_before_swap(last, minus_ins);
}
示例4: true_exprt
void goto_convertt::convert_CPROVER_throw(
const codet &code,
goto_programt &dest)
{
// set the 'exception' flag
{
goto_programt::targett t_set_exception=
dest.add_instruction(ASSIGN);
t_set_exception->source_location=code.source_location();
t_set_exception->code=code_assignt(exception_flag(), true_exprt());
}
// do we catch locally?
if(targets.throw_set)
{
// need to process destructor stack
unwind_destructor_stack(
code.source_location(), targets.throw_stack_size, dest);
// add goto
goto_programt::targett t=dest.add_instruction();
t->make_goto(targets.throw_target);
t->source_location=code.source_location();
}
else // otherwise, we do a return
{
// need to process destructor stack
unwind_destructor_stack(code.source_location(), 0, dest);
// add goto
goto_programt::targett t=dest.add_instruction();
t->make_goto(targets.return_target);
t->source_location=code.source_location();
}
}
示例5: expr
void goto_checkt::add_guarded_claim(
const exprt &_expr,
const std::string &comment,
const std::string &property_class,
const source_locationt &source_location,
const exprt &src_expr,
const guardt &guard)
{
exprt expr(_expr);
// first try simplifier on it
if(enable_simplify)
simplify(expr, ns);
// throw away trivial properties?
if(!retain_trivial && expr.is_true())
return;
// add the guard
exprt guard_expr=guard.as_expr();
exprt new_expr;
if(guard_expr.is_true())
new_expr.swap(expr);
else
{
new_expr=exprt(ID_implies, bool_typet());
new_expr.move_to_operands(guard_expr, expr);
}
if(assertions.insert(new_expr).second)
{
goto_program_instruction_typet type=
enable_assert_to_assume?ASSUME:ASSERT;
goto_programt::targett t=new_code.add_instruction(type);
std::string source_expr_string=from_expr(ns, "", src_expr);
t->guard.swap(new_expr);
t->source_location=source_location;
t->source_location.set_comment(comment+" in "+source_expr_string);
t->source_location.set_property_class(property_class);
}
}
示例6: do_function_call_other
void goto_convertt::do_function_call_other(
const exprt &lhs,
const exprt &function,
const exprt::operandst &arguments,
goto_programt &dest)
{
// don't know what to do with it
goto_programt::targett t=dest.add_instruction(FUNCTION_CALL);
code_function_callt function_call;
function_call.add_source_location()=function.source_location();
function_call.lhs()=lhs;
function_call.function()=function;
function_call.arguments()=arguments;
t->source_location=function.source_location();
t->code.swap(function_call);
}
示例7: expr
void goto_checkt::add_guarded_claim(const exprt &_expr,
const std::string &comment, const std::string &property,
const locationt &location, const guardt &guard)
{
bool all_claims = options.get_bool_option("all-claims");
exprt expr(_expr);
// first try simplifier on it
if (!options.get_bool_option("no-simplify"))
{
expr2tc tmpexpr;
migrate_expr(expr, tmpexpr);
base_type(tmpexpr, ns);
expr = migrate_expr_back(tmpexpr);
simplify(expr);
}
if (!all_claims && expr.is_true())
return;
// add the guard
exprt guard_expr = migrate_expr_back(guard.as_expr());
exprt new_expr;
if (guard_expr.is_true())
new_expr.swap(expr);
else
{
new_expr = exprt("=>", bool_typet());
new_expr.move_to_operands(guard_expr, expr);
}
if (assertions.insert(new_expr).second)
{
goto_programt::targett t = new_code.add_instruction(ASSERT);
migrate_expr(new_expr, t->guard);
t->location = location;
t->location.comment(comment);
t->location.property(property);
}
}
示例8: construct_cfg
void cfg_dominatorst::construct_cfg(
const goto_programt &program,
goto_programt::const_targett PC)
{
nodet &node=node_map[PC];
node.PC=PC;
program.get_successors(PC, node.successors);
// now do backward edges
for(goto_programt::const_targetst::const_iterator
s_it=node.successors.begin();
s_it!=node.successors.end();
s_it++)
{
node_map[*s_it].predecessors.push_back(node.PC);
}
}
示例9: error
void string_instrumentationt::do_snprintf(
goto_programt &dest,
goto_programt::targett target,
code_function_callt &call)
{
const code_function_callt::argumentst &arguments=call.arguments();
if(arguments.size()<3)
{
error().source_location=target->source_location;
error() << "snprintf expected to have three or more arguments"
<< eom;
throw 0;
}
goto_programt tmp;
goto_programt::targett assertion=tmp.add_instruction();
assertion->source_location=target->source_location;
assertion->source_location.set_property_class("string");
assertion->source_location.set_comment("snprintf buffer overflow");
exprt bufsize=buffer_size(arguments[0]);
assertion->make_assertion(
binary_relation_exprt(bufsize, ID_ge, arguments[1]));
do_format_string_read(tmp, target, arguments, 2, 3, "snprintf");
if(call.lhs().is_not_nil())
{
goto_programt::targett return_assignment=tmp.add_instruction(ASSIGN);
return_assignment->source_location=target->source_location;
exprt rhs=side_effect_expr_nondett(call.lhs().type());
rhs.add_source_location()=target->source_location;
return_assignment->code=code_assignt(call.lhs(), rhs);
}
target->make_skip();
dest.insert_before_swap(target, tmp);
}
示例10: build_havoc_code
void havoc_loopst::build_havoc_code(
const goto_programt::targett loop_head,
const modifiest &modifies,
goto_programt &dest)
{
for(modifiest::const_iterator
m_it=modifies.begin();
m_it!=modifies.end();
m_it++)
{
exprt lhs=*m_it;
exprt rhs=side_effect_expr_nondett(lhs.type());
goto_programt::targett t=dest.add_instruction(ASSIGN);
t->function=loop_head->function;
t->source_location=loop_head->source_location;
t->code=code_assignt(lhs, rhs);
t->code.add_source_location()=loop_head->source_location;
}
}
示例11: error
void string_instrumentationt::do_sprintf(
goto_programt &dest,
goto_programt::targett target,
code_function_callt &call)
{
const code_function_callt::argumentst &arguments=call.arguments();
if(arguments.size()<2)
{
error().source_location=target->source_location;
error() << "sprintf expected to have two or more arguments" << eom;
throw 0;
}
goto_programt tmp;
goto_programt::targett assertion=tmp.add_instruction();
assertion->source_location=target->source_location;
assertion->source_location.set_property_class("string");
assertion->source_location.set_comment("sprintf buffer overflow");
// in the abstract model, we have to report a
// (possibly false) positive here
assertion->make_assertion(false_exprt());
do_format_string_read(tmp, target, arguments, 1, 2, "sprintf");
if(call.lhs().is_not_nil())
{
goto_programt::targett return_assignment=tmp.add_instruction(ASSIGN);
return_assignment->source_location=target->source_location;
exprt rhs=side_effect_expr_nondett(call.lhs().type());
rhs.add_source_location()=target->source_location;
return_assignment->code=code_assignt(call.lhs(), rhs);
}
target->make_skip();
dest.insert_before_swap(target, tmp);
}
示例12: err_location
void goto_convertt::do_atomic_end(
const exprt &lhs,
const exprt &function,
const exprt::operandst &arguments,
goto_programt &dest)
{
if(lhs.is_not_nil())
{
err_location(lhs);
throw "atomic_end does not expect an LHS";
}
if(!arguments.empty())
{
err_location(function);
throw "atomic_end takes no arguments";
}
goto_programt::targett t=dest.add_instruction(ATOMIC_END);
t->source_location=function.source_location();
}
示例13: skip_loops
static bool skip_loops(
goto_programt &goto_program,
const loop_idst &loop_ids,
messaget &message)
{
loop_idst::const_iterator l_it=loop_ids.begin();
Forall_goto_program_instructions(it, goto_program)
{
if(l_it==loop_ids.end())
break;
if(!it->is_backwards_goto())
continue;
const unsigned loop_id=it->loop_number;
if(*l_it<loop_id)
break; // error handled below
if(*l_it>loop_id)
continue;
goto_programt::targett loop_head=it->get_target();
goto_programt::targett next=it;
++next;
assert(next!=goto_program.instructions.end());
goto_programt::targett g=goto_program.insert_before(loop_head);
g->make_goto(next, true_exprt());
g->source_location=loop_head->source_location;
g->function=loop_head->function;
++l_it;
}
if(l_it!=loop_ids.end())
{
message.error() << "Loop " << *l_it << " not found"
<< messaget::eom;
return true;
}
return false;
}
示例14: to_code_type
void remove_function_pointerst::fix_return_type(
code_function_callt &function_call,
goto_programt &dest)
{
// are we returning anything at all?
if(function_call.lhs().is_nil())
return;
const code_typet &code_type=
to_code_type(ns.follow(function_call.function().type()));
// type already ok?
if(type_eq(
function_call.lhs().type(),
code_type.return_type(), ns))
return;
symbolt &tmp_symbol=
get_fresh_aux_symbol(
code_type.return_type(),
"remove_function_pointers",
"tmp_return_val",
function_call.source_location(),
irep_idt(),
symbol_table);
symbol_exprt tmp_symbol_expr;
tmp_symbol_expr.type()=tmp_symbol.type;
tmp_symbol_expr.set_identifier(tmp_symbol.name);
exprt old_lhs=function_call.lhs();
function_call.lhs()=tmp_symbol_expr;
goto_programt::targett t_assign=dest.add_instruction();
t_assign->make_assignment();
t_assign->code=code_assignt(
old_lhs, typecast_exprt(tmp_symbol_expr, old_lhs.type()));
}
示例15: dereference_program
void goto_program_dereferencet::dereference_program(
goto_programt &goto_program,
bool checks_only)
{
for(goto_programt::instructionst::iterator
it=goto_program.instructions.begin();
it!=goto_program.instructions.end();
it++)
{
new_code.clear();
assertions.clear();
dereference_instruction(it, checks_only);
// insert new instructions
while(!new_code.instructions.empty())
{
goto_program.insert_before_swap(it, new_code.instructions.front());
new_code.instructions.pop_front();
it++;
}
}
}