1010#ifndef PHASAR_CONTROLLER_ANALYSISCONTROLLER_H
1111#define PHASAR_CONTROLLER_ANALYSISCONTROLLER_H
1212
13+ #include " phasar/Controller/AnalysisControllerEmitterOptions.h"
1314#include " phasar/DB/LLVMProjectIRDB.h"
15+ #include " phasar/PhasarLLVM/AnalysisStrategy/HelperAnalyses.h"
1416#include " phasar/PhasarLLVM/AnalysisStrategy/Strategies.h"
15- #include " phasar/PhasarLLVM/AnalysisStrategy/WholeProgramAnalysis.h"
1617#include " phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
17- #include " phasar/PhasarLLVM/ControlFlow/Resolver/CallGraphAnalysisType.h"
1818#include " phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h"
1919#include " phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h"
2020#include " phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IFDSSolver.h"
21+ #include " phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/SolverResults.h"
2122#include " phasar/PhasarLLVM/DataFlowSolver/Mono/Solver/InterMonoSolver.h"
2223#include " phasar/PhasarLLVM/DataFlowSolver/Mono/Solver/IntraMonoSolver.h"
2324#include " phasar/PhasarLLVM/Pointer/LLVMBasedPointsToAnalysis.h"
3536
3637namespace psr {
3738
38- enum class AnalysisControllerEmitterOptions : uint32_t {
39- None = 0 ,
40- EmitIR = (1 << 0 ),
41- EmitRawResults = (1 << 1 ),
42- EmitTextReport = (1 << 2 ),
43- EmitGraphicalReport = (1 << 3 ),
44- EmitESGAsDot = (1 << 4 ),
45- EmitTHAsText = (1 << 5 ),
46- EmitTHAsDot = (1 << 6 ),
47- EmitTHAsJson = (1 << 7 ),
48- // EmitCGAsText = (1 << 8),
49- EmitCGAsDot = (1 << 9 ),
50- // EmitCGAsJson = (1 << 10),
51- EmitPTAAsText = (1 << 11 ),
52- EmitPTAAsDot = (1 << 12 ),
53- EmitPTAAsJson = (1 << 13 ),
54- EmitStatisticsAsJson = (1 << 14 ),
55- };
56-
5739class AnalysisController {
5840private:
59- LLVMProjectIRDB &IRDB;
60- LLVMTypeHierarchy TH;
61- LLVMPointsToSet PT;
62- LLVMBasedICFG ICF;
41+ HelperAnalyses &HA;
6342 std::vector<DataFlowAnalysisType> DataFlowAnalyses;
6443 std::vector<std::string> AnalysisConfigs;
6544 std::vector<std::string> EntryPoints;
@@ -69,8 +48,6 @@ class AnalysisController {
6948 std::string ProjectID;
7049 std::filesystem::path ResultDirectory;
7150 IFDSIDESolverConfig SolverConfig;
72- [[maybe_unused]] Soundness SoundnessLevel;
73- [[maybe_unused]] bool AutoGlobalSupport;
7451
7552 // /
7653 // / \brief The maximum length of the CallStrings used in the InterMonoSolver
@@ -106,79 +83,64 @@ class AnalysisController {
10683 void executeInterMonoSolverTest ();
10784 void executeInterMonoTaint ();
10885
109- template <typename AnalysisTy, bool WithConfig = false >
110- void executeIntraMonoAnalysis () {
111- executeAnalysis<IntraMonoSolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
86+ template <typename ProblemTy>
87+ void executeIntraMonoAnalysis (ProblemTy &Problem) {
88+ IntraMonoSolver Solver (Problem);
89+ Solver.solve ();
90+ emitRequestedDataFlowResults (Solver);
11291 }
11392
114- template <typename AnalysisTy, bool WithConfig = false >
115- void executeInterMonoAnalysis () {
116- executeAnalysis<InterMonoSolver_P<AnalysisTy, 3 >, AnalysisTy, WithConfig>();
93+ template <typename ProblemTy>
94+ void executeInterMonoAnalysis (ProblemTy &Problem) {
95+ InterMonoSolver_P<ProblemTy, 3 > Solver (Problem);
96+ Solver.solve ();
97+ emitRequestedDataFlowResults (Solver);
11798 }
11899
119- template <typename AnalysisTy, bool WithConfig = false >
120- void executeIFDSAnalysis () {
121- executeAnalysis<IFDSSolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
100+ template <typename ProblemTy> void executeIFDSAnalysis (ProblemTy &Problem) {
101+ IFDSSolver Solver (Problem, &HA.getICFG ());
102+ Solver.solve ();
103+ emitRequestedDataFlowResults (Solver);
122104 }
123105
124- template <typename AnalysisTy, bool WithConfig = false >
125- void executeIDEAnalysis () {
126- executeAnalysis<IDESolver_P<AnalysisTy>, AnalysisTy, WithConfig>();
106+ template <typename ProblemTy> void executeIDEAnalysis (ProblemTy &Problem) {
107+ IDESolver Solver (Problem, &HA.getICFG ());
108+ Solver.solve ();
109+ emitRequestedDataFlowResults (Solver);
127110 }
128111
129- template <class Solver_P , typename AnalysisTy, bool WithConfig>
130- void executeAnalysis () {
131- if constexpr (WithConfig) {
132- std::string AnalysisConfigPath =
133- !AnalysisConfigs.empty () ? AnalysisConfigs[0 ] : " " ;
134- auto Config =
135- !AnalysisConfigPath.empty ()
136- ? TaintConfig (IRDB, parseTaintConfig (AnalysisConfigPath))
137- : TaintConfig (IRDB);
138- WholeProgramAnalysis<Solver_P, AnalysisTy> WPA (
139- SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
140- WPA.solve ();
141- emitRequestedDataFlowResults (WPA);
142- WPA.releaseAllHelperAnalyses ();
143- } else {
144- WholeProgramAnalysis<Solver_P, AnalysisTy> WPA (
145- SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
146- WPA.solve ();
147- emitRequestedDataFlowResults (WPA);
148- WPA.releaseAllHelperAnalyses ();
149- }
150- }
112+ TaintConfig makeTaintConfig ();
151113
152- template <typename T> void emitRequestedDataFlowResults (T &WPA ) {
114+ template <typename T> void emitRequestedDataFlowResults (T &Solver ) {
153115 if (EmitterOptions & AnalysisControllerEmitterOptions::EmitTextReport) {
154116 if (!ResultDirectory.empty ()) {
155117 if (auto OFS =
156118 openFileStream (ResultDirectory.string () + " /psr-report.txt" )) {
157- WPA .emitTextReport (*OFS);
119+ Solver .emitTextReport (*OFS);
158120 }
159121 } else {
160- WPA .emitTextReport (llvm::outs ());
122+ Solver .emitTextReport (llvm::outs ());
161123 }
162124 }
163125 if (EmitterOptions &
164126 AnalysisControllerEmitterOptions::EmitGraphicalReport) {
165127 if (!ResultDirectory.empty ()) {
166128 if (auto OFS =
167129 openFileStream (ResultDirectory.string () + " /psr-report.html" )) {
168- WPA .emitGraphicalReport (*OFS);
130+ Solver .emitGraphicalReport (*OFS);
169131 }
170132 } else {
171- WPA .emitGraphicalReport (llvm::outs ());
133+ Solver .emitGraphicalReport (llvm::outs ());
172134 }
173135 }
174136 if (EmitterOptions & AnalysisControllerEmitterOptions::EmitRawResults) {
175137 if (!ResultDirectory.empty ()) {
176138 if (auto OFS = openFileStream (ResultDirectory.string () +
177139 " /psr-raw-results.txt" )) {
178- WPA .dumpResults (*OFS);
140+ Solver .dumpResults (*OFS);
179141 }
180142 } else {
181- WPA .dumpResults (llvm::outs ());
143+ Solver .dumpResults (llvm::outs ());
182144 }
183145 }
184146 if (EmitterOptions & AnalysisControllerEmitterOptions::EmitESGAsDot) {
@@ -188,18 +150,14 @@ class AnalysisController {
188150 }
189151
190152public:
191- AnalysisController (LLVMProjectIRDB &IRDB,
192- std::vector<DataFlowAnalysisType> DataFlowAnalyses,
193- std::vector<std::string> AnalysisConfigs,
194- PointerAnalysisType PTATy, CallGraphAnalysisType CGTy,
195- Soundness SoundnessLevel, bool AutoGlobalSupport,
196- std::vector<std::string> EntryPoints,
197- AnalysisStrategy Strategy,
198- AnalysisControllerEmitterOptions EmitterOptions,
199- IFDSIDESolverConfig SolverConfig,
200- const std::string &ProjectID = " default-phasar-project" ,
201- std::filesystem::path OutDirectory = {},
202- const nlohmann::json &PrecomputedPointsToInfo = {});
153+ explicit AnalysisController (
154+ HelperAnalyses &HA, std::vector<DataFlowAnalysisType> DataFlowAnalyses,
155+ std::vector<std::string> AnalysisConfigs,
156+ std::vector<std::string> EntryPoints, AnalysisStrategy Strategy,
157+ AnalysisControllerEmitterOptions EmitterOptions,
158+ IFDSIDESolverConfig SolverConfig,
159+ const std::string &ProjectID = " default-phasar-project" ,
160+ const std::string &OutDirectory = " " );
203161
204162 ~AnalysisController () = default ;
205163
@@ -209,6 +167,13 @@ class AnalysisController {
209167 AnalysisController &operator =(const AnalysisController &&) = delete ;
210168
211169 void executeAs (AnalysisStrategy Strategy);
170+
171+ static constexpr bool
172+ needsToEmitPTA (AnalysisControllerEmitterOptions EmitterOptions) {
173+ return (EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsDot) ||
174+ (EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsJson) ||
175+ (EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsText);
176+ }
212177};
213178
214179} // namespace psr
0 commit comments