Skip to content

Commit cbd60b7

Browse files
committed
added example program that uses phasar as library to examples/
1 parent 121d8f5 commit cbd60b7

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

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::m_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::m_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+
}

0 commit comments

Comments
 (0)