about summary refs log tree commit diff homepage
path: root/lib/Core/Context.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-28 07:59:09 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-28 07:59:09 +0000
commitf5e6b462646f5a20dd0e5f6c4befaa7b72d1e1ff (patch)
tree8c3a622ce7955e304134b2175813721b30a99005 /lib/Core/Context.cpp
parent4fcf6a3c9b87b02d73b6a2f55c17573ca7fc5bbc (diff)
downloadklee-f5e6b462646f5a20dd0e5f6c4befaa7b72d1e1ff.tar.gz
Move Machine constants into Context object, initialized based on the target
data.
 - This is the first step towards having KLEE be fully target independent, its not
   particularly beautiful but its expedient.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@77306 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core/Context.cpp')
-rw-r--r--lib/Core/Context.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/Core/Context.cpp b/lib/Core/Context.cpp
new file mode 100644
index 00000000..590b2080
--- /dev/null
+++ b/lib/Core/Context.cpp
@@ -0,0 +1,56 @@
+//===-- Context.cpp -------------------------------------------------------===//
+//
+//                     The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Context.h"
+
+#include "klee/Expr.h"
+
+#include "llvm/Type.h"
+#include "llvm/DerivedTypes.h"
+
+#include <cassert>
+
+using namespace klee;
+
+static bool Initialized = false;
+static Context TheContext;
+
+void Context::initialize(bool IsLittleEndian, Expr::Width PointerWidth) {
+  assert(!Initialized && "Duplicate context initialization!");
+  TheContext = Context(IsLittleEndian, PointerWidth);
+  Initialized = true;
+}
+
+const Context &Context::get() {
+  assert(Initialized && "Context has not been initialized!");
+  return TheContext;
+}
+
+// FIXME: This is a total hack, just to avoid a layering issue until this stuff
+// moves out of Expr.
+
+Expr::Width Expr::getWidthForLLVMType(const llvm::Type *t) {
+  switch (t->getTypeID()) {
+  default:
+    assert(0 && "non-primitive type argument to Expr::getTypeForLLVMType()\n");
+  case llvm::Type::IntegerTyID: return cast<llvm::IntegerType>(t)->getBitWidth();
+  case llvm::Type::FloatTyID: return Expr::Int32;
+  case llvm::Type::DoubleTyID: return Expr::Int64;
+  case llvm::Type::X86_FP80TyID: return 80;
+  case llvm::Type::PointerTyID: return Context::get().getPointerWidth();
+  }
+}
+
+ref<Expr> Expr::createCoerceToPointerType(ref<Expr> e) {
+  return ZExtExpr::create(e, Context::get().getPointerWidth());
+}
+
+ref<ConstantExpr> Expr::createPointer(uint64_t v) {
+  return ConstantExpr::create(v, Context::get().getPointerWidth());
+}