From 8d89546353180aa51484c27be68ffb0bb10583cd Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Mon, 1 Apr 2019 14:08:43 +0100 Subject: Clean-up and add documentation --- include/klee/Expr/Constraints.h | 24 +++++++++++++++++------- include/klee/Solver/Solver.h | 7 ++++--- lib/Expr/Constraints.cpp | 41 +++++++++++++++++++---------------------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/include/klee/Expr/Constraints.h b/include/klee/Expr/Constraints.h index ae0f86f2..a9a1ce70 100644 --- a/include/klee/Expr/Constraints.h +++ b/include/klee/Expr/Constraints.h @@ -24,7 +24,7 @@ public: using iterator = constraints_ty::iterator; using const_iterator = constraints_ty::const_iterator; - typedef const_iterator constraint_iterator; + using constraint_iterator = const_iterator; bool empty() const; constraint_iterator begin() const; @@ -49,20 +49,30 @@ class ExprVisitor; /// Manages constraints, e.g. optimisation class ConstraintManager { public: - // create from constraints with no optimization + /// Create constraint manager that modifies constraints + /// \param constraints explicit ConstraintManager(ConstraintSet &constraints); + /// Simplify expression expr based on constraints + /// \param constraints set of constraints used for simplification + /// \param expr to simplify + /// \return simplified expression static ref simplifyExpr(const ConstraintSet &constraints, - const ref &e); + const ref &expr); - void addConstraint(ref e); + /// Add constraint to the referenced constraint set + /// \param constraint + void addConstraint(const ref &constraint); - // returns true iff the constraints were modified +private: + /// Rewrite set of constraints using the visitor + /// \param visitor constraint rewriter + /// \return true iff any constraint has been changed bool rewriteConstraints(ExprVisitor &visitor); - void addConstraintInternal(ref e); + /// Add constraint to the set of constraints + void addConstraintInternal(const ref &constraint); -private: ConstraintSet &constraints; }; diff --git a/include/klee/Solver/Solver.h b/include/klee/Solver/Solver.h index 8d5f87d5..263f1626 100644 --- a/include/klee/Solver/Solver.h +++ b/include/klee/Solver/Solver.h @@ -21,10 +21,11 @@ namespace klee { class Expr; class SolverImpl; - /// Collection of meta data used by a solver - /// + /// Collection of meta data that a solver can have access to. This is + /// independent of the actual constraints but can be used as a two-way + /// communication between solver and context of query. struct SolverQueryMetaData { - /// @brief Costs for all queries issued for this state, in seconds + /// @brief Costs for all queries issued for this state time::Span queryCost; }; diff --git a/lib/Expr/Constraints.cpp b/lib/Expr/Constraints.cpp index 6b576435..2a4c2adb 100644 --- a/lib/Expr/Constraints.cpp +++ b/lib/Expr/Constraints.cpp @@ -9,10 +9,9 @@ #include "klee/Expr/Constraints.h" -#include "klee/Expr/ExprPPrinter.h" #include "klee/Expr/ExprVisitor.h" -#include "klee/Support/OptionCategories.h" #include "klee/Module/KModule.h" +#include "klee/Support/OptionCategories.h" #include "llvm/IR/Function.h" #include "llvm/Support/CommandLine.h" @@ -28,29 +27,28 @@ llvm::cl::opt RewriteEqualities( "constant is added (default=true)"), llvm::cl::init(true), llvm::cl::cat(SolvingCat)); -} +} // namespace class ExprReplaceVisitor : public ExprVisitor { private: ref src, dst; public: - ExprReplaceVisitor(ref _src, ref _dst) : src(_src), dst(_dst) {} + ExprReplaceVisitor(const ref &_src, const ref &_dst) + : src(_src), dst(_dst) {} - Action visitExpr(const Expr &e) { - if (e == *src.get()) { + Action visitExpr(const Expr &e) override { + if (e == *src) { return Action::changeTo(dst); - } else { - return Action::doChildren(); } + return Action::doChildren(); } - Action visitExprPost(const Expr &e) { - if (e == *src.get()) { + Action visitExprPost(const Expr &e) override { + if (e == *src) { return Action::changeTo(dst); - } else { - return Action::doChildren(); } + return Action::doChildren(); } }; @@ -59,17 +57,16 @@ private: const std::map< ref, ref > &replacements; public: - ExprReplaceVisitor2(const std::map, ref> &_replacements) + explicit ExprReplaceVisitor2( + const std::map, ref> &_replacements) : ExprVisitor(true), replacements(_replacements) {} - Action visitExprPost(const Expr &e) { - std::map< ref, ref >::const_iterator it = - replacements.find(ref(const_cast(&e))); + Action visitExprPost(const Expr &e) override { + auto it = replacements.find(ref(const_cast(&e))); if (it!=replacements.end()) { return Action::changeTo(it->second); - } else { - return Action::doChildren(); } + return Action::doChildren(); } }; @@ -118,7 +115,7 @@ ref ConstraintManager::simplifyExpr(const ConstraintSet &constraints, return ExprReplaceVisitor2(equalities).visit(e); } -void ConstraintManager::addConstraintInternal(ref e) { +void ConstraintManager::addConstraintInternal(const ref &e) { // rewrite any known equalities and split Ands into different conjuncts switch (e->getKind()) { @@ -158,9 +155,9 @@ void ConstraintManager::addConstraintInternal(ref e) { } } -void ConstraintManager::addConstraint(ref e) { - e = simplifyExpr(constraints, e); - addConstraintInternal(e); +void ConstraintManager::addConstraint(const ref &e) { + ref simplified = simplifyExpr(constraints, e); + addConstraintInternal(simplified); } ConstraintManager::ConstraintManager(ConstraintSet &_constraints) -- cgit 1.4.1