Skip to content

Commit 9f4a9dc

Browse files
committed
extract transition_systemt::inputs and ::state_variables
This extracts to replicated methods that identify the inputs and the state variables of the transition system.
1 parent 8aeba7c commit 9f4a9dc

File tree

4 files changed

+57
-93
lines changed

4 files changed

+57
-93
lines changed

src/ebmc/liveness_to_safety.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,10 @@ void liveness_to_safetyt::operator()()
120120
if(!properties.requires_lasso_constraints())
121121
return; // no
122122

123-
irep_idt module_identifier = transition_system.main_symbol->name;
124-
125123
// gather the state variables
126-
const namespacet ns(transition_system.symbol_table);
124+
state_vars = transition_system.state_variables();
127125

128-
const auto &symbol_module_map =
129-
transition_system.symbol_table.symbol_module_map;
130-
auto lower = symbol_module_map.lower_bound(module_identifier);
131-
auto upper = symbol_module_map.upper_bound(module_identifier);
132-
133-
for(auto it = lower; it != upper; it++)
134-
{
135-
const symbolt &symbol = ns.lookup(it->second);
136-
137-
if(symbol.is_state_var)
138-
state_vars.push_back(symbol.symbol_expr());
139-
}
126+
const namespacet ns(transition_system.symbol_table);
140127

141128
// create 'loop' shadow symbols for the state variables
142129
for(auto &symbol_expr : state_vars)

src/ebmc/random_traces.cpp

+2-78
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class random_tracest
8484

8585
constant_exprt random_value(const typet &);
8686

87-
symbolst inputs() const;
88-
symbolst state_variables() const;
8987
symbolst remove_constrained(const symbolst &) const;
9088

9189
void
@@ -440,80 +438,6 @@ constant_exprt random_tracest::random_value(const typet &type)
440438

441439
/*******************************************************************\
442440
443-
Function: random_tracest::inputs
444-
445-
Inputs:
446-
447-
Outputs:
448-
449-
Purpose:
450-
451-
\*******************************************************************/
452-
453-
random_tracest::symbolst random_tracest::inputs() const
454-
{
455-
symbolst inputs;
456-
457-
const auto &module_symbol = *transition_system.main_symbol;
458-
459-
if(module_symbol.type.id() != ID_module)
460-
throw ebmc_errort() << "expected a module but got "
461-
<< module_symbol.type.id();
462-
463-
const auto &ports = module_symbol.type.find(ID_ports);
464-
465-
// filter out the inputs
466-
for(auto &port : static_cast<const exprt &>(ports).operands())
467-
{
468-
DATA_INVARIANT(port.id() == ID_symbol, "port must be a symbol");
469-
if(port.get_bool(ID_input) && !port.get_bool(ID_output))
470-
{
471-
symbol_exprt input_symbol(port.get(ID_identifier), port.type());
472-
input_symbol.add_source_location() = port.source_location();
473-
inputs.push_back(std::move(input_symbol));
474-
}
475-
}
476-
477-
return inputs;
478-
}
479-
480-
/*******************************************************************\
481-
482-
Function: random_tracest::state_variables
483-
484-
Inputs:
485-
486-
Outputs:
487-
488-
Purpose:
489-
490-
\*******************************************************************/
491-
492-
random_tracest::symbolst random_tracest::state_variables() const
493-
{
494-
symbolst state_variables;
495-
496-
const auto &module_symbol = *transition_system.main_symbol;
497-
const namespacet ns(transition_system.symbol_table);
498-
499-
const auto &symbol_module_map =
500-
transition_system.symbol_table.symbol_module_map;
501-
auto lower = symbol_module_map.lower_bound(module_symbol.name);
502-
auto upper = symbol_module_map.upper_bound(module_symbol.name);
503-
504-
for(auto it = lower; it != upper; it++)
505-
{
506-
const symbolt &symbol = ns.lookup(it->second);
507-
508-
if(symbol.is_state_var)
509-
state_variables.push_back(symbol.symbol_expr());
510-
}
511-
512-
return state_variables;
513-
}
514-
515-
/*******************************************************************\
516-
517441
Function: random_tracest::remove_constrained
518442
519443
Inputs:
@@ -665,12 +589,12 @@ void random_tracest::operator()(
665589
ns,
666590
true);
667591

668-
auto inputs = this->inputs();
592+
auto inputs = transition_system.inputs();
669593

670594
if(inputs.empty())
671595
throw ebmc_errort() << "module does not have inputs";
672596

673-
auto state_variables = this->state_variables();
597+
auto state_variables = transition_system.state_variables();
674598

675599
message.statistics() << "Found " << inputs.size() << " input(s) and "
676600
<< state_variables.size() << " state variable(s)"

src/ebmc/transition_system.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,53 @@ int show_symbol_table(
368368
return get_transition_system(
369369
cmdline, message_handler, dummy_transition_system);
370370
}
371+
372+
std::vector<symbol_exprt> transition_systemt::state_variables() const
373+
{
374+
std::vector<symbol_exprt> state_variables;
375+
376+
const auto &module_symbol = *main_symbol;
377+
const namespacet ns(symbol_table);
378+
379+
const auto &symbol_module_map = symbol_table.symbol_module_map;
380+
auto lower = symbol_module_map.lower_bound(module_symbol.name);
381+
auto upper = symbol_module_map.upper_bound(module_symbol.name);
382+
383+
for(auto it = lower; it != upper; it++)
384+
{
385+
const symbolt &symbol = ns.lookup(it->second);
386+
387+
if(symbol.is_state_var)
388+
state_variables.push_back(symbol.symbol_expr());
389+
}
390+
391+
return state_variables;
392+
}
393+
394+
std::vector<symbol_exprt> transition_systemt::inputs() const
395+
{
396+
std::vector<symbol_exprt> inputs;
397+
398+
const auto &module_symbol = *main_symbol;
399+
400+
DATA_INVARIANT(
401+
module_symbol.type.id() == ID_module, "main_symbol must be module");
402+
403+
const auto &ports_irep = module_symbol.type.find(ID_ports);
404+
405+
// filter out the inputs
406+
auto &ports = static_cast<const exprt &>(ports_irep).operands();
407+
for(auto &port : ports)
408+
{
409+
DATA_INVARIANT(port.id() == ID_symbol, "port must be a symbol");
410+
if(port.get_bool(ID_input) && !port.get_bool(ID_output))
411+
{
412+
symbol_exprt input_symbol(
413+
to_symbol_expr(port).get_identifier(), port.type());
414+
input_symbol.add_source_location() = port.source_location();
415+
inputs.push_back(std::move(input_symbol));
416+
}
417+
}
418+
419+
return inputs;
420+
}

src/ebmc/transition_system.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class transition_systemt
2929
transt trans_expr; // transition system expression
3030

3131
void output(std::ostream &) const;
32+
33+
std::vector<symbol_exprt> state_variables() const;
34+
std::vector<symbol_exprt> inputs() const;
3235
};
3336

3437
transition_systemt get_transition_system(const cmdlinet &, message_handlert &);

0 commit comments

Comments
 (0)