about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-26 06:17:51 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-26 06:17:51 +0000
commit8e62069f6298f517f97a333bdc3a7b1c50adad64 (patch)
tree01d56b6c853307ed749c5a25a2c811abefd6d568 /lib
parent553e2871ba937a91da303190631daf627f83eabb (diff)
downloadklee-8e62069f6298f517f97a333bdc3a7b1c50adad64.tar.gz
More large integer support.
 - Allow constructing a ConstantExpr from an APInt, too painful otherwise.

 - Parser support for large integers.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@74278 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Core/Executor.cpp16
-rw-r--r--lib/Expr/ExprBuilder.cpp12
-rw-r--r--lib/Expr/Parser.cpp8
-rw-r--r--lib/Solver/STPBuilder.cpp1
4 files changed, 12 insertions, 25 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 1db9efe7..8f5b3daa 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -931,21 +931,7 @@ ref<klee::ConstantExpr> Executor::evalConstant(Constant *c) {
     return evalConstantExpr(ce);
   } else {
     if (const ConstantInt *ci = dyn_cast<ConstantInt>(c)) {
-      const APInt &Val = ci->getValue();
-      unsigned W = Val.getBitWidth();
-      
-      if (W <= 64)
-        return ConstantExpr::create(Val.getZExtValue(), W);
-
-      assert(0 && "FIXME: Untested!");
-      ref<ConstantExpr> Res = ConstantExpr::create(0, W);
-      for (unsigned i = 0; i < Val.getNumWords(); ++i) {
-        ref<ConstantExpr> Tmp = ConstantExpr::alloc(Val.getRawData()[i], W);
-        Tmp = Tmp->Shl(ConstantExpr::alloc(i * 64, W));
-        Res = Res->Or(Tmp);
-      }
-
-      return Res;
+      return ConstantExpr::alloc(ci->getValue());
     } else if (const ConstantFP *cf = dyn_cast<ConstantFP>(c)) {      
       switch(cf->getType()->getTypeID()) {
       case Type::FloatTyID: {
diff --git a/lib/Expr/ExprBuilder.cpp b/lib/Expr/ExprBuilder.cpp
index 68a7fefd..009e621e 100644
--- a/lib/Expr/ExprBuilder.cpp
+++ b/lib/Expr/ExprBuilder.cpp
@@ -19,8 +19,8 @@ ExprBuilder::~ExprBuilder() {
 
 namespace {
   class DefaultExprBuilder : public ExprBuilder {
-    virtual ref<Expr> Constant(uint64_t Value, Expr::Width W) {
-      return ConstantExpr::alloc(Value, W);
+    virtual ref<Expr> Constant(const llvm::APInt &Value) {
+      return ConstantExpr::alloc(Value);
     }
 
     virtual ref<Expr> NotOptimized(const ref<Expr> &Index) {
@@ -164,8 +164,8 @@ namespace {
       : Builder(_Builder), Base(_Base) {}
     ~ChainedBuilder() { delete Base; }
 
-    ref<Expr> Constant(uint64_t Value, Expr::Width W) {
-      return Base->Constant(Value, W);
+    ref<Expr> Constant(const llvm::APInt &Value) {
+      return Base->Constant(Value);
     }
 
     ref<Expr> NotOptimized(const ref<Expr> &Index) {
@@ -307,8 +307,8 @@ namespace {
     ConstantSpecializedExprBuilder(ExprBuilder *Base) : Builder(this, Base) {}
     ~ConstantSpecializedExprBuilder() {}
 
-    virtual ref<Expr> Constant(uint64_t Value, Expr::Width W) {
-      return Builder.Constant(Value, W);
+    virtual ref<Expr> Constant(const llvm::APInt &Value) {
+      return Builder.Constant(Value);
     }
 
     virtual ref<Expr> NotOptimized(const ref<Expr> &Index) {
diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp
index 2b9777cb..42e8af03 100644
--- a/lib/Expr/Parser.cpp
+++ b/lib/Expr/Parser.cpp
@@ -1462,7 +1462,7 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) {
   }
 
   // This is a simple but slow way to handle overflow.
-  APInt Val(std::max(64U, RadixBits * N), 0);
+  APInt Val(RadixBits * N, 0);
   APInt RadixVal(Val.getBitWidth(), Radix);
   APInt DigitVal(Val.getBitWidth(), 0);
   for (unsigned i=0; i<N; ++i) {
@@ -1496,9 +1496,11 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) {
     Val = -Val;
 
   if (Type < Val.getBitWidth())
-    Val = Val.trunc(Type);
+    Val.trunc(Type);
+  else if (Type > Val.getBitWidth())
+    Val.zext(Type);
 
-  return ExprResult(Builder->Constant(Val.getZExtValue(), Type));
+  return ExprResult(Builder->Constant(Val));
 }
 
 /// ParseTypeSpecifier - Parse a type specifier.
diff --git a/lib/Solver/STPBuilder.cpp b/lib/Solver/STPBuilder.cpp
index 2e313fb0..65ef24d1 100644
--- a/lib/Solver/STPBuilder.cpp
+++ b/lib/Solver/STPBuilder.cpp
@@ -479,7 +479,6 @@ ExprHandle STPBuilder::constructActual(ref<Expr> e, int *width_out) {
       return bvConst64(*width_out, CE->getZExtValue());
 
     // FIXME: Optimize?
-    assert(0 && "FIXME: Not tested!");
     ref<ConstantExpr> Tmp = CE;
     ExprHandle Res = bvConst64(64, Tmp->Extract(0, 64)->getZExtValue());
     for (unsigned i = (*width_out / 64) - 1; i; --i) {