Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Initial version of the z3 expression builder #441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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 @@ -396,7 +397,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 @@ -110,6 +111,7 @@ std::string BuildQuery(InstContext &IC, const BlockPCs &BPCs,
std::vector<Inst *> *ModelVars, Inst *Precondition, bool Negate=false);

std::unique_ptr<ExprBuilder> createKLEEBuilder(InstContext &IC);
std::unique_ptr<ExprBuilder> createZ3Builder(InstContext &IC);
Inst *getUBInstCondition(InstContext &IC, Inst *Root);
}

Expand Down
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 @@ -956,6 +958,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