CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
path_storage.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Path Storage
4
5Author: Kareem Khazem <karkhaz@karkhaz.com>
6
7\*******************************************************************/
8
9#include "path_storage.h"
10
11#include <sstream>
12
13#include <util/cmdline.h>
14#include <util/exit_codes.h>
15
17operator()(typet type, source_locationt location)
18{
19 return nondet_symbol_exprt{"symex::nondet" + std::to_string(nondet_count++),
20 std::move(type),
21 std::move(location)};
22}
23
24// _____________________________________________________________________________
25// path_lifot
26
28{
29 last_peeked = paths.end();
31 return paths.back();
32}
33
35{
36 paths.push_back(path);
37}
38
40{
42 paths.erase(last_peeked);
43 last_peeked = paths.end();
44}
45
46std::size_t path_lifot::size() const
47{
48 return paths.size();
49}
50
52{
53 paths.clear();
54}
55
56// _____________________________________________________________________________
57// path_fifot
58
63
65{
66 paths.push_back(path);
67}
68
70{
71 paths.pop_front();
72}
73
74std::size_t path_fifot::size() const
75{
76 return paths.size();
77}
78
80{
81 paths.clear();
82}
83
84// _____________________________________________________________________________
85// path_strategy_choosert
86
87static const std::map<
88 const std::string,
89 std::pair<
90 const std::string,
91 const std::function<std::unique_ptr<path_storaget>()>>>
93 {{"lifo",
94 {" lifo next instruction is pushed before\n"
95 " goto target; paths are popped in\n"
96 " last-in, first-out order. Explores\n"
97 " the program tree depth-first.\n",
98 []() { // NOLINT(whitespace/braces)
99 return std::make_unique<path_lifot>();
100 }}},
101 {"fifo",
102 {" fifo next instruction is pushed before\n"
103 " goto target; paths are popped in\n"
104 " first-in, first-out order. Explores\n"
105 " the program tree breadth-first.\n",
106 []() { // NOLINT(whitespace/braces)
107 return std::make_unique<path_fifot>();
108 }}}});
109
111{
112 std::stringstream ss;
113 for(auto &pair : path_strategies)
114 ss << pair.second.first;
115 return ss.str();
116}
117
119{
120 return "lifo";
121}
122
123bool is_valid_path_strategy(const std::string strategy)
124{
125 return path_strategies.find(strategy) != path_strategies.end();
126}
127
128std::unique_ptr<path_storaget> get_path_strategy(const std::string strategy)
129{
130 auto found = path_strategies.find(strategy);
131 INVARIANT(
132 found != path_strategies.end(), "Unknown strategy '" + strategy + "'.");
133 return found->second.second();
134}
135
137 const cmdlinet &cmdline,
138 optionst &options,
139 message_handlert &message_handler)
140{
141 messaget log(message_handler);
142 if(cmdline.isset("paths"))
143 {
144 options.set_option("paths", true);
145 std::string strategy = cmdline.get_value("paths");
147 {
148 log.error() << "Unknown strategy '" << strategy
149 << "'. Pass the --show-symex-strategies flag to list "
150 "available strategies."
151 << messaget::eom;
153 }
154 options.set_option("exploration-strategy", strategy);
155 }
156 else
157 {
158 options.set_option("exploration-strategy", default_path_strategy());
159 }
160}
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::string get_value(char option) const
Definition cmdline.cpp:48
virtual bool isset(char option) const
Definition cmdline.cpp:30
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
static eomt eom
Definition message.h:289
Expression to hold a nondeterministic choice.
Definition std_expr.h:292
void set_option(const std::string &option, const bool value)
Definition options.cpp:28
void clear() override
Clear all saved paths.
void private_pop() override
patht & private_peek() override
std::list< patht > paths
void push(const patht &) override
Add a path to resume to the storage.
std::size_t size() const override
How many paths does this storage contain?
std::list< patht > paths
void private_pop() override
std::list< path_storaget::patht >::iterator last_peeked
void push(const patht &) override
Add a path to resume to the storage.
patht & private_peek() override
std::size_t size() const override
How many paths does this storage contain?
void clear() override
Clear all saved paths.
nondet_symbol_exprt operator()(typet type, source_locationt location)
The type of an expression, extends irept.
Definition type.h:29
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_USAGE_ERROR
A usage error is returned when the command line is invalid or conflicting.
Definition exit_codes.h:33
double log(double x)
Definition math.c:2449
std::string default_path_strategy()
static const std::map< const std::string, std::pair< const std::string, const std::function< std::unique_ptr< path_storaget >()> > > path_strategies({{"lifo", {" lifo next instruction is pushed before\n" " goto target; paths are popped in\n" " last-in, first-out order. Explores\n" " the program tree depth-first.\n", []() { return std::make_unique< path_lifot >();}}}, {"fifo", {" fifo next instruction is pushed before\n" " goto target; paths are popped in\n" " first-in, first-out order. Explores\n" " the program tree breadth-first.\n", []() { return std::make_unique< path_fifot >();}}}})
std::unique_ptr< path_storaget > get_path_strategy(const std::string strategy)
Ensure that is_valid_strategy() returns true for a particular string before calling this function on ...
void parse_path_strategy_options(const cmdlinet &cmdline, optionst &options, message_handlert &message_handler)
add paths and exploration-strategy option, suitable to be invoked from front-ends.
bool is_valid_path_strategy(const std::string strategy)
is there a factory constructor for the named strategy?
std::string show_path_strategies()
suitable for displaying as a front-end help message
Storage of symbolic execution paths to resume.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
void exit(int status)
Definition stdlib.c:102
Information saved at a conditional goto to resume execution.