Fine, go all of the way and check that the argument types are correct as well.
authorChris Lattner <sabre@nondot.org>
Sun, 15 Aug 2004 23:39:59 +0000 (23:39 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 15 Aug 2004 23:39:59 +0000 (23:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15797 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/JIT/JIT.cpp

index a2f2275384f2dca69d1d55c03d8e3974bc56aee5..e6fd470d3428d7ea67bf45f307196e247d050212 100644 (file)
@@ -64,22 +64,36 @@ GenericValue JIT::runFunction(Function *F,
   void *FPtr = getPointerToFunction(F);
   assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
   const Type *RetTy = F->getReturnType();
+  const FunctionType *FTy = F->getFunctionType();
 
   // Handle some common cases first.
   if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) {
-    if (ArgValues.size() == 3) {
-      int (*PF)(int, char **, const char **) =
-        (int(*)(int, char **, const char **))FPtr;
-      
-      // Call the function.
-      rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]),
-                     (const char **)GVTOP(ArgValues[2]));
-      return rv;
-    } else if (ArgValues.size() == 1) {
-      int (*PF)(int) = (int(*)(int))FPtr;
-      rv.IntVal = PF(ArgValues[0].IntVal);
-      return rv;
-    } else if (ArgValues.size() == 0) {
+    switch (ArgValues.size()) {
+    case 3:
+      if (FTy->getNumParams() == 3 && 
+          (FTy->getParamType(0) == Type::IntTy || 
+           FTy->getParamType(0) == Type::UIntTy) &&
+          isa<PointerType>(FTy->getParamType(1)) &&
+          isa<PointerType>(FTy->getParamType(2))) {
+        int (*PF)(int, char **, const char **) =
+          (int(*)(int, char **, const char **))FPtr;
+        
+        // Call the function.
+        rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]),
+                       (const char **)GVTOP(ArgValues[2]));
+        return rv;
+      }
+      break;
+    case 1:
+      if (FTy->getNumParams() == 1 &&
+          (FTy->getParamType(0) == Type::IntTy || 
+           FTy->getParamType(0) == Type::UIntTy)) {
+        int (*PF)(int) = (int(*)(int))FPtr;
+        rv.IntVal = PF(ArgValues[0].IntVal);
+        return rv;
+      }
+      break;
+    case 0:
       int (*PF)() = (int(*)())FPtr;
       rv.IntVal = PF();
       return rv;