From 380ca8863db645f0c00843af2fef575b655783ff Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 14 Jun 2009 04:23:54 +0000 Subject: 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 --- include/klee/Expr.h | 32 +++++++++++++++++++++++++++----- include/klee/util/Assignment.h | 7 ++----- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'include') 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 Concat(const ref &RHS); @@ -936,21 +958,21 @@ COMPARISON_EXPR_CLASS(Sge) inline bool Expr::isZero() const { if (const ConstantExpr *CE = dyn_cast(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(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(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 inline bool Assignment::satisfies(InputIterator begin, InputIterator end) { AssignmentEvaluator v(*this); - for (; begin!=end; ++begin) { - ref res = v.visit(*begin); - ConstantExpr *CE = dyn_cast(res); - if (!CE || !CE->getConstantValue()) + for (; begin!=end; ++begin) + if (!v.visit(*begin)->isTrue()) return false; - } return true; } } -- cgit 1.4.1