|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Shortest path graph |
| 4 | +
|
| 5 | + |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#ifndef CPROVER_SYMEX_SHORTEST_PATH_GRAPH_H |
| 10 | +#define CPROVER_SYMEX_SHORTEST_PATH_GRAPH_H |
| 11 | + |
| 12 | +#include <goto-programs/cfg.h> |
| 13 | +#include <path-symex/locs.h> |
| 14 | +#include <goto-programs/goto_model.h> |
| 15 | +#include <limits> |
| 16 | + |
| 17 | + |
| 18 | +struct shortest_path_nodet |
| 19 | +{ |
| 20 | + bool visited; |
| 21 | + std::size_t shortest_path_to_property; |
| 22 | + bool is_property; |
| 23 | + shortest_path_nodet(): |
| 24 | + visited(false), |
| 25 | + is_property(false) |
| 26 | + { |
| 27 | + shortest_path_to_property = std::numeric_limits<std::size_t>::max(); |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +/// \brief constructs a CFG of all program locations. Then computes |
| 32 | +/// the shortest path from every program location to a single property. |
| 33 | +/// WARNING: if more than one property is present in the graph, we will |
| 34 | +/// use the first property found |
| 35 | +/// The distances computed for each node are written to the corresponding |
| 36 | +/// loct in the locst passed as param to the constructor. This allows us |
| 37 | +/// to use these numbers to guide a symex search |
| 38 | +/// \param goto functions to create the CFG from, locs struct made from the |
| 39 | +/// same goto_functions |
| 40 | +class shortest_path_grapht: public cfg_baset<shortest_path_nodet> |
| 41 | +{ |
| 42 | +public: |
| 43 | + explicit shortest_path_grapht( |
| 44 | + const goto_functionst &_goto_functions, locst &_locs): |
| 45 | + locs(_locs), |
| 46 | + target_to_loc_map(_locs) |
| 47 | + { |
| 48 | + cfg_baset<shortest_path_nodet>::operator()(_goto_functions); |
| 49 | + get_path_lengths_to_property(); |
| 50 | + } |
| 51 | + |
| 52 | +protected: |
| 53 | + /// \brief writes the computed shortest path for every node |
| 54 | + /// in the graph to the corresponding location in locst. |
| 55 | + /// This is done so that we can use these numbers to guide |
| 56 | + /// a search heuristic for symex |
| 57 | + void write_lengths_to_locs(); |
| 58 | + /// \brief computes the shortest path from every node in |
| 59 | + /// the graph to a single property. WARNING: if more than one property |
| 60 | + /// is present, we use the first one discovered. |
| 61 | + /// Calls bfs() to do this. |
| 62 | + void get_path_lengths_to_property(); |
| 63 | + /// \brief implements backwards BFS to compute distance from every node in |
| 64 | + /// the graph to the node index given as parameter |
| 65 | + /// \param destination node index |
| 66 | + void bfs(node_indext property_index); |
| 67 | + std::set<node_indext> working_set; |
| 68 | + locst &locs; |
| 69 | + target_to_loc_mapt target_to_loc_map; |
| 70 | +}; |
| 71 | + |
| 72 | +#endif /* CPROVER_SYMEX_SHORTEST_PATH_GRAPH_H */ |
0 commit comments