@@ -27,25 +27,31 @@ Module: State Encoding
2727class state_encodingt
2828{
2929public:
30+ state_encodingt (const goto_functionst &__goto_functions)
31+ : goto_functions(__goto_functions)
32+ {
33+ }
34+
3035 void operator ()(
31- const goto_functionst &,
3236 const goto_functiont &,
3337 encoding_targett &);
3438
3539 void encode (
36- const goto_functionst &,
3740 const goto_functiont &,
41+ const std::string &state_prefix,
3842 const symbol_exprt &entry_state,
43+ const exprt &return_lhs,
3944 encoding_targett &);
4045
4146protected:
4247 using loct = goto_programt::const_targett;
48+ const goto_functionst &goto_functions;
4349
4450 symbol_exprt out_state_expr (loct) const ;
4551 symbol_exprt state_expr_with_suffix (loct, const std::string &suffix) const ;
4652 symbol_exprt out_state_expr (loct, bool taken) const ;
4753 symbol_exprt in_state_expr (loct) const ;
48- std::vector<irep_idt > incoming_symbols (loct) const ;
54+ std::vector<symbol_exprt > incoming_symbols (loct) const ;
4955 exprt evaluate_expr (loct, const exprt &, const exprt &) const ;
5056 exprt evaluate_expr_rec (
5157 loct,
@@ -60,16 +66,16 @@ class state_encodingt
6066 void setup_incoming (const goto_functiont &);
6167 exprt assignment_constraint (loct, exprt lhs, exprt rhs) const ;
6268 void function_call (
63- const goto_functionst &,
6469 goto_programt::const_targett,
6570 encoding_targett &);
6671 void function_call_symbol (
67- const goto_functionst &,
6872 goto_programt::const_targett,
6973 encoding_targett &);
7074
75+ std::string state_prefix;
7176 loct first_loc;
7277 symbol_exprt entry_state = symbol_exprt(irep_idt(), typet());
78+ exprt return_lhs = nil_exprt();
7379 using incomingt = std::map<loct, std::vector<loct>>;
7480 incomingt incoming;
7581};
@@ -84,7 +90,7 @@ symbol_exprt state_encodingt::state_expr_with_suffix(
8490 const std::string &suffix) const
8591{
8692 irep_idt identifier =
87- std::string ( " S " ) + std::to_string (loc->location_number ) + suffix;
93+ state_prefix + std::to_string (loc->location_number ) + suffix;
8894 return symbol_exprt (identifier, state_predicate_type ());
8995}
9096
@@ -93,13 +99,13 @@ symbol_exprt state_encodingt::out_state_expr(loct loc, bool taken) const
9399 return state_expr_with_suffix (loc, taken ? " T" : " " );
94100}
95101
96- std::vector<irep_idt > state_encodingt::incoming_symbols (loct loc) const
102+ std::vector<symbol_exprt > state_encodingt::incoming_symbols (loct loc) const
97103{
98104 auto incoming_it = incoming.find (loc);
99105
100106 DATA_INVARIANT (incoming_it != incoming.end (), " incoming is complete" );
101107
102- std::vector<irep_idt > symbols;
108+ std::vector<symbol_exprt > symbols;
103109 symbols.reserve (incoming_it->second .size ());
104110
105111 for (auto &loc_in : incoming_it->second )
@@ -114,7 +120,7 @@ std::vector<irep_idt> state_encodingt::incoming_symbols(loct loc) const
114120 suffix = " T" ;
115121 }
116122
117- symbols.push_back (" S " + std::to_string (loc_in-> location_number ) + suffix);
123+ symbols.push_back (state_expr_with_suffix (loc_in, suffix) );
118124 }
119125
120126 return symbols;
@@ -128,10 +134,9 @@ symbol_exprt state_encodingt::in_state_expr(loct loc) const
128134 auto incoming_symbols = this ->incoming_symbols (loc);
129135
130136 if (incoming_symbols.size () == 1 )
131- return symbol_exprt (incoming_symbols.front (), state_predicate_type ());
132-
133- return symbol_exprt (
134- " S" + std::to_string (loc->location_number ) + " in" , state_predicate_type ());
137+ return incoming_symbols.front ();
138+ else
139+ return state_expr_with_suffix (loc, " in" );
135140}
136141
137142exprt state_encodingt::evaluate_expr (
@@ -366,7 +371,6 @@ static exprt simplifying_not(exprt src)
366371}
367372
368373void state_encodingt::function_call_symbol (
369- const goto_functionst &goto_functions,
370374 goto_programt::const_targett loc,
371375 encoding_targett &dest)
372376{
@@ -428,9 +432,11 @@ void state_encodingt::function_call_symbol(
428432 loc, function_application_exprt (function_entry_state, {arguments_state}));
429433
430434 // now do the body, recursively
431- state_encodingt body_state_encoding;
435+ state_encodingt body_state_encoding (goto_functions);
436+ auto new_state_prefix =
437+ state_prefix + std::to_string (loc->location_number ) + " ." ;
432438 body_state_encoding.encode (
433- goto_functions, f->second , function_entry_state, dest);
439+ f->second , new_state_prefix, function_entry_state, nil_exprt () , dest);
434440
435441 // Function return state (suffix PostReturn).
436442 // This is the state after exiting the function but prior to
@@ -481,7 +487,6 @@ void state_encodingt::function_call_symbol(
481487}
482488
483489void state_encodingt::function_call (
484- const goto_functionst &goto_functions,
485490 goto_programt::const_targett loc,
486491 encoding_targett &dest)
487492{
@@ -495,7 +500,7 @@ void state_encodingt::function_call(
495500 }
496501 else if (function.id () == ID_symbol)
497502 {
498- function_call_symbol (goto_functions, loc, dest);
503+ function_call_symbol (loc, dest);
499504 }
500505 else
501506 {
@@ -505,7 +510,6 @@ void state_encodingt::function_call(
505510}
506511
507512void state_encodingt::operator ()(
508- const goto_functionst &goto_functions,
509513 const goto_functiont &goto_function,
510514 encoding_targett &dest)
511515{
@@ -520,17 +524,20 @@ void state_encodingt::operator()(
520524 implies_exprt (
521525 true_exprt (), function_application_exprt (in_state, {state_expr ()})));
522526
523- encode (goto_functions, goto_function , in_state, dest);
527+ encode (goto_function, " S " , in_state, nil_exprt () , dest);
524528}
525529
526530void state_encodingt::encode (
527- const goto_functionst &goto_functions,
528531 const goto_functiont &goto_function,
532+ const std::string &state_prefix,
529533 const symbol_exprt &entry_state,
534+ const exprt &return_lhs,
530535 encoding_targett &dest)
531536{
532537 first_loc = goto_function.body .instructions .begin ();
538+ this ->state_prefix = state_prefix;
533539 this ->entry_state = entry_state;
540+ this ->return_lhs = return_lhs;
534541
535542 setup_incoming (goto_function);
536543
@@ -549,13 +556,10 @@ void state_encodingt::encode(
549556 auto s = state_expr ();
550557 for (auto incoming_symbol : incoming_symbols)
551558 {
552- auto incoming_state =
553- symbol_exprt (incoming_symbol, state_predicate_type ());
554-
555559 dest << forall_exprt (
556560 {s},
557561 implies_exprt (
558- function_application_exprt (std::move (incoming_state) , {s}),
562+ function_application_exprt (incoming_symbol , {s}),
559563 function_application_exprt (in_state_expr (loc), {s})));
560564 }
561565 }
@@ -645,14 +649,21 @@ void state_encodingt::encode(
645649 }
646650 else if (loc->is_function_call ())
647651 {
648- function_call (goto_functions, loc, dest);
652+ function_call (loc, dest);
649653 }
650654 else if (loc->is_set_return_value ())
651655 {
652- // treat these as assignments to a special symbol named 'return_value'
653- auto rhs = loc->return_value ();
654- auto lhs = symbol_exprt (" return_value" , rhs.type ());
655- dest << assignment_constraint (loc, std::move (lhs), std::move (rhs));
656+ const auto &rhs = loc->return_value ();
657+
658+ if (return_lhs.is_nil ())
659+ {
660+ // treat these as assignments to a special symbol named 'return_value'
661+ auto lhs = symbol_exprt (" return_value" , rhs.type ());
662+ dest << assignment_constraint (loc, std::move (lhs), std::move (rhs));
663+ }
664+ else
665+ {
666+ }
656667 }
657668 }
658669}
@@ -670,7 +681,7 @@ void state_encoding(
670681 if (f_entry == goto_model.goto_functions .function_map .end ())
671682 throw incorrect_goto_program_exceptiont (" The program has no entry point" );
672683
673- state_encodingt{}( goto_model.goto_functions , f_entry->second , dest);
684+ state_encodingt{goto_model.goto_functions }( f_entry->second , dest);
674685 }
675686 else
676687 {
@@ -682,7 +693,7 @@ void state_encoding(
682693 if (f->second .body_available ())
683694 {
684695 dest.annotation (" function " + id2string (f->first ));
685- state_encodingt{}( goto_model.goto_functions , f->second , dest);
696+ state_encodingt{goto_model.goto_functions }( f->second , dest);
686697 }
687698 }
688699 }
0 commit comments