Reapply patch from r62553, with a fix to avoid looking for an ffi.h that isn't
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / ExternalFunctions.cpp
index 9f44a63654cbcfa030eadddff53c2d2de78c6e09..36de08358acf89e8b6b4cf13c75d0864fdffb220 100644 (file)
 #include <cmath>
 #include <cstring>
 
-#ifdef HAVE_LIBFFI
-#include FFI_HEADER
+#ifdef HAVE_FFI
+#ifdef HAVE_FFI_H
+#include <ffi.h>
+#elif HAVE_FFI_FFI_H
+#include <ffi/ffi.h>
+#else
+#error "Not sure where configure found ffi.h!"
+#endif
 #endif
 
 using namespace llvm;
@@ -44,10 +50,10 @@ typedef GenericValue (*ExFunc)(const FunctionType *,
 static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
 static std::map<std::string, ExFunc> FuncNames;
 
-#ifdef HAVE_LIBFFI
+#ifdef HAVE_FFI
 typedef void (*RawFunc)(void);
 static ManagedStatic<std::map<const Function *, RawFunc> > RawFunctions;
-#endif // HAVE_LIBFFI
+#endif
 
 static Interpreter *TheInterpreter;
 
@@ -99,7 +105,7 @@ static ExFunc lookupFunction(const Function *F) {
   return FnPtr;
 }
 
-#ifdef HAVE_LIBFFI
+#ifdef HAVE_FFI
 static ffi_type *ffiTypeFor(const Type *Ty) {
   switch (Ty->getTypeID()) {
     case Type::VoidTyID: return &ffi_type_void;
@@ -149,7 +155,7 @@ static void *ffiValueFor(const Type *Ty, const GenericValue &AV,
       }
     case Type::FloatTyID: {
       float *FloatPtr = (float *) ArgDataPtr;
-      *FloatPtr = AV.FloatVal;
+      *FloatPtr = AV.DoubleVal;
       return ArgDataPtr;
     }
     case Type::DoubleTyID: {
@@ -234,7 +240,7 @@ static bool ffiInvoke(RawFunc Fn, Function *F,
 
   return false;
 }
-#endif // HAVE_LIBFFI
+#endif // HAVE_FFI
 
 GenericValue Interpreter::callExternalFunction(Function *F,
                                      const std::vector<GenericValue> &ArgVals) {
@@ -247,7 +253,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
                                                    : FI->second)
     return Fn(F->getFunctionType(), ArgVals);
 
-#ifdef HAVE_LIBFFI
+#ifdef HAVE_FFI
   std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
   RawFunc RawFn;
   if (RF == RawFunctions->end()) {
@@ -262,7 +268,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
   GenericValue Result;
   if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
     return Result;
-#endif // HAVE_LIBFFI
+#endif // HAVE_FFI
 
   cerr << "Tried to execute an unknown external function: "
        << F->getType()->getDescription() << " " << F->getName() << "\n";