|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Aggressive Slicer |
| 4 | +
|
| 5 | +Author: Elizabeth Polgreen, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// Aggressive slicer |
| 11 | +/// Consider the control flow graph of the goto program and a criterion |
| 12 | +/// description of aggressive slicer here |
| 13 | + |
| 14 | +#ifndef CPROVER_GOTO_INSTRUMENT_AGGRESSIVE_SLICER_H |
| 15 | +#define CPROVER_GOTO_INSTRUMENT_AGGRESSIVE_SLICER_H |
| 16 | + |
| 17 | +#include <list> |
| 18 | +#include <string> |
| 19 | +#include <unordered_set> |
| 20 | + |
| 21 | +#include <util/irep.h> |
| 22 | + |
| 23 | +#include <analyses/call_graph.h> |
| 24 | + |
| 25 | +#include <linking/static_lifetime_init.h> |
| 26 | + |
| 27 | +class goto_modelt; |
| 28 | +class message_handlert; |
| 29 | + |
| 30 | +/// \brief The aggressive slicer removes the body of all the functions except |
| 31 | +/// those on the shortest path, those within the call-depth of the |
| 32 | +/// shortest path, those given by name as command line argument, |
| 33 | +/// and those that contain a given irep_idt snippet |
| 34 | +/// If no properties are set by the user, we preserve all functions on |
| 35 | +/// the shortest paths to each property. |
| 36 | +class aggressive_slicert |
| 37 | +{ |
| 38 | +public: |
| 39 | + aggressive_slicert(goto_modelt &_goto_model, message_handlert &_msg) |
| 40 | + : preserve_all_direct_paths(false), |
| 41 | + goto_model(_goto_model), |
| 42 | + message_handler(_msg) |
| 43 | + { |
| 44 | + start_function = goto_model.goto_functions.entry_point(); |
| 45 | + call_depth = 0; |
| 46 | + call_grapht undirected_call_graph = |
| 47 | + call_grapht::create_from_root_function(goto_model, start_function, false); |
| 48 | + call_graph = undirected_call_graph.get_directed_graph(); |
| 49 | + } |
| 50 | + |
| 51 | + /// \brief Removes the body of all functions except those on the |
| 52 | + /// shortest path or functions |
| 53 | + /// that are reachable from functions on the shortest path within |
| 54 | + /// N calls, where N is given by the parameter "distance" |
| 55 | + void doit(); |
| 56 | + |
| 57 | + /// \brief Adds a list of functions to the set of functions for the aggressive |
| 58 | + /// slicer to preserve |
| 59 | + /// \param function_list: a list of functions in form |
| 60 | + /// std::list<std::string>, as returned by get_cmdline_option. |
| 61 | + void preserve_functions(const std::list<std::string> &function_list) |
| 62 | + { |
| 63 | + for(const auto &f : function_list) |
| 64 | + functions_to_keep.insert(f); |
| 65 | + }; |
| 66 | + |
| 67 | + std::list<std::string> user_specified_properties; |
| 68 | + std::size_t call_depth; |
| 69 | + std::list<std::string> name_snippets; |
| 70 | + bool preserve_all_direct_paths; |
| 71 | + |
| 72 | +private: |
| 73 | + irep_idt start_function; |
| 74 | + goto_modelt &goto_model; |
| 75 | + message_handlert &message_handler; |
| 76 | + std::set<irep_idt> functions_to_keep; |
| 77 | + call_grapht::directed_grapht call_graph; |
| 78 | + |
| 79 | + /// \brief Finds all functions whose name contains a name snippet |
| 80 | + /// and adds them to the std::unordered_set of irep_idts of functions |
| 81 | + /// for the aggressive slicer to preserve |
| 82 | + void find_functions_that_contain_name_snippet(); |
| 83 | + |
| 84 | + /// \brief notes functions to keep in the slice based on the program |
| 85 | + /// start function and the given destination function. Functions are noted |
| 86 | + /// according to the configuration parameters set in the aggressive |
| 87 | + /// slicer, i.e., shortest path between two functions, or all direct paths. |
| 88 | + /// Inserts functions to preserve into the functions_to_keep set |
| 89 | + /// \param destination_function name of destination function for slice |
| 90 | + void note_functions_to_keep(irep_idt destination_function); |
| 91 | + |
| 92 | + /// \brief Finds all functions that contain a property, |
| 93 | + /// and adds them to the list of functions to keep. This |
| 94 | + /// function is only called if no properties are given by the user. |
| 95 | + /// This behaviour mirrors the behaviour of the other program |
| 96 | + /// slicers (reachability, global, full) |
| 97 | + void get_all_functions_containing_properties(); |
| 98 | +}; |
| 99 | + |
| 100 | +#endif /* CPROVER_GOTO_INSTRUMENT_AGGRESSIVE_SLICER_H */ |
0 commit comments