Skip to content

Commit 332509b

Browse files
authored
Update Phasar Config (#752)
* Derive PhasarConfig::PhasarVersion() from cmake + some cleanup in Configuration.h * PHASAR_VERSION in Doxyfile
1 parent d9d0b65 commit 332509b

File tree

8 files changed

+80
-80
lines changed

8 files changed

+80
-80
lines changed

CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ if (DEFINED LLVM_MAIN_SRC_DIR)
2424
endif()
2525

2626
if (NOT PHASAR_IN_TREE)
27-
project (phasar)
28-
set(CMAKE_PROJECT_NAME "phasar")
27+
project (phasar
28+
LANGUAGES C CXX
29+
DESCRIPTION "A LLVM-based static analysis framework."
30+
)
2931
endif ()
32+
set(PHASAR_VERSION 2403)
3033

3134
# NOTE: When we require cmake >= 3.21, we can use PROJECT_IS_TOP_LEVEL instead
3235
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
@@ -492,7 +495,7 @@ configure_package_config_file(
492495

493496
write_basic_package_version_file(
494497
${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake
495-
VERSION 2403
498+
VERSION ${PHASAR_VERSION}
496499
COMPATIBILITY SameMajorVersion
497500
)
498501

Config.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(PHASAR_VERSION 2403)
1+
set(PHASAR_VERSION @PHASAR_VERSION@)
22

33
@PACKAGE_INIT@
44
set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")

config.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define PHASAR_CONFIG_CONFIG_H
33

44
#define PHASAR_CONFIG_DIR "@PHASAR_CONFIG_INSTALL_DIR@"
5+
#define PHASAR_VERSION @PHASAR_VERSION@
6+
#define PHASAR_VERSION_STRING "v@PHASAR_VERSION@"
57

68
#cmakedefine PAMM_CORE
79
#cmakedefine PAMM_FULL

docs/Doxyfile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "Phasar"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 1.1
41+
PROJECT_NUMBER = @PHASAR_VERSION@
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

include/phasar/Config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#define PHASAR_CONFIG_H
1212

1313
#include "phasar/Config/Configuration.h"
14-
#include "phasar/Config/Version.h"
14+
#include "phasar/Config/phasar-config.h"
1515

1616
#endif // PHASAR_CONFIG_H

include/phasar/Config/Configuration.h

+9-25
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717
#ifndef PHASAR_CONFIG_CONFIGURATION_H_
1818
#define PHASAR_CONFIG_CONFIGURATION_H_
1919

20-
#include "phasar/Config/Version.h"
21-
2220
#include "llvm/ADT/StringRef.h"
2321
#include "llvm/ADT/iterator_range.h"
2422
#include "llvm/Support/MemoryBuffer.h"
2523

26-
#include <filesystem>
2724
#include <optional>
2825
#include <set>
2926
#include <string>
@@ -32,7 +29,8 @@ namespace psr {
3229

3330
class PhasarConfig {
3431
public:
35-
/// Current Phasar version
32+
/// Current Phasar version. Same as the preprocessor-symbol
33+
/// PHASAR_VERSION_STRING
3634
// NOLINTNEXTLINE(readability-identifier-naming)
3735
[[nodiscard]] static llvm::StringRef PhasarVersion() noexcept;
3836

@@ -66,27 +64,30 @@ class PhasarConfig {
6664
[[nodiscard]] std::optional<std::string>
6765
readConfigFileAsTextOrNull(const llvm::Twine &FileName);
6866

69-
/// Specifies the directory in which Phasar is located.
67+
/// Specifies the directory in which Phasar's sources are located.
7068
// NOLINTNEXTLINE(readability-identifier-naming)
7169
[[nodiscard]] static llvm::StringRef PhasarDirectory() noexcept;
7270

7371
/// Name of the file storing all standard header search paths used for
7472
/// compilation.
75-
[[nodiscard]] static constexpr llvm::StringRef
73+
[[nodiscard, deprecated("This ancient API is broken and should not be used "
74+
"anymore")]] static constexpr llvm::StringRef
7675
// NOLINTNEXTLINE(readability-identifier-naming)
7776
HeaderSearchPathsFileName() noexcept {
7877
return "standard_header_paths.conf";
7978
}
8079

8180
/// Name of the compile_commands.json file (in case we wish to rename)
82-
[[nodiscard]] static constexpr llvm::StringRef
81+
[[nodiscard, deprecated("This ancient API is broken and should not be used "
82+
"anymore")]] static constexpr llvm::StringRef
8383
// NOLINTNEXTLINE(readability-identifier-naming)
8484
CompileCommandsJson() noexcept {
8585
return "compile_commands.json";
8686
}
8787

8888
/// Default Source- and Sink-Functions path
89-
[[nodiscard]] static llvm::StringRef
89+
[[nodiscard, deprecated("This ancient API is broken and should not be used "
90+
"anymore")]] static llvm::StringRef
9091
// NOLINTNEXTLINE(readability-identifier-naming)
9192
DefaultSourceSinkFunctionsPath() noexcept;
9293

@@ -142,24 +143,7 @@ class PhasarConfig {
142143
private:
143144
PhasarConfig();
144145

145-
bool loadConfigFileInto(llvm::StringRef FileName,
146-
std::set<std::string> &Lines);
147-
148-
void loadGlibcSpecialFunctionNames();
149-
void loadLLVMSpecialFunctionNames();
150-
151146
std::set<std::string> SpecialFuncNames;
152-
153-
/// Name of the file storing all glibc function names.
154-
static constexpr llvm::StringLiteral GLIBCFunctionListFileName =
155-
"glibc_function_list_v1-04.05.17.conf";
156-
157-
/// Name of the file storing all LLVM intrinsic function names.
158-
static constexpr llvm::StringLiteral LLVMIntrinsicFunctionListFileName =
159-
"llvm_intrinsics_function_list_v1-04.05.17.conf";
160-
161-
/// Log file directory
162-
static constexpr llvm::StringLiteral LogFileDirectory = "log/";
163147
};
164148

165149
} // namespace psr

include/phasar/Config/Version.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#ifndef PHASAR_CONFIG_VERSION_H
22
#define PHASAR_CONFIG_VERSION_H
33

4-
#define PHASAR_VERSION v2403
4+
/// Note: This header is only left for backward compatibility and may be removed
5+
/// in the future
6+
7+
#pragma GCC warning( \
8+
"The header Version.h is deprecated. Use 'phasar/Config/phasar-config.h' instead")
9+
10+
#include "phasar/Config/phasar-config.h"
511

612
#endif

lib/Config/Configuration.cpp

+53-48
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@
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-
3935
using namespace psr;
4036

4137
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+
4246
llvm::StringRef PhasarConfig::PhasarVersion() noexcept {
43-
return XSTR(PHASAR_VERSION);
47+
return PHASAR_VERSION_STRING;
4448
}
4549

4650
llvm::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+
58104
PhasarConfig::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-
164169
PhasarConfig &PhasarConfig::getPhasarConfig() {
165170
static PhasarConfig PC{};
166171
return PC;

0 commit comments

Comments
 (0)