mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-11 21:38:19 +00:00
Link against libffi if available, fall back to "no external calls from
interpreter mode" when it's not. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68937 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -289,6 +289,3 @@ endif
|
|||||||
|
|
||||||
# Location of the plugin header file for gold.
|
# Location of the plugin header file for gold.
|
||||||
BINUTILS_INCDIR := @BINUTILS_INCDIR@
|
BINUTILS_INCDIR := @BINUTILS_INCDIR@
|
||||||
|
|
||||||
# Can we use libFFI for the interpreter?
|
|
||||||
HAVE_FFI := @HAVE_FFI@
|
|
||||||
|
@ -737,8 +737,9 @@ AC_SEARCH_LIBS(dlopen,dl,AC_DEFINE([HAVE_DLOPEN],[1],
|
|||||||
AC_MSG_WARN([dlopen() not found - disabling plugin support]))
|
AC_MSG_WARN([dlopen() not found - disabling plugin support]))
|
||||||
|
|
||||||
dnl libffi is optional; used to call external functions from the interpreter
|
dnl libffi is optional; used to call external functions from the interpreter
|
||||||
AC_CHECK_LIB(ffi,ffi_call,[have_libffi=1],
|
AC_SEARCH_LIBS(ffi_call,ffi,AC_DEFINE([HAVE_FFI_CALL],[1],
|
||||||
AC_MSG_WARN([libffi not found - disabling external calls from interpreter]))
|
[Define if libffi is available on this platform.]),
|
||||||
|
AC_MSG_WARN([libffi not found - disabling external calls from interpreter]))
|
||||||
|
|
||||||
dnl mallinfo is optional; the code can compile (minus features) without it
|
dnl mallinfo is optional; the code can compile (minus features) without it
|
||||||
AC_SEARCH_LIBS(mallinfo,malloc,AC_DEFINE([HAVE_MALLINFO],[1],
|
AC_SEARCH_LIBS(mallinfo,malloc,AC_DEFINE([HAVE_MALLINFO],[1],
|
||||||
@ -802,10 +803,8 @@ else
|
|||||||
AC_SUBST(HAVE_PTHREAD, 0)
|
AC_SUBST(HAVE_PTHREAD, 0)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl Once we know we have libffi, try to find ffi.h.
|
dnl Try to find ffi.h.
|
||||||
if test -n "$have_libffi" ; then
|
AC_CHECK_HEADERS([ffi.h ffi/ffi.h])
|
||||||
AC_CHECK_HEADERS([ffi.h ffi/ffi.h], [AC_SUBST(HAVE_FFI, 1)])
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl===-----------------------------------------------------------------------===
|
dnl===-----------------------------------------------------------------------===
|
||||||
dnl===
|
dnl===
|
||||||
|
@ -33,13 +33,13 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef HAVE_FFI
|
#ifdef HAVE_FFI_CALL
|
||||||
#ifdef HAVE_FFI_H
|
#ifdef HAVE_FFI_H
|
||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
|
#define USE_LIBFFI
|
||||||
#elif HAVE_FFI_FFI_H
|
#elif HAVE_FFI_FFI_H
|
||||||
#include <ffi/ffi.h>
|
#include <ffi/ffi.h>
|
||||||
#else
|
#define USE_LIBFFI
|
||||||
#error "Not sure where configure found ffi.h!"
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ typedef GenericValue (*ExFunc)(const FunctionType *,
|
|||||||
static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
|
static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
|
||||||
static std::map<std::string, ExFunc> FuncNames;
|
static std::map<std::string, ExFunc> FuncNames;
|
||||||
|
|
||||||
#ifdef HAVE_FFI
|
#ifdef USE_LIBFFI
|
||||||
typedef void (*RawFunc)(void);
|
typedef void (*RawFunc)(void);
|
||||||
static ManagedStatic<std::map<const Function *, RawFunc> > RawFunctions;
|
static ManagedStatic<std::map<const Function *, RawFunc> > RawFunctions;
|
||||||
#endif
|
#endif
|
||||||
@ -105,7 +105,7 @@ static ExFunc lookupFunction(const Function *F) {
|
|||||||
return FnPtr;
|
return FnPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FFI
|
#ifdef USE_LIBFFI
|
||||||
static ffi_type *ffiTypeFor(const Type *Ty) {
|
static ffi_type *ffiTypeFor(const Type *Ty) {
|
||||||
switch (Ty->getTypeID()) {
|
switch (Ty->getTypeID()) {
|
||||||
case Type::VoidTyID: return &ffi_type_void;
|
case Type::VoidTyID: return &ffi_type_void;
|
||||||
@ -240,7 +240,7 @@ static bool ffiInvoke(RawFunc Fn, Function *F,
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif // HAVE_FFI
|
#endif // USE_LIBFFI
|
||||||
|
|
||||||
GenericValue Interpreter::callExternalFunction(Function *F,
|
GenericValue Interpreter::callExternalFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgVals) {
|
const std::vector<GenericValue> &ArgVals) {
|
||||||
@ -253,7 +253,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
|
|||||||
: FI->second)
|
: FI->second)
|
||||||
return Fn(F->getFunctionType(), ArgVals);
|
return Fn(F->getFunctionType(), ArgVals);
|
||||||
|
|
||||||
#ifdef HAVE_FFI
|
#ifdef USE_LIBFFI
|
||||||
std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
|
std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
|
||||||
RawFunc RawFn;
|
RawFunc RawFn;
|
||||||
if (RF == RawFunctions->end()) {
|
if (RF == RawFunctions->end()) {
|
||||||
@ -268,7 +268,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
|
|||||||
GenericValue Result;
|
GenericValue Result;
|
||||||
if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
|
if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getTargetData(), Result))
|
||||||
return Result;
|
return Result;
|
||||||
#endif // HAVE_FFI
|
#endif // USE_LIBFFI
|
||||||
|
|
||||||
cerr << "Tried to execute an unknown external function: "
|
cerr << "Tried to execute an unknown external function: "
|
||||||
<< F->getType()->getDescription() << " " << F->getName() << "\n";
|
<< F->getType()->getDescription() << " " << F->getName() << "\n";
|
||||||
|
Reference in New Issue
Block a user