mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-01 02:33:44 +00:00
Stop using alloca.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82225 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e2394e9bfe
commit
7de3bd273e
@ -33,10 +33,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
// Some platforms may need malloc.h for alloca.
|
|
||||||
#ifdef HAVE_MALLOC_H
|
|
||||||
#include <malloc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_FFI_CALL
|
#ifdef HAVE_FFI_CALL
|
||||||
#ifdef HAVE_FFI_H
|
#ifdef HAVE_FFI_H
|
||||||
@ -207,9 +203,10 @@ static bool ffiInvoke(RawFunc Fn, Function *F,
|
|||||||
ArgBytes += TD->getTypeStoreSize(ArgTy);
|
ArgBytes += TD->getTypeStoreSize(ArgTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *ArgData = (uint8_t*) alloca(ArgBytes);
|
SmallVector<uint8_t, 128> ArgData;
|
||||||
uint8_t *ArgDataPtr = ArgData;
|
ArgData.resize(ArgBytes);
|
||||||
std::vector<void*> values(NumArgs);
|
uint8_t *ArgDataPtr = ArgData.data();
|
||||||
|
SmallVector<void*, 16> values(NumArgs);
|
||||||
for (Function::const_arg_iterator A = F->arg_begin(), E = F->arg_end();
|
for (Function::const_arg_iterator A = F->arg_begin(), E = F->arg_end();
|
||||||
A != E; ++A) {
|
A != E; ++A) {
|
||||||
const unsigned ArgNo = A->getArgNo();
|
const unsigned ArgNo = A->getArgNo();
|
||||||
@ -222,22 +219,22 @@ static bool ffiInvoke(RawFunc Fn, Function *F,
|
|||||||
ffi_type *rtype = ffiTypeFor(RetTy);
|
ffi_type *rtype = ffiTypeFor(RetTy);
|
||||||
|
|
||||||
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, &args[0]) == FFI_OK) {
|
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, &args[0]) == FFI_OK) {
|
||||||
void *ret = NULL;
|
SmallVector<uint8_t, 128> ret;
|
||||||
if (RetTy->getTypeID() != Type::VoidTyID)
|
if (RetTy->getTypeID() != Type::VoidTyID)
|
||||||
ret = alloca(TD->getTypeStoreSize(RetTy));
|
ret.resize(TD->getTypeStoreSize(RetTy));
|
||||||
ffi_call(&cif, Fn, ret, &values[0]);
|
ffi_call(&cif, Fn, ret.data(), values.data());
|
||||||
switch (RetTy->getTypeID()) {
|
switch (RetTy->getTypeID()) {
|
||||||
case Type::IntegerTyID:
|
case Type::IntegerTyID:
|
||||||
switch (cast<IntegerType>(RetTy)->getBitWidth()) {
|
switch (cast<IntegerType>(RetTy)->getBitWidth()) {
|
||||||
case 8: Result.IntVal = APInt(8 , *(int8_t *) ret); break;
|
case 8: Result.IntVal = APInt(8 , *(int8_t *) ret.data()); break;
|
||||||
case 16: Result.IntVal = APInt(16, *(int16_t*) ret); break;
|
case 16: Result.IntVal = APInt(16, *(int16_t*) ret.data()); break;
|
||||||
case 32: Result.IntVal = APInt(32, *(int32_t*) ret); break;
|
case 32: Result.IntVal = APInt(32, *(int32_t*) ret.data()); break;
|
||||||
case 64: Result.IntVal = APInt(64, *(int64_t*) ret); break;
|
case 64: Result.IntVal = APInt(64, *(int64_t*) ret.data()); break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Type::FloatTyID: Result.FloatVal = *(float *) ret; break;
|
case Type::FloatTyID: Result.FloatVal = *(float *) ret.data(); break;
|
||||||
case Type::DoubleTyID: Result.DoubleVal = *(double*) ret; break;
|
case Type::DoubleTyID: Result.DoubleVal = *(double*) ret.data(); break;
|
||||||
case Type::PointerTyID: Result.PointerVal = *(void **) ret; break;
|
case Type::PointerTyID: Result.PointerVal = *(void **) ret.data(); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user