|
18 | 18 | #define PHASAR_DATAFLOW_MONO_SOLVER_INTRAMONOSOLVER_H |
19 | 19 |
|
20 | 20 | #include "phasar/DataFlow/Mono/IntraMonoProblem.h" |
21 | | -#include "phasar/Utils/BitVectorSet.h" |
| 21 | +#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" |
| 22 | +#include "phasar/Utils/DefaultValue.h" |
| 23 | +#include "phasar/Utils/Utilities.h" |
22 | 24 |
|
23 | 25 | #include <deque> |
24 | 26 | #include <unordered_map> |
@@ -109,20 +111,47 @@ template <typename AnalysisDomainTy> class IntraMonoSolver { |
109 | 111 | } |
110 | 112 | } |
111 | 113 |
|
112 | | - mono_container_t getResultsAt(n_t Stmt) { return Analysis[Stmt]; } |
| 114 | + [[nodiscard]] const mono_container_t &getResultsAt(n_t Stmt) const { |
| 115 | + auto It = Analysis.find(Stmt); |
| 116 | + if (It != Analysis.end()) { |
| 117 | + return It->second; |
| 118 | + } |
| 119 | + return getDefaultValue<mono_container_t>(); |
| 120 | + } |
113 | 121 |
|
114 | 122 | virtual void dumpResults(llvm::raw_ostream &OS = llvm::outs()) { |
115 | | - OS << "Intra-Monotone solver results:\n" |
116 | | - "------------------------------\n"; |
117 | | - for (auto &[Node, FlowFacts] : this->Analysis) { |
118 | | - OS << "Instruction:\n" << NToString(Node); |
119 | | - OS << "\nFacts:\n"; |
| 123 | + OS << "\n***************************************************************\n" |
| 124 | + << "* Raw IntraMonoSolver results *\n" |
| 125 | + << "***************************************************************\n"; |
| 126 | + |
| 127 | + if (Analysis.empty()) { |
| 128 | + OS << "No results computed!" << '\n'; |
| 129 | + return; |
| 130 | + } |
| 131 | + |
| 132 | + std::vector<std::pair<n_t, mono_container_t>> Cells; |
| 133 | + Cells.reserve(Analysis.size()); |
| 134 | + Cells.insert(Cells.end(), Analysis.begin(), Analysis.end()); |
| 135 | + |
| 136 | + std::sort(Cells.begin(), Cells.end(), [](const auto &Lhs, const auto &Rhs) { |
| 137 | + if constexpr (std::is_same_v<n_t, const llvm::Instruction *>) { |
| 138 | + return StringIDLess{}(getMetaDataID(Lhs.first), |
| 139 | + getMetaDataID(Rhs.first)); |
| 140 | + } else { |
| 141 | + // If non-LLVM IR is used |
| 142 | + return Lhs.first < Rhs.first; |
| 143 | + } |
| 144 | + }); |
| 145 | + |
| 146 | + for (const auto &[Node, FlowFacts] : Cells) { |
| 147 | + OS << "Instruction: " << NToString(Node); |
| 148 | + OS << "\nFacts: "; |
120 | 149 | if (FlowFacts.empty()) { |
121 | | - OS << "\tEMPTY\n"; |
| 150 | + OS << "EMPTY\n"; |
122 | 151 | } else { |
123 | 152 | IMProblem.printContainer(OS, FlowFacts); |
124 | 153 | } |
125 | | - OS << "\n\n"; |
| 154 | + OS << "\n"; |
126 | 155 | } |
127 | 156 | } |
128 | 157 |
|
|
0 commit comments