P4C
The P4 Compiler
Loading...
Searching...
No Matches
lib/concolic.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_CONCOLIC_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_CONCOLIC_H_
3
4#include <sys/types.h>
5
6#include <functional>
7#include <list>
8#include <tuple>
9#include <utility>
10#include <variant>
11#include <vector>
12
13#include "backends/p4tools/common/lib/model.h"
14#include "ir/ir.h"
15#include "ir/vector.h"
16#include "ir/visitor.h"
17#include "lib/cstring.h"
18#include "lib/ordered_map.h"
19
20#include "backends/p4tools/modules/testgen/lib/execution_state.h"
21
22namespace P4::P4Tools::P4Testgen {
23
29using ConcolicVariableMap =
30 ordered_map<std::variant<IR::ConcolicVariable, const IR::Expression *>, const IR::Expression *>;
31
34 private:
35 using MethodImpl = std::function<void(
36 cstring concolicMethodName, const IR::ConcolicVariable *var, const ExecutionState &state,
37 const Model &evaluatedModel, ConcolicVariableMap *resolvedConcolicVariables)>;
38
40 impls;
41
42 static bool matches(const std::vector<cstring> &paramNames,
43 const IR::Vector<IR::Argument> *args);
44
45 public:
46 using ImplList = std::list<std::tuple<cstring, std::vector<cstring>, MethodImpl>>;
47
48 explicit ConcolicMethodImpls(const ImplList &implList);
49
50 bool exec(cstring concolicMethodName, const IR::ConcolicVariable *var,
51 const ExecutionState &state, const Model &evaluatedModel,
52 ConcolicVariableMap *resolvedConcolicVariables) const;
53
54 void add(const ImplList &implList);
55};
56
58 public:
59 explicit ConcolicResolver(const Model &evaluatedModel, const ExecutionState &state,
60 const ConcolicMethodImpls &concolicMethodImpls);
61
62 ConcolicResolver(const Model &evaluatedModel, const ExecutionState &state,
63 const ConcolicMethodImpls &concolicMethodImpls,
64 ConcolicVariableMap resolvedConcolicVariables);
65
66 const ConcolicVariableMap *getResolvedConcolicVariables() const;
67
68 private:
69 bool preorder(const IR::ConcolicVariable *var) override;
70
72 const ExecutionState &state;
73
75 const Model &evaluatedModel;
76
79 ConcolicVariableMap resolvedConcolicVariables;
80
83 const ConcolicMethodImpls &concolicMethodImpls;
84};
85
86class Concolic {
87 public:
88 static const ConcolicMethodImpls::ImplList *getCoreConcolicMethodImpls();
89};
90
91} // namespace P4::P4Tools::P4Testgen
92
93#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_CONCOLIC_H_ */
Definition vector.h:59
Definition visitor.h:400
Definition backends/p4tools/common/lib/model.h:19
Definition lib/concolic.h:86
Encapsulates a set of concolic method implementations.
Definition lib/concolic.h:33
Definition lib/concolic.h:57
Represents state of execution after having reached a program point.
Definition execution_state.h:34
Definition cstring.h:85