diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-06-14 04:23:54 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-06-14 04:23:54 +0000 |
commit | 380ca8863db645f0c00843af2fef575b655783ff (patch) | |
tree | 843cb4a2e71da3d150d8360f6c293204923e1093 /include | |
parent | 92e1bf7b665a7f5ec682becb78e014e62d10beec (diff) | |
download | klee-380ca8863db645f0c00843af2fef575b655783ff.tar.gz |
Add several ConstantExpr utility functions and move clients over.
- Reducing uses of getConstantValue() so we can move to arbitrary precision constants. - No (intended) functionality change. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/klee/Expr.h | 32 | ||||
-rw-r--r-- | include/klee/util/Assignment.h | 7 |
2 files changed, 29 insertions, 10 deletions
diff --git a/include/klee/Expr.h b/include/klee/Expr.h index 192be985..9851d122 100644 --- a/include/klee/Expr.h +++ b/include/klee/Expr.h @@ -354,6 +354,28 @@ public: } static bool classof(const ConstantExpr *) { return true; } + /* Utility Functions */ + + /// isZero - Is this a constant zero. + bool isZero() const { return getConstantValue() == 0; } + + /// isTrue - Is this the true expression. + bool isTrue() const { + assert(getWidth() == Expr::Bool && "Invalid isTrue() call!"); + return getConstantValue() == 1; + } + + /// isFalse - Is this the false expression. + bool isFalse() const { + assert(getWidth() == Expr::Bool && "Invalid isTrue() call!"); + return getConstantValue() == 0; + } + + /// isAllOnes - Is this constant all ones. + bool isAllOnes() const { + return getConstantValue() == bits64::maxValueOfNBits(getWidth()); + } + /* Constant Operations */ ref<ConstantExpr> Concat(const ref<ConstantExpr> &RHS); @@ -936,21 +958,21 @@ COMPARISON_EXPR_CLASS(Sge) inline bool Expr::isZero() const { if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) - return CE->getConstantValue() == 0; + return CE->isZero(); return false; } inline bool Expr::isTrue() const { + assert(getWidth() == Expr::Bool && "Invalid isTrue() call!"); if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) - return (CE->getWidth() == Expr::Bool && - CE->getConstantValue() == 1); + return CE->isTrue(); return false; } inline bool Expr::isFalse() const { + assert(getWidth() == Expr::Bool && "Invalid isFalse() call!"); if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) - return (CE->getWidth() == Expr::Bool && - CE->getConstantValue() == 0); + return CE->isFalse(); return false; } diff --git a/include/klee/util/Assignment.h b/include/klee/util/Assignment.h index 458b8d8d..838d03bd 100644 --- a/include/klee/util/Assignment.h +++ b/include/klee/util/Assignment.h @@ -88,12 +88,9 @@ namespace klee { template<typename InputIterator> inline bool Assignment::satisfies(InputIterator begin, InputIterator end) { AssignmentEvaluator v(*this); - for (; begin!=end; ++begin) { - ref<Expr> res = v.visit(*begin); - ConstantExpr *CE = dyn_cast<ConstantExpr>(res); - if (!CE || !CE->getConstantValue()) + for (; begin!=end; ++begin) + if (!v.visit(*begin)->isTrue()) return false; - } return true; } } |