|
| 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