#include <cmath>
#include <cstring>
-#ifdef HAVE_LIBFFI
-#include FFI_HEADER
+#ifdef HAVE_FFI_CALL
+#ifdef HAVE_FFI_H
+#include <ffi.h>
+#define USE_LIBFFI
+#elif HAVE_FFI_FFI_H
+#include <ffi/ffi.h>
+#define USE_LIBFFI
+#endif
#endif
using namespace llvm;
static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
static std::map<std::string, ExFunc> FuncNames;
-#ifdef HAVE_LIBFFI
+#ifdef USE_LIBFFI
typedef void (*RawFunc)(void);
static ManagedStatic<std::map<const Function *, RawFunc> > RawFunctions;
-#endif // HAVE_LIBFFI
+#endif
static Interpreter *TheInterpreter;
return FnPtr;
}
-#ifdef HAVE_LIBFFI
+#ifdef USE_LIBFFI
static ffi_type *ffiTypeFor(const Type *Ty) {
switch (Ty->getTypeID()) {
case Type::VoidTyID: return &ffi_type_void;
}
case Type::FloatTyID: {
float *FloatPtr = (float *) ArgDataPtr;
- *FloatPtr = AV.FloatVal;
+ *FloatPtr = AV.DoubleVal;
return ArgDataPtr;
}
case Type::DoubleTyID: {
return false;
}
-#endif // HAVE_LIBFFI
+#endif // USE_LIBFFI
GenericValue Interpreter::callExternalFunction(Function *F,
const std::vector<GenericValue> &ArgVals) {
: FI->second)
return Fn(F->getFunctionType(), ArgVals);
-#ifdef HAVE_LIBFFI
+#ifdef USE_LIBFFI
std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
RawFunc RawFn;
if (RF == RawFunctions->end()) {
GenericValue Result;
if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
return Result;
-#endif // HAVE_LIBFFI
+#endif // USE_LIBFFI
cerr << "Tried to execute an unknown external function: "
<< F->getType()->getDescription() << " " << F->getName() << "\n";