Skip to content

Commit c634148

Browse files
committed
progress on inlining
1 parent 255e892 commit c634148

File tree

3 files changed

+28
-74
lines changed

3 files changed

+28
-74
lines changed

src/cprover/cprover_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int cprover_parse_optionst::main()
106106

107107
label_properties(goto_model);
108108

109-
bool perform_inlining = true;
109+
bool perform_inlining = !cmdline.isset("no-inline");
110110
// bool perform_inlining = false;
111111

112112
if(perform_inlining)

src/cprover/cprover_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Author: Daniel Kroening, [email protected]
1919
"(smt2)(text)(outfile):" \
2020
"(safety)" \
2121
"(solve)" \
22-
"(inline)" \
22+
"(inline)(no-inline)" \
2323
"(show-goto-functions)(show-loops)" \
2424
"(validate-goto-model)" \
2525
"(verbose)"

src/cprover/state_encoding.cpp

Lines changed: 26 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ class state_encodingt
3333
}
3434

3535
void operator()(
36-
const goto_functiont &,
36+
const goto_functionst::function_mapt::const_iterator,
3737
encoding_targett &);
3838

3939
void encode(
4040
const goto_functiont &,
4141
const std::string &state_prefix,
42+
const std::string &annotation,
4243
const symbol_exprt &entry_state,
4344
const exprt &return_lhs,
4445
encoding_targett &);
@@ -73,6 +74,7 @@ class state_encodingt
7374
encoding_targett &);
7475

7576
std::string state_prefix;
77+
std::string annotation;
7678
loct first_loc;
7779
symbol_exprt entry_state = symbol_exprt(irep_idt(), typet());
7880
exprt return_lhs = nil_exprt();
@@ -378,6 +380,9 @@ void state_encodingt::function_call_symbol(
378380
const auto &type = to_code_type(function.type());
379381
auto identifier = function.get_identifier();
380382

383+
auto new_annotation = annotation + u8" \u2192 " + id2string(identifier);
384+
dest.annotation(new_annotation);
385+
381386
// malloc is special-cased
382387
if(identifier == "malloc")
383388
{
@@ -436,54 +441,12 @@ void state_encodingt::function_call_symbol(
436441
auto new_state_prefix =
437442
state_prefix + std::to_string(loc->location_number) + ".";
438443
body_state_encoding.encode(
439-
f->second, new_state_prefix, function_entry_state, nil_exprt(), dest);
440-
441-
// Function return state (suffix PostReturn).
442-
// This is the state after exiting the function but prior to
443-
// assigning the LHS of the function call.
444-
// auto return_state = state_expr_with_suffix(loc, "PostReturn");
445-
446-
/*
447-
constraints.push_back(
448-
multi_ary_exprt(
449-
ID_goto_contract,
450-
{loc->call_function(), in_state, return_state, arguments_evaluated},
451-
bool_typet()));
452-
*/
453-
454-
// assign the return value, if any
455-
if(loc->call_lhs().is_not_nil())
456-
{
457-
// exprt equality_rhs = return_state;
458-
459-
/*
460-
auto &return_type = loc->call_lhs().type();
461-
auto rhs_evaluated =
462-
evaluate_expr(
463-
loc,
464-
return_state,
465-
symbol_exprt("return_value", return_type));
466-
467-
multi_ary_exprt designator(ID_designator, { loc->call_lhs() }, typet());
468-
469-
auto lhs = out_state_expr(source);
470-
471-
auto rhs = update_exprt(
472-
return_state,
473-
designator,
474-
rhs_evaluated);
475-
476-
// 'out state' equality
477-
constraints.push_back(equal_exprt(lhs, rhs));
478-
*/
479-
}
480-
/*
481-
else
482-
{
483-
// 'out state' equality
484-
dest << equal_exprt(out_state_expr(loc), return_state);
485-
}
486-
*/
444+
f->second,
445+
new_state_prefix,
446+
new_annotation,
447+
function_entry_state,
448+
nil_exprt(),
449+
dest);
487450
}
488451

489452
void state_encodingt::function_call(
@@ -510,9 +473,11 @@ void state_encodingt::function_call(
510473
}
511474

512475
void state_encodingt::operator()(
513-
const goto_functiont &goto_function,
476+
goto_functionst::function_mapt::const_iterator f_entry,
514477
encoding_targett &dest)
515478
{
479+
const auto &goto_function = f_entry->second;
480+
516481
if(goto_function.body.instructions.empty())
517482
return;
518483

@@ -524,18 +489,22 @@ void state_encodingt::operator()(
524489
implies_exprt(
525490
true_exprt(), function_application_exprt(in_state, {state_expr()})));
526491

527-
encode(goto_function, "S", in_state, nil_exprt(), dest);
492+
auto annotation = id2string(f_entry->first);
493+
494+
encode(goto_function, "S", annotation, in_state, nil_exprt(), dest);
528495
}
529496

530497
void state_encodingt::encode(
531498
const goto_functiont &goto_function,
532499
const std::string &state_prefix,
500+
const std::string &annotation,
533501
const symbol_exprt &entry_state,
534502
const exprt &return_lhs,
535503
encoding_targett &dest)
536504
{
537505
first_loc = goto_function.body.instructions.begin();
538506
this->state_prefix = state_prefix;
507+
this->annotation = annotation;
539508
this->entry_state = entry_state;
540509
this->return_lhs = return_lhs;
541510

@@ -673,30 +642,15 @@ void state_encoding(
673642
bool program_is_inlined,
674643
encoding_targett &dest)
675644
{
676-
if(program_is_inlined)
677-
{
678-
auto f_entry = goto_model.goto_functions.function_map.find(
679-
goto_functionst::entry_point());
645+
auto f_entry =
646+
goto_model.goto_functions.function_map.find(goto_functionst::entry_point());
680647

681-
if(f_entry == goto_model.goto_functions.function_map.end())
682-
throw incorrect_goto_program_exceptiont("The program has no entry point");
648+
if(f_entry == goto_model.goto_functions.function_map.end())
649+
throw incorrect_goto_program_exceptiont("The program has no entry point");
683650

684-
state_encodingt{goto_model.goto_functions}(f_entry->second, dest);
685-
}
686-
else
687-
{
688-
// output alphabetically
689-
const auto sorted = goto_model.goto_functions.sorted();
651+
dest.annotation("function " + id2string(f_entry->first));
690652

691-
for(const auto &f : sorted)
692-
{
693-
if(f->second.body_available())
694-
{
695-
dest.annotation("function " + id2string(f->first));
696-
state_encodingt{goto_model.goto_functions}(f->second, dest);
697-
}
698-
}
699-
}
653+
state_encodingt{goto_model.goto_functions}(f_entry, dest);
700654
}
701655

702656
void format_hooks();

0 commit comments

Comments
 (0)