forked from secure-software-engineering/phasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6741866
commit 1cc8a26
Showing
2 changed files
with
33 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "phasar/PhasarLLVM/Utils/SourceMgrPrinter.h" | ||
|
||
#include <llvm/Support/SourceMgr.h> | ||
|
||
namespace psr { | ||
|
||
llvm::StringMap<unsigned> FileNameIDMap{}; | ||
llvm::SourceMgr SrcMgr{}; | ||
|
||
std::optional<unsigned> getSourceBufId(llvm::StringRef FileName) { | ||
if (auto It = FileNameIDMap.find(FileName); It != FileNameIDMap.end()) { | ||
return It->second; | ||
} | ||
|
||
auto Buf = llvm::MemoryBuffer::getFile(FileName, true); | ||
if (!Buf) { | ||
PHASAR_LOG_LEVEL(WARNING, "File not accessible: " << FileName); | ||
return std::nullopt; | ||
} | ||
|
||
auto Id = SrcMgr.AddNewSourceBuffer(std::move(Buf.get()), llvm::SMLoc{}); | ||
FileNameIDMap.try_emplace(FileName, Id); | ||
return Id; | ||
} | ||
} // namespace psr |