about summary refs log tree commit diff homepage
path: root/include
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-14 06:07:30 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-14 06:07:30 +0000
commit7c27c8a6a7c233c3c6162d9b86942351fe5f42b3 (patch)
tree876b610183e2e4d470139b8544cd6cdbf22a6982 /include
parentd15a30cc0ce2579747ae4c2e919af54c6b06af70 (diff)
downloadklee-7c27c8a6a7c233c3c6162d9b86942351fe5f42b3.tar.gz
Add ConstantExpr::{getLimitedValue,getZExtValue}.
 - For use in situations where the range of the constant is known to fit in a
   uint64 (or smaller), or the extra bits don't matter.

 - No (intended) functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73326 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/klee/Expr.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/include/klee/Expr.h b/include/klee/Expr.h
index 70d9abfc..69f9f1df 100644
--- a/include/klee/Expr.h
+++ b/include/klee/Expr.h
@@ -314,6 +314,21 @@ public:
 
   uint64_t getConstantValue() const { return value; }
 
+  /// getZExtValue - Return the constant value for a limited number of bits.
+  ///
+  /// This routine should be used in situations where the width of the constant
+  /// is known to be limited to a certain number of bits.
+  uint64_t getZExtValue(unsigned bits = 64) const {
+    assert(getWidth() <= bits && "Value may be out of range!");
+    return value;
+  }
+
+  /// getLimitedValue - If this value is smaller than the specified limit,
+  /// return it, otherwise return the limit value.
+  uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
+    return (value > Limit) ? Limit :  getZExtValue();
+  }
+
   int compareContents(const Expr &b) const { 
     const ConstantExpr &cb = static_cast<const ConstantExpr&>(b);
     if (width != cb.width) return width < cb.width ? -1 : 1;
@@ -357,23 +372,24 @@ public:
   /* Utility Functions */
 
   /// isZero - Is this a constant zero.
-  bool isZero() const { return getConstantValue() == 0; }
+  bool isZero() const { return getZExtValue() == 0; }
+
+  /// isOne - Is this a constant one.
+  bool isOne() const { return getZExtValue() == 1; }
   
   /// isTrue - Is this the true expression.
   bool isTrue() const { 
-    assert(getWidth() == Expr::Bool && "Invalid isTrue() call!");
-    return getConstantValue() == 1;
+    return getZExtValue(1) == 1;
   }
 
   /// isFalse - Is this the false expression.
   bool isFalse() const {
-    assert(getWidth() == Expr::Bool && "Invalid isTrue() call!");
-    return getConstantValue() == 0;
+    return getZExtValue(1) == 0;
   }
 
   /// isAllOnes - Is this constant all ones.
   bool isAllOnes() const {
-    return getConstantValue() == bits64::maxValueOfNBits(getWidth());
+    return getZExtValue(getWidth()) == bits64::maxValueOfNBits(getWidth());
   }
 
   /* Constant Operations */