Skip to content

Commit

Permalink
adding TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
sritejakv committed Feb 9, 2024
1 parent 1369499 commit 29e7b8a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions include/phasar/PhasarLLVM/Utils/SourceMgrPrinter.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
#ifndef PHASAR_PHASARLLVM_UTILS_SOURCEMGRPRINTER_H
#define PHASAR_PHASARLLVM_UTILS_SOURCEMGRPRINTER_H
#include "phasar/PhasarLLVM/Utils/AnalysisPrinterBase.h"
#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"
#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h"
#include "phasar/PhasarLLVM/Utils/OnTheFlyAnalysisPrinter.h"
#include "phasar/Utils/AnalysisPrinterBase.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/MaybeUniquePtr.h"

#include "llvm/ADT/FunctionExtras.h"
#include "llvm/Support/MemoryBuffer.h"

#include <llvm/ADT/StringMap.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/raw_ostream.h> // quoting style

namespace psr {
template <typename AnalysisDomainTy>
class SourceMgrPrinter : public AnalysisPrinterBase<AnalysisDomainTy> {
public:
SourceMgrPrinter() = default;
SourceMgrPrinter<AnalysisDomainTy>(llvm::raw_ostream &OS) : OS(&OS){};
SourceMgrPrinter(
llvm::unique_function<std::string(DataFlowAnalysisType)> &&PrintMessage,
llvm::raw_ostream &OS = llvm::errs())
: GetPrintMessage(std::move(PrintMessage)), OS(&OS) {}

void onInitialize() override {}
void onFinalize() const override{};
void onFinalize() override {}
void onResult(Warning<AnalysisDomainTy> Warn) override {
auto BufIdOpt = getSourceBufId(getFilePathFromIR(Warn.Instr));
if (BufIdOpt.has_value()) {
SrcMgr.PrintMessage(
*OS,
SrcMgr.FindLocForLineAndColumn(
BufIdOpt.value(), getLineAndColFromIR(Warn.Instr).first,
getLineAndColFromIR(Warn.Instr).second),
llvm::SourceMgr::DK_Warning,
toString(Warn.AnalysisType) + " Analysis found an error");
/// TODO: getLineAndColFromIR call only once
/// TODO:Configuration options for warning or error
SrcMgr.PrintMessage(*OS,
SrcMgr.FindLocForLineAndColumn(
BufIdOpt.value(),
getLineAndColFromIR(Warn.Instr).first,
getLineAndColFromIR(Warn.Instr).second),
llvm::SourceMgr::DK_Warning,

GetPrintMessage(Warn.AnalysisType));
}
}

/// TODO: use non-virtual function to call virtual function with default
/// parameters +
/// TODO: templace magic - #include "memory_resource"

/// TODO: move this to cpp file and refactor the imports
std::optional<unsigned> getSourceBufId(llvm::StringRef FileName) {
if (auto It = FileNameIDMap.find(FileName); It != FileNameIDMap.end()) {
return It->second;
Expand All @@ -53,8 +63,9 @@ class SourceMgrPrinter : public AnalysisPrinterBase<AnalysisDomainTy> {
}

private:
llvm::SourceMgr SrcMgr;
llvm::StringMap<unsigned> FileNameIDMap;
llvm::SourceMgr SrcMgr{};
llvm::StringMap<unsigned> FileNameIDMap{};
llvm::unique_function<std::string(DataFlowAnalysisType)> GetPrintMessage;
MaybeUniquePtr<llvm::raw_ostream> OS = &llvm::errs();
};
} // namespace psr
Expand Down

0 comments on commit 29e7b8a

Please sign in to comment.