18
18
#include " phasar/DataFlow/IfdsIde/IFDSIDESolverConfig.h"
19
19
#include " phasar/DataFlow/IfdsIde/InitialSeeds.h"
20
20
#include " phasar/DataFlow/IfdsIde/Solver/GenericSolverResults.h"
21
- #include " phasar/DataFlow/IfdsIde/SolverResults .h"
21
+ #include " phasar/Utils/DefaultAnalysisPrinterSelector .h"
22
22
#include " phasar/Utils/JoinLattice.h"
23
+ #include " phasar/Utils/Macros.h"
24
+ #include " phasar/Utils/MaybeUniquePtr.h"
23
25
#include " phasar/Utils/NullAnalysisPrinter.h"
24
26
#include " phasar/Utils/SemiRing.h"
25
27
#include " phasar/Utils/Soundness.h"
26
28
29
+ #include " llvm/Support/raw_ostream.h"
30
+
27
31
#include < cassert>
32
+ #include < memory>
28
33
#include < optional>
29
34
#include < set>
30
35
#include < string>
@@ -96,20 +101,28 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
96
101
ZeroValue) noexcept (std::is_nothrow_move_constructible_v<d_t >)
97
102
: IRDB(IRDB), EntryPoints(std::move(EntryPoints)),
98
103
ZeroValue(std::move(ZeroValue)),
99
- Printer(NullAnalysisPrinter<AnalysisDomainTy>::getInstance()) {
104
+ Printer(std::make_unique<typename DefaultAnalysisPrinterSelector<
105
+ AnalysisDomainTy>::type>()) {
100
106
assert (IRDB != nullptr );
101
107
}
102
108
103
- void setAnalysisPrinter (AnalysisPrinterBase<AnalysisDomainTy> *P) {
109
+ IDETabulationProblem (IDETabulationProblem &&) noexcept = default ;
110
+ IDETabulationProblem &operator =(IDETabulationProblem &&) noexcept = default ;
111
+
112
+ IDETabulationProblem (const IDETabulationProblem &) = delete ;
113
+ IDETabulationProblem &operator =(const IDETabulationProblem &) = delete ;
114
+
115
+ ~IDETabulationProblem () override = default ;
116
+
117
+ void
118
+ setAnalysisPrinter (MaybeUniquePtr<AnalysisPrinterBase<AnalysisDomainTy>> P) {
104
119
if (P) {
105
- Printer = P ;
120
+ Printer = std::move (P) ;
106
121
} else {
107
122
Printer = NullAnalysisPrinter<AnalysisDomainTy>::getInstance ();
108
123
}
109
124
}
110
125
111
- ~IDETabulationProblem () override = default ;
112
-
113
126
// / Checks if the given data-flow fact is the special tautological lambda (or
114
127
// / zero) fact.
115
128
[[nodiscard]] virtual bool isZeroValue (d_t FlowFact) const noexcept {
@@ -148,7 +161,7 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
148
161
virtual void
149
162
emitTextReport ([[maybe_unused]] GenericSolverResults<n_t , d_t , l_t > Results,
150
163
llvm::raw_ostream &OS = llvm::outs()) {
151
- OS << " No text report available! \n " ;
164
+ Printer-> onFinalize (OS) ;
152
165
}
153
166
154
167
// / Generates a graphical report, e.g. in html or other markup languages, of
@@ -163,7 +176,9 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
163
176
// / the level of soundness is ignored. Otherwise, true.
164
177
virtual bool setSoundness (Soundness /* S*/ ) { return false ; }
165
178
166
- const ProjectIRDBBase<db_t > *getProjectIRDB () const noexcept { return IRDB; }
179
+ [[nodiscard]] const ProjectIRDBBase<db_t > *getProjectIRDB () const noexcept {
180
+ return IRDB;
181
+ }
167
182
168
183
protected:
169
184
typename FlowFunctions<AnalysisDomainTy, Container>::FlowFunctionPtrType
@@ -172,6 +187,19 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
172
187
std::move (FactToGenerate), getZeroValue ());
173
188
}
174
189
190
+ template <typename D = d_t , typename L = l_t >
191
+ void onResult (n_t Instr, D &&DfFact, L &&LatticeElement,
192
+ DataFlowAnalysisType AnalysisType) {
193
+ Printer->onResult (Instr, PSR_FWD (DfFact), PSR_FWD (LatticeElement),
194
+ AnalysisType);
195
+ }
196
+
197
+ template <typename D = d_t , typename L = l_t >
198
+ std::enable_if_t <std::is_same_v<L, psr::BinaryDomain>>
199
+ onResult (n_t Instr, D &&DfFact, DataFlowAnalysisType AnalysisType) {
200
+ Printer->onResult (Instr, PSR_FWD (DfFact), AnalysisType);
201
+ }
202
+
175
203
// / Seeds that just start with ZeroValue and bottomElement() at the starting
176
204
// / points of each EntryPoint function.
177
205
// / Takes the __ALL__ EntryPoint into account.
@@ -196,7 +224,7 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
196
224
197
225
[[maybe_unused]] Soundness SF = Soundness::Soundy;
198
226
199
- AnalysisPrinterBase<AnalysisDomainTy> * Printer;
227
+ MaybeUniquePtr< AnalysisPrinterBase<AnalysisDomainTy>> Printer;
200
228
};
201
229
202
230
} // namespace psr
0 commit comments