Skip to content

Commit

Permalink
Add enums for CGA and PT to replace wise_enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rleer committed Nov 14, 2019
1 parent e9b050c commit ea7c780
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 88 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@
[submodule "external/WALi-OpenNWA"]
path = external/WALi-OpenNWA
url = https://github.com/pdschubert/WALi-OpenNWA.git
[submodule "external/wise_enum"]
path = external/wise_enum
url = https://github.com/quicknir/wise_enum.git
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ endif()
add_subdirectory(external/WALi-OpenNWA)
include_directories(external/WALi-OpenNWA/Source/wali/include)

# wise enum
add_subdirectory(external/wise_enum)
include_directories(external/wise_enum)

# Boost
find_package(Boost COMPONENTS filesystem graph system program_options log thread REQUIRED)
include_directories(${BOOST_INCLUDE_DIR})
Expand Down
26 changes: 0 additions & 26 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,6 @@ can be traced back to its original author, and all of those authors have public
ated with licensed code from other projects.


wise_enum
-------------------------------------------------------------------------------
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

JSON
-------------------------------------------------------------------------------
MIT License
Expand Down
4 changes: 0 additions & 4 deletions include/phasar/Controller/AnalysisController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace psr {

class ProjectIRDB;

WISE_ENUM_CLASS(ExportType, (JSON, 0))

std::ostream &operator<<(std::ostream &os, const ExportType &e);

class AnalysisController {
public:
using json = nlohmann::json;
Expand Down
11 changes: 9 additions & 2 deletions include/phasar/PhasarLLVM/ControlFlow/ICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
#include <string>

#include <json.hpp>
#include <wise_enum.h>

#include <phasar/PhasarLLVM/ControlFlow/CFG.h>

namespace psr {

WISE_ENUM_CLASS(CallGraphAnalysisType, CHA, RTA, DTA, OTF)
enum class CallGraphAnalysisType {
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE) TYPE,
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
Invalid
};

std::string to_string(const CallGraphAnalysisType &CGA);

CallGraphAnalysisType to_CallGraphAnalysisType(const std::string &S);

std::ostream &operator<<(std::ostream &os, const CallGraphAnalysisType &CGA);

Expand Down
17 changes: 12 additions & 5 deletions include/phasar/PhasarLLVM/Pointer/LLVMPointsToGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
#define PHASAR_PHASARLLVM_POINTER_POINTSTOGRAPH_H_

#include <vector>
#include <json.hpp>

#include <boost/graph/adjacency_list.hpp>

#include <llvm/IR/CallSite.h>

#include <json.hpp>
#include <wise_enum.h>

#include <phasar/Config/Configuration.h>

namespace llvm {
Expand Down Expand Up @@ -73,7 +70,17 @@ inline void PrintLoadStoreResults(const char *Msg, bool P,
const llvm::Value *V1, const llvm::Value *V2,
const llvm::Module *M);

WISE_ENUM_CLASS(PointerAnalysisType, CFLSteens, CFLAnders)
enum class PointerAnalysisType{
#define ANALYSIS_SETUP_POINTER_TYPE(NAME, CMDFLAG, TYPE) TYPE,
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
Invalid
};

std::string to_string(const PointerAnalysisType &PA);

PointerAnalysisType to_PointerAnalysisType(const std::string &S);

std::ostream &operator<<(std::ostream &os, const PointerAnalysisType &PA);

// TODO: add a more high level description.
/**
Expand Down
28 changes: 28 additions & 0 deletions include/phasar/PhasarLLVM/Utils/AnalysisSetups.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/******************************************************************************
* Copyright (c) 2019 Philipp Schubert.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Philipp Schubert and others
*****************************************************************************/

#ifndef ANALYSIS_SETUP_CALLGRAPH_TYPE
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE)
#endif

ANALYSIS_SETUP_CALLGRAPH_TYPE("CHA", "cha", CHA)
ANALYSIS_SETUP_CALLGRAPH_TYPE("RTA", "rta", RTA)
ANALYSIS_SETUP_CALLGRAPH_TYPE("DTA", "dta", DTA)
ANALYSIS_SETUP_CALLGRAPH_TYPE("VTA", "vta", VTA)
ANALYSIS_SETUP_CALLGRAPH_TYPE("OTF", "otf", OTF)

#ifndef ANALYSIS_SETUP_POINTER_TYPE
#define ANALYSIS_SETUP_POINTER_TYPE(NAME, CMDFLAG, TYPE)
#endif

ANALYSIS_SETUP_POINTER_TYPE("CFLSteens", "cflsteens", CFLSteens)
ANALYSIS_SETUP_POINTER_TYPE("CFLAnders", "cflanders", CFLAnders)

#undef ANALYSIS_SETUP_CALLGRAPH_TYPE
#undef ANALYSIS_SETUP_POINTER_TYPE
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace psr {

enum class DataFlowAnalysisType {
#define DATA_FLOW_ANALYSIS_TYPES(NAME, CMDFLAG, TYPE) TYPE,
#include "DataFlowAnalysisType.def"
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.def>
};

std::string to_string(const DataFlowAnalysisType &D);
Expand Down
13 changes: 2 additions & 11 deletions lib/Controller/AnalysisController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@
#include <phasar/PhasarLLVM/DataFlowSolver/Mono/Solver/LLVMIntraMonoSolver.h>
#include <phasar/PhasarLLVM/Plugins/AnalysisPluginController.h>
#include <phasar/PhasarLLVM/Plugins/PluginFactories.h>
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
#include <phasar/PhasarLLVM/Pointer/VTable.h>
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
#include <phasar/PhasarLLVM/Utils/TaintConfiguration.h>

using namespace std;
using namespace psr;

namespace psr {

std::ostream &operator<<(std::ostream &os, const ExportType &E) {
return os << wise_enum::to_string(E);
}

AnalysisController::AnalysisController(
ProjectIRDB &&IRDB, std::vector<DataFlowAnalysisType> Analyses,
bool WPA_MODE, bool PrintEdgeRecorder, std::string graph_id)
Expand Down Expand Up @@ -168,12 +164,7 @@ AnalysisController::AnalysisController(
// }

// Call graph construction stategy
CallGraphAnalysisType CGType(
(PhasarConfig::VariablesMap().count("callgraph-analysis"))
? wise_enum::from_string<CallGraphAnalysisType>(
PhasarConfig::VariablesMap()["callgraph-analysis"].as<string>())
.value()
: CallGraphAnalysisType::OTF);
CallGraphAnalysisType CGType = to_CallGraphAnalysisType(PhasarConfig::VariablesMap().count("callgraph-analysis"));
// Perform whole program analysis (WPA) analysis
if (WPA_MODE) {
START_TIMER("CG Construction", PAMM_SEVERITY_LEVEL::Core);
Expand Down
35 changes: 33 additions & 2 deletions lib/PhasarLLVM/ControlFlow/ICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,47 @@
* Author: pdschbrt
*/

#include <iostream>
#include <ostream>
#include <string>

#include <llvm/ADT/StringSwitch.h>

#include <phasar/PhasarLLVM/ControlFlow/ICFG.h>

using namespace psr;
using namespace std;

namespace psr {

std::string to_string(const CallGraphAnalysisType &CGA) {
switch (CGA) {
default:
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE) \
case CallGraphAnalysisType::TYPE: \
return NAME; \
break;
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
}
}

CallGraphAnalysisType to_CallGraphAnalysisType(const std::string &S) {
CallGraphAnalysisType Type = llvm::StringSwitch<CallGraphAnalysisType>(S)
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE) \
.Case(NAME, CallGraphAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
.Default(CallGraphAnalysisType::Invalid);
if (Type == CallGraphAnalysisType::Invalid) {
Type = llvm::StringSwitch<CallGraphAnalysisType>(S)
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE) \
.Case(CMDFLAG, CallGraphAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
.Default(CallGraphAnalysisType::Invalid);
}
return Type;
}

ostream &operator<<(ostream &os, const CallGraphAnalysisType &CGA) {
return os << wise_enum::to_string(CGA);
return os << to_string(CGA);
}

} // namespace psr
32 changes: 32 additions & 0 deletions lib/PhasarLLVM/Pointer/LLVMPointsToGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Author: pdschbrt
*/
#include <llvm/ADT/SetVector.h>
#include <llvm/ADT/StringSwitch.h>
#include <llvm/Analysis/CFLSteensAliasAnalysis.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/InstIterator.h>
Expand All @@ -40,6 +41,37 @@ using namespace psr;

namespace psr {

std::string to_string(const PointerAnalysisType &PA) {
switch (PA) {
default:
#define ANALYSIS_SETUP_CALLGRAPH_TYPE(NAME, CMDFLAG, TYPE) \
case PointerAnalysisType::TYPE: \
return NAME; \
break;
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
}
}

PointerAnalysisType to_PointerAnalysisType(const std::string &S) {
PointerAnalysisType Type = llvm::StringSwitch<PointerAnalysisType>(S)
#define ANALYSIS_SETUP_POINTER_TYPE(NAME, CMDFLAG, TYPE) \
.Case(NAME, PointerAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
.Default(PointerAnalysisType::Invalid);
if (Type == PointerAnalysisType::Invalid) {
Type = llvm::StringSwitch<PointerAnalysisType>(S)
#define ANALYSIS_SETUP_POINTER_TYPE(NAME, CMDFLAG, TYPE) \
.Case(CMDFLAG, PointerAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/AnalysisSetups.def>
.Default(PointerAnalysisType::Invalid);
}
return Type;
}

ostream &operator<<(ostream &os, const PointerAnalysisType &PA) {
return os << to_string(PA);
}

struct PointsToGraph::allocation_site_dfs_visitor : boost::default_dfs_visitor {
// collect the allocation sites that are found
std::set<const llvm::Value *> &allocation_sites;
Expand Down
16 changes: 8 additions & 8 deletions lib/PhasarLLVM/Utils/DataFlowAnalysisType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ std::string to_string(const DataFlowAnalysisType &D) {

DataFlowAnalysisType to_DataFlowAnalysisType(const std::string &S) {
DataFlowAnalysisType Type = llvm::StringSwitch<DataFlowAnalysisType>(S)
#define DATA_FLOW_ANALYSIS_TYPES(NAME, CMDFLAG, TYPE) \
.Case(NAME, DataFlowAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.def>
.Default(DataFlowAnalysisType::None);
#define DATA_FLOW_ANALYSIS_TYPES(NAME, CMDFLAG, TYPE) \
.Case(NAME, DataFlowAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.def>
.Default(DataFlowAnalysisType::None);
if (Type == DataFlowAnalysisType::None) {
Type = llvm::StringSwitch<DataFlowAnalysisType>(S)
#define DATA_FLOW_ANALYSIS_TYPES(NAME, CMDFLAG, TYPE) \
.Case(CMDFLAG, DataFlowAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.def>
.Default(DataFlowAnalysisType::None);
#define DATA_FLOW_ANALYSIS_TYPES(NAME, CMDFLAG, TYPE) \
.Case(CMDFLAG, DataFlowAnalysisType::TYPE)
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.def>
.Default(DataFlowAnalysisType::None);
}
return Type;
}
Expand Down
6 changes: 2 additions & 4 deletions lib/PhasarPass/PhasarPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <llvm/PassAnalysisSupport.h>
#include <llvm/Support/ErrorHandling.h>
#include <llvm/Support/raw_ostream.h>
#include <wise_enum.h>

#include <phasar/DB/ProjectIRDB.h>
#include <phasar/PhasarLLVM/ControlFlow/ICFG.h>
Expand Down Expand Up @@ -68,8 +67,7 @@ bool PhasarPass::runOnModule(llvm::Module &M) {
}
}
// set up the call-graph algorithm to be used
CallGraphAnalysisType CGTy =
wise_enum::from_string<CallGraphAnalysisType>(CallGraphAnalysis).value();
CallGraphAnalysisType CGTy = to_CallGraphAnalysisType(CallGraphAnalysis);
LLVMTypeHierarchy H(DB);
LLVMBasedCFG CFG;
LLVMBasedICFG I(H, DB, CGTy, EntryPoints);
Expand Down Expand Up @@ -190,7 +188,7 @@ bool PhasarPass::doInitialization(llvm::Module &M) {
if (EntryPoints.empty()) {
llvm::report_fatal_error("psr error: no entry points provided");
}
if (!wise_enum::from_string<CallGraphAnalysisType>(CallGraphAnalysis)) {
if (to_CallGraphAnalysisType(CallGraphAnalysis) == CallGraphAnalysisType::Invalid) {
llvm::report_fatal_error("psr error: call-graph analysis does not exist");
}
if (to_DataFlowAnalysisType(DataFlowAnalysis) == DataFlowAnalysisType::None) {
Expand Down
Loading

0 comments on commit ea7c780

Please sign in to comment.