2828#include " llvm/Support/FileSystem.h"
2929#include " llvm/Support/Path.h"
3030
31- #include < algorithm>
3231#include < cstdlib>
3332#include < iterator>
3433#include < system_error>
3534
36- #define XSTR (S ) STR(S)
37- #define STR (S ) #S
38-
3935using namespace psr ;
4036
4137namespace psr {
38+ // / Name of the file storing all glibc function names.
39+ static constexpr llvm::StringLiteral GLIBCFunctionListFileName =
40+ " glibc_function_list_v1-04.05.17.conf" ;
41+
42+ // / Name of the file storing all LLVM intrinsic function names.
43+ static constexpr llvm::StringLiteral LLVMIntrinsicFunctionListFileName =
44+ " llvm_intrinsics_function_list_v1-04.05.17.conf" ;
45+
4246llvm::StringRef PhasarConfig::PhasarVersion () noexcept {
43- return XSTR (PHASAR_VERSION) ;
47+ return PHASAR_VERSION_STRING ;
4448}
4549
4650llvm::StringRef PhasarConfig::GlobalConfigurationDirectory () noexcept {
@@ -55,9 +59,51 @@ llvm::StringRef PhasarConfig::DefaultSourceSinkFunctionsPath() noexcept {
5559 return PHASAR_SRC_DIR " /config/phasar-source-sink-function.json" ;
5660}
5761
62+ static bool loadConfigFileInto (PhasarConfig &PC, llvm::StringRef FileName,
63+ std::set<std::string> &Lines) {
64+ auto ConfigFile = PC.readConfigFileAsTextOrErr (FileName);
65+ if (!ConfigFile) {
66+ if (ConfigFile.getError () != std::errc::no_such_file_or_directory) {
67+ PHASAR_LOG_LEVEL (WARNING, " Could not open config file '"
68+ << FileName << " ': "
69+ << ConfigFile.getError ().message ());
70+ }
71+
72+ return false ;
73+ }
74+
75+ llvm::SmallVector<llvm::StringRef, 0 > ConfigLines;
76+ llvm::SplitString (*ConfigFile, ConfigLines, " \n " );
77+
78+ llvm::transform (
79+ ConfigLines, std::inserter (Lines, Lines.end ()), [](llvm::StringRef Str) {
80+ if (auto Comment = Str.find (" //" ); Comment != llvm::StringRef::npos) {
81+ Str = Str.slice (0 , Comment);
82+ }
83+ return Str.trim ().str ();
84+ });
85+ return true ;
86+ }
87+
88+ static void loadGlibcSpecialFunctionNames (PhasarConfig &PC,
89+ std::set<std::string> &Into) {
90+ if (!loadConfigFileInto (PC, GLIBCFunctionListFileName, Into)) {
91+ // Add default glibc function names
92+ Into.insert ({" _exit" });
93+ }
94+ }
95+
96+ static void loadLLVMSpecialFunctionNames (PhasarConfig &PC,
97+ std::set<std::string> &Into) {
98+ if (!loadConfigFileInto (PC, LLVMIntrinsicFunctionListFileName, Into)) {
99+ // Add default LLVM function names
100+ Into.insert ({" llvm.va_start" });
101+ }
102+ }
103+
58104PhasarConfig::PhasarConfig () {
59- loadGlibcSpecialFunctionNames ();
60- loadLLVMSpecialFunctionNames ();
105+ loadGlibcSpecialFunctionNames (* this , SpecialFuncNames );
106+ loadLLVMSpecialFunctionNames (* this , SpecialFuncNames );
61107
62108 // Insert allocation operators
63109 SpecialFuncNames.insert ({" _Znwm" , " _Znam" , " _ZdlPv" , " _ZdaPv" });
@@ -120,47 +166,6 @@ PhasarConfig::readConfigFileAsTextOrNull(const llvm::Twine &FileName) {
120166 return std::nullopt ;
121167}
122168
123- bool PhasarConfig::loadConfigFileInto (llvm::StringRef FileName,
124- std::set<std::string> &Lines) {
125- auto ConfigFile = readConfigFileAsTextOrErr (FileName);
126- if (!ConfigFile) {
127- if (ConfigFile.getError () != std::errc::no_such_file_or_directory) {
128- PHASAR_LOG_LEVEL (WARNING, " Could not open config file '"
129- << FileName << " ': "
130- << ConfigFile.getError ().message ());
131- }
132-
133- return false ;
134- }
135-
136- llvm::SmallVector<llvm::StringRef, 0 > ConfigLines;
137- llvm::SplitString (*ConfigFile, ConfigLines, " \n " );
138-
139- llvm::transform (
140- ConfigLines, std::inserter (Lines, Lines.end ()), [](llvm::StringRef Str) {
141- if (auto Comment = Str.find (" //" ); Comment != llvm::StringRef::npos) {
142- Str = Str.slice (0 , Comment);
143- }
144- return Str.trim ().str ();
145- });
146- return true ;
147- }
148-
149- void PhasarConfig::loadGlibcSpecialFunctionNames () {
150- if (!loadConfigFileInto (GLIBCFunctionListFileName, SpecialFuncNames)) {
151- // Add default glibc function names
152- SpecialFuncNames.insert ({" _exit" });
153- }
154- }
155-
156- void PhasarConfig::loadLLVMSpecialFunctionNames () {
157- if (!loadConfigFileInto (LLVMIntrinsicFunctionListFileName,
158- SpecialFuncNames)) {
159- // Add default LLVM function names
160- SpecialFuncNames.insert ({" llvm.va_start" });
161- }
162- }
163-
164169PhasarConfig &PhasarConfig::getPhasarConfig () {
165170 static PhasarConfig PC{};
166171 return PC;
0 commit comments