about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-25 00:02:11 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-25 00:02:11 +0000
commitfabd71bf0a6dd89ce6fb8cea48380a52aad7edc4 (patch)
treec8af05db7ef87dc1cb75de8f5b78ff3bec2e6cde /lib/Core
parente42a614b850ce3f1ea008e2d0ba02c387eb0dccd (diff)
downloadklee-fabd71bf0a6dd89ce6fb8cea48380a52aad7edc4.tar.gz
Flesh out support for arbitrary bit widths in some key places (STP & constant
creation).
 - Not used yet.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@74142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Executor.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index aca9dd2a..1db9efe7 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -396,7 +396,15 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os,
       initializeGlobalObject(state, os, cs->getOperand(i), 
 			     offset + sl->getElementOffset(i));
   } else {
-    os->write(offset, evalConstant(c));
+    unsigned StoreBits = targetData->getTypeStoreSizeInBits(c->getType());
+    ref<ConstantExpr> C = evalConstant(c);
+
+    // Extend the constant if necessary;
+    assert(StoreBits >= C->getWidth() && "Invalid store size!");
+    if (StoreBits > C->getWidth())
+      C = ConstantExpr::alloc(0, StoreBits - C->getWidth())->Concat(C);
+
+    os->write(offset, C);
   }
 }
 
@@ -923,15 +931,21 @@ ref<klee::ConstantExpr> Executor::evalConstant(Constant *c) {
     return evalConstantExpr(ce);
   } else {
     if (const ConstantInt *ci = dyn_cast<ConstantInt>(c)) {
-      switch(ci->getBitWidth()) {
-      case  1: return ConstantExpr::create(ci->getZExtValue(), Expr::Bool);
-      case  8: return ConstantExpr::create(ci->getZExtValue(), Expr::Int8);
-      case 16: return ConstantExpr::create(ci->getZExtValue(), Expr::Int16);
-      case 32: return ConstantExpr::create(ci->getZExtValue(), Expr::Int32);
-      case 64: return ConstantExpr::create(ci->getZExtValue(), Expr::Int64);
-      default:
-        assert(0 && "XXX arbitrary bit width constants unhandled");
+      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;
     } else if (const ConstantFP *cf = dyn_cast<ConstantFP>(c)) {      
       switch(cf->getType()->getTypeID()) {
       case Type::FloatTyID: {