Skip to content

Commit

Permalink
Add more constness
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed May 29, 2024
1 parent 993023f commit 8e45bee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
Soundness S = Soundness::Soundy);

[[nodiscard]] LLVMBasedCallGraph
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, Resolver &CGResolver,
buildLLVMBasedCallGraph(const LLVMProjectIRDB &IRDB, Resolver &CGResolver,
llvm::ArrayRef<const llvm::Function *> EntryPoints,
Soundness S = Soundness::Soundy);

Expand All @@ -41,7 +41,7 @@ buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
Soundness S = Soundness::Soundy);

[[nodiscard]] LLVMBasedCallGraph
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, Resolver &CGResolver,
buildLLVMBasedCallGraph(const LLVMProjectIRDB &IRDB, Resolver &CGResolver,
llvm::ArrayRef<std::string> EntryPoints,
Soundness S = Soundness::Soundy);
} // namespace psr
Expand Down
15 changes: 11 additions & 4 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Support/raw_ostream.h"

#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"

namespace psr {
class LLVMTypeHierarchy;
Expand Down Expand Up @@ -88,10 +89,16 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
bool IncludeGlobals = true);

/// Creates an ICFG with an already given call-graph
explicit LLVMBasedICFG(CallGraph<n_t, f_t> CG, LLVMProjectIRDB *IRDB);
explicit LLVMBasedICFG(CallGraph<n_t, f_t> CG, const LLVMProjectIRDB *IRDB);

explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB,
explicit LLVMBasedICFG(const LLVMProjectIRDB *IRDB,
const nlohmann::json &SerializedCG);
// To avoid ambiguity with the first ctor (json implicitly converts to
// CallGraphAnalysisType for whatever reason)
explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB,
const nlohmann::json &SerializedCG)
: LLVMBasedICFG(static_cast<const LLVMProjectIRDB *>(IRDB),
SerializedCG) {}

// Deleter of LLVMTypeHierarchy may be unknown here...
~LLVMBasedICFG();
Expand Down Expand Up @@ -124,7 +131,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
}

/// Gets the underlying IRDB
[[nodiscard]] LLVMProjectIRDB *getIRDB() const noexcept { return IRDB; }
[[nodiscard]] const LLVMProjectIRDB *getIRDB() const noexcept { return IRDB; }

/// Returns true, if a function was generated by phasar.
[[nodiscard]] static bool
Expand Down Expand Up @@ -164,7 +171,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
// ---

LLVMBasedCallGraph CG;
LLVMProjectIRDB *IRDB = nullptr;
const LLVMProjectIRDB *IRDB = nullptr;
LLVMVFTableProvider VTP;
};

Expand Down
7 changes: 4 additions & 3 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedCallGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace {
using namespace psr;
struct Builder {
LLVMProjectIRDB *IRDB = nullptr;
const LLVMProjectIRDB *IRDB = nullptr;
Resolver *Res = nullptr;
CallGraphBuilder<const llvm::Instruction *, const llvm::Function *>
CGBuilder{};
Expand Down Expand Up @@ -249,7 +249,7 @@ bool Builder::constructDynamicCall(const llvm::Instruction *CS) {
} // namespace

auto psr::buildLLVMBasedCallGraph(
LLVMProjectIRDB &IRDB, Resolver &CGResolver,
const LLVMProjectIRDB &IRDB, Resolver &CGResolver,
llvm::ArrayRef<const llvm::Function *> EntryPoints, Soundness S)
-> LLVMBasedCallGraph {
Builder B{&IRDB, &CGResolver};
Expand Down Expand Up @@ -297,7 +297,8 @@ auto psr::buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB,
return buildLLVMBasedCallGraph(IRDB, CGType, EntryPointFns, TH, VTP, PT, S);
}

auto psr::buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, Resolver &CGResolver,
auto psr::buildLLVMBasedCallGraph(const LLVMProjectIRDB &IRDB,
Resolver &CGResolver,
llvm::ArrayRef<std::string> EntryPoints,
Soundness S) -> LLVMBasedCallGraph {
auto EntryPointFns = getEntryFunctions(IRDB, EntryPoints);
Expand Down
5 changes: 3 additions & 2 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB, Resolver &CGResolver,
initialize(IRDB, CGResolver, EntryPoints, S, IncludeGlobals);
}

LLVMBasedICFG::LLVMBasedICFG(CallGraph<n_t, f_t> CG, LLVMProjectIRDB *IRDB)
LLVMBasedICFG::LLVMBasedICFG(CallGraph<n_t, f_t> CG,
const LLVMProjectIRDB *IRDB)
: CG(std::move(CG)), IRDB(IRDB), VTP(*IRDB) {}

LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB,
LLVMBasedICFG::LLVMBasedICFG(const LLVMProjectIRDB *IRDB,
const nlohmann::json &SerializedCG)
: CG(CallGraph<n_t, f_t>::deserialize(
SerializedCG,
Expand Down

0 comments on commit 8e45bee

Please sign in to comment.