Skip to content

Commit

Permalink
Initial version of the z3 expression builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rsas committed Feb 11, 2019
1 parent 233bbd1 commit 7d806c4
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ set(SOUPER_EXTRACTOR_FILES
lib/Extractor/ExprBuilder.cpp
lib/Extractor/KLEEBuilder.cpp
lib/Extractor/Solver.cpp
lib/Extractor/Z3Builder.cpp
include/souper/Extractor/Candidates.h
include/souper/Extractor/ExprBuilder.h
include/souper/Extractor/Solver.h
Expand Down Expand Up @@ -363,7 +364,7 @@ if(NOT GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
PROPERTIES COMPILE_FLAGS "${LLVM_CXXFLAGS}")
target_include_directories(souperweb-backend PRIVATE "${LLVM_INCLUDEDIR}")

target_link_libraries(souperweb-backend souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser souperInst ${HIREDIS_LIBRARY})
target_link_libraries(souperweb-backend souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser souperInst ${HIREDIS_LIBRARY} ${Z3_LIBRARY})

add_custom_target(souperweb ALL COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/souperweb ${CMAKE_SOURCE_DIR}/tools/souperweb.go
COMMENT "Building souperweb")
Expand Down
4 changes: 3 additions & 1 deletion include/souper/Extractor/ExprBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ExprBuilder {
const unsigned MAX_PHI_DEPTH = 25;
public:
enum Builder {
KLEE
KLEE,
Z3
};

ExprBuilder(InstContext &IC) : LIC(&IC) {}
Expand Down Expand Up @@ -108,6 +109,7 @@ std::string BuildQuery(InstContext &IC, const BlockPCs &BPCs,
std::vector<Inst *> *ModelVars, bool Negate=false);

std::unique_ptr<ExprBuilder> createKLEEBuilder(InstContext &IC);
std::unique_ptr<ExprBuilder> createZ3Builder(InstContext &IC);
}

#endif // SOUPER_EXTRACTOR_EXPRBUILDER_H
7 changes: 6 additions & 1 deletion lib/Extractor/ExprBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ static llvm::cl::opt<souper::ExprBuilder::Builder> SMTExprBuilder(
llvm::cl::desc("SMT-LIBv2 expression builder (default=klee)"),
llvm::cl::values(clEnumValN(souper::ExprBuilder::KLEE, "klee",
"Use KLEE's Expr library")),
llvm::cl::init(souper::ExprBuilder::KLEE));
llvm::cl::values(clEnumValN(souper::ExprBuilder::Z3, "z3",
"Use Z3 API")),
llvm::cl::init(souper::ExprBuilder::Z3));

bool ExprBuilder::getUBPaths(Inst *I, UBPath *Current,
std::vector<std::unique_ptr<UBPath>> &Paths,
Expand Down Expand Up @@ -954,6 +956,9 @@ std::string BuildQuery(InstContext &IC, const BlockPCs &BPCs,
case ExprBuilder::KLEE:
EB = createKLEEBuilder(IC);
break;
case ExprBuilder::Z3:
EB = createZ3Builder(IC);
break;
default:
llvm::report_fatal_error("cannot reach here");
break;
Expand Down
Loading

0 comments on commit 7d806c4

Please sign in to comment.