28
28
#include " llvm/Support/FileSystem.h"
29
29
#include " llvm/Support/Path.h"
30
30
31
- #include < algorithm>
32
31
#include < cstdlib>
33
32
#include < iterator>
34
33
#include < system_error>
35
34
36
- #define XSTR (S ) STR(S)
37
- #define STR (S ) #S
38
-
39
35
using namespace psr ;
40
36
41
37
namespace 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
+
42
46
llvm::StringRef PhasarConfig::PhasarVersion () noexcept {
43
- return XSTR (PHASAR_VERSION) ;
47
+ return PHASAR_VERSION_STRING ;
44
48
}
45
49
46
50
llvm::StringRef PhasarConfig::GlobalConfigurationDirectory () noexcept {
@@ -55,9 +59,51 @@ llvm::StringRef PhasarConfig::DefaultSourceSinkFunctionsPath() noexcept {
55
59
return PHASAR_SRC_DIR " /config/phasar-source-sink-function.json" ;
56
60
}
57
61
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
+
58
104
PhasarConfig::PhasarConfig () {
59
- loadGlibcSpecialFunctionNames ();
60
- loadLLVMSpecialFunctionNames ();
105
+ loadGlibcSpecialFunctionNames (* this , SpecialFuncNames );
106
+ loadLLVMSpecialFunctionNames (* this , SpecialFuncNames );
61
107
62
108
// Insert allocation operators
63
109
SpecialFuncNames.insert ({" _Znwm" , " _Znam" , " _ZdlPv" , " _ZdaPv" });
@@ -120,47 +166,6 @@ PhasarConfig::readConfigFileAsTextOrNull(const llvm::Twine &FileName) {
120
166
return std::nullopt;
121
167
}
122
168
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
-
164
169
PhasarConfig &PhasarConfig::getPhasarConfig () {
165
170
static PhasarConfig PC{};
166
171
return PC;
0 commit comments