Skip to content

Commit 98a9ce0

Browse files
committed
Get rid of the dependency phasar_phasarllvm_utils -> phasar_db, such that phasar_db can safely refer to phasar_phasarllvm_utils
1 parent e33d633 commit 98a9ce0

7 files changed

Lines changed: 50 additions & 51 deletions

File tree

include/phasar/DB/ProjectIRDB.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ class ProjectIRDB {
229229
persistedStringToValue(const std::string &StringRep) const;
230230
};
231231

232+
/**
233+
* Revserses the getMetaDataID function
234+
*/
235+
const llvm::Value *fromMetaDataId(const ProjectIRDB &IRDB, llvm::StringRef Id);
236+
232237
} // namespace psr
233238

234239
#endif

include/phasar/PhasarLLVM/Utils/BasicBlockOrdering.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "llvm/ADT/DenseMap.h"
1717
#include "llvm/ADT/FunctionExtras.h"
1818

19-
#include "phasar/DB/ProjectIRDB.h"
20-
2119
namespace llvm {
2220
class Function;
2321
class BasicBlock;

include/phasar/PhasarLLVM/Utils/LLVMShorthands.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "llvm/IR/ModuleSlotTracker.h"
2626
#include "llvm/IR/Value.h"
2727

28-
#include "phasar/DB/ProjectIRDB.h"
2928
#include "phasar/Utils/Utilities.h"
3029

3130
namespace psr {
@@ -95,11 +94,6 @@ globalValuesUsedinFunction(const llvm::Function *F);
9594
*/
9695
std::string getMetaDataID(const llvm::Value *V);
9796

98-
/**
99-
* Revserses the getMetaDataID function
100-
*/
101-
const llvm::Value *fromMetaDataId(const ProjectIRDB &IRDB, llvm::StringRef Id);
102-
10397
/**
10498
* @brief Does less-than comparison based on the annotated ID.
10599
*

lib/DB/ProjectIRDB.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <algorithm>
1111
#include <cassert>
12+
#include <charconv>
1213
#include <filesystem>
1314
#include <ostream>
1415
#include <string>
@@ -551,3 +552,44 @@ bool ProjectIRDB::debugInfoAvailable() const {
551552
}
552553

553554
} // namespace psr
555+
556+
const llvm::Value *psr::fromMetaDataId(const ProjectIRDB &IRDB,
557+
llvm::StringRef Id) {
558+
if (Id.empty() || Id[0] == '-') {
559+
return nullptr;
560+
}
561+
562+
auto ParseInt = [](llvm::StringRef Str) -> std::optional<unsigned> {
563+
unsigned Num;
564+
auto [Ptr, EC] = std::from_chars(Str.data(), Str.data() + Str.size(), Num);
565+
566+
if (EC == std::errc{}) {
567+
return Num;
568+
}
569+
570+
PHASAR_LOG_LEVEL(WARNING, "Invalid metadata id '"
571+
<< Str.str() << "': "
572+
<< std::make_error_code(EC).message());
573+
return std::nullopt;
574+
};
575+
576+
if (auto Dot = Id.find('.'); Dot != llvm::StringRef::npos) {
577+
auto FName = Id.slice(0, Dot);
578+
579+
auto ArgNr = ParseInt(Id.drop_front(Dot + 1));
580+
581+
if (!ArgNr) {
582+
return nullptr;
583+
}
584+
585+
const auto *F = IRDB.getFunction(FName);
586+
if (F) {
587+
return getNthFunctionArgument(F, *ArgNr);
588+
}
589+
590+
return nullptr;
591+
}
592+
593+
auto IdNr = ParseInt(Id);
594+
return IdNr ? IRDB.getInstruction(*IdNr) : nullptr;
595+
}

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/EdgeDomain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
* Fabian Schiebel and others
88
*****************************************************************************/
99

10-
#include "llvm/Support/raw_os_ostream.h"
11-
1210
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/EdgeDomain.h"
1311
#include "phasar/PhasarLLVM/Utils/BasicBlockOrdering.h"
1412
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
1513

14+
#include "llvm/ADT/SmallPtrSet.h"
15+
#include "llvm/Support/raw_os_ostream.h"
16+
1617
namespace psr::XTaint {
1718

1819
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const EdgeDomain &ED) {

lib/PhasarLLVM/Utils/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ file(GLOB_RECURSE UTILS_SRC *.h *.cpp)
33
set(PHASAR_LINK_LIBS
44
phasar_config
55
phasar_utils
6-
phasar_db
76
)
87

98
set(LLVM_LINK_COMPONENTS

lib/PhasarLLVM/Utils/LLVMShorthands.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -250,46 +250,6 @@ std::string getMetaDataID(const llvm::Value *V) {
250250
return "-1";
251251
}
252252

253-
const llvm::Value *fromMetaDataId(const ProjectIRDB &IRDB, llvm::StringRef Id) {
254-
if (Id.empty() || Id[0] == '-') {
255-
return nullptr;
256-
}
257-
258-
auto ParseInt = [](llvm::StringRef Str) -> std::optional<unsigned> {
259-
unsigned Num;
260-
auto [Ptr, EC] = std::from_chars(Str.data(), Str.data() + Str.size(), Num);
261-
262-
if (EC == std::errc{}) {
263-
return Num;
264-
}
265-
266-
PHASAR_LOG_LEVEL(WARNING, "Invalid metadata id '"
267-
<< Str.str() << "': "
268-
<< std::make_error_code(EC).message());
269-
return std::nullopt;
270-
};
271-
272-
if (auto Dot = Id.find('.'); Dot != llvm::StringRef::npos) {
273-
auto FName = Id.slice(0, Dot);
274-
275-
auto ArgNr = ParseInt(Id.drop_front(Dot + 1));
276-
277-
if (!ArgNr) {
278-
return nullptr;
279-
}
280-
281-
const auto *F = IRDB.getFunction(FName);
282-
if (F) {
283-
return getNthFunctionArgument(F, *ArgNr);
284-
}
285-
286-
return nullptr;
287-
}
288-
289-
auto IdNr = ParseInt(Id);
290-
return IdNr ? IRDB.getInstruction(*IdNr) : nullptr;
291-
}
292-
293253
bool LLVMValueIDLess::operator()(const llvm::Value *Lhs,
294254
const llvm::Value *Rhs) const {
295255
std::string LhsId = getMetaDataID(Lhs);

0 commit comments

Comments
 (0)