Skip to content

Commit 084787a

Browse files
committed
Merge branch 'development' into development-gitlab
2 parents f9e9ddd + 4727c83 commit 084787a

20 files changed

Lines changed: 339 additions & 135 deletions

File tree

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ option(PHASAR_BUILD_IR "Build IR test code (default is OFF)" OFF)
5151

5252
option(PHASAR_BUILD_DOC "Build documentation" OFF)
5353

54+
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
55+
5456
option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
5557

5658
option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON)
@@ -103,7 +105,6 @@ endif()
103105
# Boost
104106
find_package(Boost 1.65.1 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
105107
include_directories(${Boost_INCLUDE_DIRS})
106-
add_definitions(-DBOOST_LOG_DYN_LINK)
107108

108109
# JSON library
109110
option(JSON_BuildTests OFF)
@@ -233,6 +234,8 @@ if (PHASAR_BUILD_IR)
233234
add_subdirectory(test)
234235
endif()
235236

237+
set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Install dir of headers")
238+
236239
# Install targets of phasar-llvm, other executables, and libraries are to be
237240
# found in the individual subdirectories of tools/
238241

@@ -273,6 +276,33 @@ install(DIRECTORY config/
273276
WORLD_READ
274277
)
275278

279+
install(EXPORT phasarTargets
280+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
281+
NAMESPACE phasar::
282+
FILE phasarTargets.cmake
283+
)
284+
285+
include(CMakePackageConfigHelpers)
286+
configure_package_config_file(
287+
Config.cmake.in
288+
phasarConfig.cmake
289+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
290+
PATH_VARS INCLUDE_INSTALL_DIR
291+
)
292+
293+
write_basic_package_version_file(
294+
${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake
295+
VERSION 1.0.0
296+
COMPATIBILITY SameMajorVersion
297+
)
298+
299+
### Install Config and ConfigVersion files
300+
install(
301+
FILES "${CMAKE_CURRENT_BINARY_DIR}/phasarConfig.cmake"
302+
"${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake"
303+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
304+
)
305+
276306
# If the Phasar shared object libraries are not installed into a system folder
277307
# the so libs must be added manually to the linker search path and the linker
278308
# config must be updated as follows:

Config.cmake.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(PHASAR_VERSION 1.0.0)
2+
3+
@PACKAGE_INIT@
4+
set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
5+
include( "${CMAKE_CURRENT_LIST_DIR}/phasarTargets.cmake" )
6+
7+
check_required_components(phasar)

cmake/phasar_macros.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ macro(add_phasar_library name)
161161
set(libkind)
162162
endif()
163163
add_library( ${name} ${libkind} ${srcs} )
164+
add_library( phasar::${name} ALIAS ${name} )
164165
if( LLVM_COMMON_DEPENDS )
165166
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
166167
endif( LLVM_COMMON_DEPENDS )
@@ -173,6 +174,11 @@ macro(add_phasar_library name)
173174
if(PHASAR_LINK_LIBS)
174175
foreach(lib ${PHASAR_LINK_LIBS})
175176
target_link_libraries(${name} LINK_PRIVATE ${lib})
177+
if(PHASAR_DEBUG_LIBDEPS)
178+
target_link_libraries(${name} LINK_PRIVATE ${lib})
179+
else()
180+
target_link_libraries(${name} LINK_PUBLIC ${lib})
181+
endif(PHASAR_DEBUG_LIBDEPS)
176182
endforeach(lib)
177183
endif(PHASAR_LINK_LIBS)
178184

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(PhasarExttoolTest)
4+
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
set(CMAKE_CXX_EXTENSIONS OFF)
9+
10+
11+
# Build a small test tool to show how phasar may be used
12+
add_executable(myphasartool
13+
myphasartool.cpp
14+
)
15+
16+
find_package(phasar)
17+
include_directories(${PHASAR_INCLUDE_DIR})
18+
link_directories(${PHASAR_LIBRARY_DIR})
19+
20+
target_link_libraries(myphasartool
21+
LINK_PUBLIC
22+
phasar::phasar_config
23+
phasar::phasar_controller
24+
phasar::phasar_db
25+
phasar::phasar_experimental
26+
phasar::phasar_clang
27+
phasar::phasar_controlflow
28+
phasar::phasar_ifdside
29+
phasar::phasar_mono
30+
phasar::phasar_passes
31+
phasar::phasar_pointer
32+
phasar::phasar_typehierarchy
33+
phasar::phasar_phasarllvm_utils
34+
# phasar::phasar_utils #already introduced through phasar_clang
35+
)
36+
37+
install(TARGETS myphasartool
38+
RUNTIME DESTINATION bin
39+
LIBRARY DESTINATION lib
40+
ARCHIVE DESTINATION lib
41+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a demo tool that uses PhASAR as a library. Currently this is only supported in the f-CMakePackage feature branch of PhASAR. The number of phasar libraries explicitly stated in CMakeLists.txt can be further reduced by stating the non-transitive dependencies of phasar libraries. This is pending work on the PhASAR side.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/******************************************************************************
2+
* Copyright (c) 2017 Philipp Schubert.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Philipp Schubert and others
8+
*****************************************************************************/
9+
10+
#include <iostream>
11+
#include <fstream>
12+
13+
#include <boost/filesystem/operations.hpp>
14+
15+
#include <phasar/DB/ProjectIRDB.h>
16+
#include <phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h>
17+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h>
18+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IFDSLinearConstantAnalysis.h>
19+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h>
20+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IFDSSolver.h>
21+
#include <phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h>
22+
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
23+
#include <phasar/Utils/Logger.h>
24+
25+
namespace llvm {
26+
class Value;
27+
} // namespace llvm
28+
29+
using namespace psr;
30+
31+
int main(int argc, const char **argv) {
32+
initializeLogger(false);
33+
auto &lg = lg::get();
34+
if (argc < 2 || !boost::filesystem::exists(argv[1]) ||
35+
boost::filesystem::is_directory(argv[1])) {
36+
std::cerr << "myphasartool\n"
37+
"A small PhASAR-based example program\n\n"
38+
"Usage: myphasartool <LLVM IR file>\n";
39+
return 1;
40+
}
41+
initializeLogger(false);
42+
ProjectIRDB DB({argv[1]});
43+
if (auto F = DB.getFunctionDefinition("main")) {
44+
LLVMTypeHierarchy H(DB);
45+
// print type hierarchy
46+
H.print();
47+
LLVMPointsToInfo P(DB);
48+
// print points-to information
49+
P.print();
50+
LLVMBasedICFG I(DB, CallGraphAnalysisType::OTF, {"main"}, &H, &P);
51+
// print inter-procedural control-flow graph
52+
I.print();
53+
// IFDS template parametrization test
54+
std::cout << "Testing IFDS:\n";
55+
IFDSLinearConstantAnalysis L(&DB, &H, &I, &P, {"main"});
56+
IFDSSolver<IFDSLinearConstantAnalysis::n_t, IFDSLinearConstantAnalysis::d_t,
57+
IFDSLinearConstantAnalysis::f_t, IFDSLinearConstantAnalysis::t_t,
58+
IFDSLinearConstantAnalysis::v_t, IFDSLinearConstantAnalysis::i_t>
59+
S(L);
60+
S.solve();
61+
S.dumpResults();
62+
// IDE template parametrization test
63+
std::cout << "Testing IDE:\n";
64+
IDELinearConstantAnalysis M(&DB, &H, &I, &P, {"main"});
65+
IDESolver<IDELinearConstantAnalysis::n_t, IDELinearConstantAnalysis::d_t,
66+
IDELinearConstantAnalysis::f_t, IDELinearConstantAnalysis::t_t,
67+
IDELinearConstantAnalysis::v_t, IDELinearConstantAnalysis::l_t,
68+
IDELinearConstantAnalysis::i_t>
69+
T(M);
70+
T.solve();
71+
T.dumpResults();
72+
} else {
73+
std::cerr << "error: file does not contain a 'main' function!\n";
74+
}
75+
return 0;
76+
}

include/phasar/DB/ProjectIRDB.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <llvm/IR/LLVMContext.h>
2121
#include <llvm/IR/Module.h>
2222

23-
#include <phasar/PhasarLLVM/Pointer/LLVMPointsToGraph.h>
2423
#include <phasar/Utils/EnumFlags.h>
2524

2625
namespace llvm {

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class LLVMBasedICFG
8888
};
8989

9090
/// Specify the type of graph to be used.
91-
typedef boost::adjacency_list<boost::multisetS, boost::vecS,
91+
typedef boost::adjacency_list<boost::vecS, boost::vecS,
9292
boost::bidirectionalS, VertexProperties,
9393
EdgeProperties>
9494
bidigraph_t;
@@ -106,7 +106,7 @@ class LLVMBasedICFG
106106
/// Maps function names to the corresponding vertex id.
107107
std::unordered_map<const llvm::Function *, vertex_t> FunctionVertexMap;
108108

109-
void constructionWalker(const llvm::Function *F, Resolver *Res);
109+
void constructionWalker(const llvm::Function *F, Resolver &Resolver);
110110

111111
struct dependency_visitor;
112112

@@ -162,44 +162,7 @@ class LLVMBasedICFG
162162
using LLVMBasedCFG::print; // tell the compiler we wish to have both prints
163163
void print(std::ostream &OS = std::cout) const override;
164164

165-
// provide a VertexPropertyWrite to tell boost how to write a vertex
166-
class CallGraphVertexWriter {
167-
public:
168-
CallGraphVertexWriter(const bidigraph_t &CGraph) : CGraph(CGraph) {}
169-
template <class VertexOrEdge>
170-
void operator()(std::ostream &out, const VertexOrEdge &v) const {
171-
out << "[label=\"" << CGraph[v].getFunctionName() << "\"]";
172-
}
173-
174-
private:
175-
const bidigraph_t &CGraph;
176-
};
177-
178-
// a function to conveniently create the vertex writer
179-
CallGraphVertexWriter
180-
makeCallGraphVertexWriter(const bidigraph_t &CGraph) const {
181-
return CallGraphVertexWriter(CGraph);
182-
}
183-
184-
// provide a EdgePropertyWrite to tell boost how to write an edge
185-
class CallGraphEdgeWriter {
186-
public:
187-
CallGraphEdgeWriter(const bidigraph_t &CGraph) : CGraph(CGraph) {}
188-
template <class VertexOrEdge>
189-
void operator()(std::ostream &out, const VertexOrEdge &v) const {
190-
out << "[label=\"" << CGraph[v].getCallSiteAsString() << "\"]";
191-
}
192-
193-
private:
194-
const bidigraph_t &CGraph;
195-
};
196-
197-
// a function to conveniently create the edge writer
198-
CallGraphEdgeWriter makeCallGraphEdgeWriter(const bidigraph_t &CGraph) const {
199-
return CallGraphEdgeWriter(CGraph);
200-
}
201-
202-
void printAsDot(std::ostream &OS = std::cout) const;
165+
void printAsDot(std::ostream &OS = std::cout, bool printEdgeLabels = true) const;
203166

204167
void printInternalPTGAsDot(std::ostream &OS = std::cout) const;
205168

include/phasar/PhasarLLVM/Pointer/LLVMPointsToGraph.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class PointsToGraph {
7777
VertexProperties() = default;
7878
VertexProperties(const llvm::Value *v);
7979
std::string getValueAsString() const;
80+
81+
// Fetching the users for V is expensive, so we cache the result.
82+
mutable std::vector<const llvm::User*> users;
83+
std::vector<const llvm::User*> getUsers() const;
8084
};
8185

8286
/**
@@ -91,7 +95,7 @@ class PointsToGraph {
9195
};
9296

9397
/// Data structure for holding the points-to graph.
94-
typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS,
98+
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
9599
VertexProperties, EdgeProperties>
96100
graph_t;
97101

lib/DB/ProjectIRDB.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <boost/filesystem.hpp>
3030

31+
#include <phasar/Config/Configuration.h>
3132
#include <phasar/DB/ProjectIRDB.h>
3233
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/LLVMZeroValue.h>
3334
#include <phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h>

0 commit comments

Comments
 (0)