CBMC
trace_automaton.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Loop Acceleration
4 
5 Author: Matt Lewis
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_TRACE_AUTOMATON_H
13 #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_TRACE_AUTOMATON_H
14 
15 #include "path.h"
16 
18 
19 #include <map>
20 #include <vector>
21 #include <set>
22 #include <iosfwd>
23 
24 typedef unsigned int statet;
25 typedef std::set<statet> state_sett;
26 
28 {
29  public:
32  num_states(0)
33  {
34  }
35 
36  statet add_state();
38 
40  {
41  return accept_states.find(s)!=accept_states.end();
42  }
43 
45  {
46  accept_states.insert(s);
47  }
48 
51 
52  void reverse(goto_programt::targett epsilon);
53  void trim();
54 
55  std::size_t count_transitions();
56 
57  void output(std::ostream &str) const;
58 
59  void clear()
60  {
61  transitions.clear();
62  accept_states.clear();
63  num_states=0;
64  }
65 
66  void swap(automatont &that)
67  {
68  transitions.swap(that.transitions);
69  accept_states.swap(that.accept_states);
72  }
73 
74  static const statet no_state;
75 
76 // protected:
77  typedef std::
78  multimap<goto_programt::targett, statet, goto_programt::target_less_than>
80  typedef std::pair<transitionst::iterator, transitionst::iterator>
82  typedef std::vector<transitionst> transition_tablet;
83 
85  unsigned num_states;
88 };
89 
91 {
92  public:
93  explicit trace_automatont(goto_programt &_goto_program):
94  goto_program(_goto_program)
95  {
97  init_nta();
98 
100  epsilon++; // TODO: This is illegal.
101  }
102 
103  void add_path(patht &path);
104 
105  void build();
106 
108  {
109  return dta.init_state;
110  }
111 
112  void accept_states(state_sett &states)
113  {
114  states.insert(dta.accept_states.begin(), dta.accept_states.end());
115  }
116 
117  typedef std::pair<statet, statet> state_pairt;
118  typedef std::multimap<
120  state_pairt,
123  typedef std::pair<sym_mapt::iterator, sym_mapt::iterator> sym_range_pairt;
124 
125  void get_transitions(sym_mapt &transitions);
126 
127  unsigned num_states()
128  {
129  return dta.num_states;
130  }
131 
132  typedef std::set<goto_programt::targett, goto_programt::target_less_than>
135 
136  protected:
137  void build_alphabet(goto_programt &program);
138  void init_nta();
139 
141  {
142  return alphabet.find(t)!=alphabet.end();
143  }
144 
146 
147  void determinise();
148  void epsilon_closure(state_sett &s);
149 
150  void minimise();
151  void reverse();
152 
156 
157  typedef std::map<state_sett, statet> state_mapt;
158 
161  std::vector<state_sett> unmarked_dstates;
163 
166 };
167 
168 #endif // CPROVER_GOTO_INSTRUMENT_ACCELERATE_TRACE_AUTOMATON_H
bool is_accepting(statet s)
unsigned num_states
std::vector< transitionst > transition_tablet
static const statet no_state
void set_accepting(statet s)
transition_tablet transitions
std::pair< transitionst::iterator, transitionst::iterator > transition_ranget
statet add_state()
void output(std::ostream &str) const
void move(statet s, goto_programt::targett a, state_sett &t)
void swap(automatont &that)
void reverse(goto_programt::targett epsilon)
statet init_state
void add_trans(statet s, goto_programt::targett a, statet t)
state_sett accept_states
std::size_t count_transitions()
std::multimap< goto_programt::targett, statet, goto_programt::target_less_than > transitionst
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
instructionst instructions
The list of instructions in the goto program.
Definition: goto_program.h:622
instructionst::iterator targett
Definition: goto_program.h:614
bool in_alphabet(goto_programt::targett t)
goto_programt::targett epsilon
void get_transitions(sym_mapt &transitions)
statet find_dstate(state_sett &s)
void add_dtrans(state_sett &s, goto_programt::targett a, state_sett &t)
statet add_dstate(state_sett &s)
trace_automatont(goto_programt &_goto_program)
void accept_states(state_sett &states)
void build_alphabet(goto_programt &program)
std::pair< sym_mapt::iterator, sym_mapt::iterator > sym_range_pairt
std::multimap< goto_programt::targett, state_pairt, goto_programt::target_less_than > sym_mapt
std::vector< state_sett > unmarked_dstates
std::map< state_sett, statet > state_mapt
std::pair< statet, statet > state_pairt
unsigned num_states()
void add_path(patht &path)
std::set< goto_programt::targett, goto_programt::target_less_than > alphabett
void epsilon_closure(state_sett &s)
goto_programt & goto_program
void pop_unmarked_dstate(state_sett &s)
Concrete Goto Program.
Loop Acceleration.
std::list< path_nodet > patht
Definition: path.h:44
A total order over targett and const_targett.
Definition: goto_program.h:392
std::set< statet > state_sett
unsigned int statet