mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
[ExecutionEngine] ArrayRefize argument passing.
No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239687 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -205,7 +205,7 @@ public:
|
|||||||
/// runFunction - Execute the specified function with the specified arguments,
|
/// runFunction - Execute the specified function with the specified arguments,
|
||||||
/// and return the result.
|
/// and return the result.
|
||||||
virtual GenericValue runFunction(Function *F,
|
virtual GenericValue runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues) = 0;
|
ArrayRef<GenericValue> ArgValues) = 0;
|
||||||
|
|
||||||
/// getPointerToNamedFunction - This method returns the address of the
|
/// getPointerToNamedFunction - This method returns the address of the
|
||||||
/// specified function by using the dlsym function call. As such it is only
|
/// specified function by using the dlsym function call. As such it is only
|
||||||
|
@@ -376,7 +376,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
|
|||||||
|
|
||||||
// Execute the ctor/dtor function!
|
// Execute the ctor/dtor function!
|
||||||
if (Function *F = dyn_cast<Function>(FP))
|
if (Function *F = dyn_cast<Function>(FP))
|
||||||
runFunction(F, std::vector<GenericValue>());
|
runFunction(F, None);
|
||||||
|
|
||||||
// FIXME: It is marginally lame that we just do nothing here if we see an
|
// FIXME: It is marginally lame that we just do nothing here if we see an
|
||||||
// entry we don't recognize. It might not be unreasonable for the verifier
|
// entry we don't recognize. It might not be unreasonable for the verifier
|
||||||
|
@@ -2073,8 +2073,7 @@ GenericValue Interpreter::getOperandValue(Value *V, ExecutionContext &SF) {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// callFunction - Execute the specified function...
|
// callFunction - Execute the specified function...
|
||||||
//
|
//
|
||||||
void Interpreter::callFunction(Function *F,
|
void Interpreter::callFunction(Function *F, ArrayRef<GenericValue> ArgVals) {
|
||||||
const std::vector<GenericValue> &ArgVals) {
|
|
||||||
assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
|
assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
|
||||||
ECStack.back().Caller.arg_size() == ArgVals.size()) &&
|
ECStack.back().Caller.arg_size() == ArgVals.size()) &&
|
||||||
"Incorrect number of arguments passed into function call!");
|
"Incorrect number of arguments passed into function call!");
|
||||||
|
@@ -49,8 +49,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
static ManagedStatic<sys::Mutex> FunctionsLock;
|
static ManagedStatic<sys::Mutex> FunctionsLock;
|
||||||
|
|
||||||
typedef GenericValue (*ExFunc)(FunctionType *,
|
typedef GenericValue (*ExFunc)(FunctionType *, ArrayRef<GenericValue>);
|
||||||
const std::vector<GenericValue> &);
|
|
||||||
static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
|
static ManagedStatic<std::map<const Function *, ExFunc> > ExportedFunctions;
|
||||||
static ManagedStatic<std::map<std::string, ExFunc> > FuncNames;
|
static ManagedStatic<std::map<std::string, ExFunc> > FuncNames;
|
||||||
|
|
||||||
@@ -178,8 +177,7 @@ static void *ffiValueFor(Type *Ty, const GenericValue &AV,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ffiInvoke(RawFunc Fn, Function *F,
|
static bool ffiInvoke(RawFunc Fn, Function *F, ArrayRef<GenericValue> ArgVals,
|
||||||
const std::vector<GenericValue> &ArgVals,
|
|
||||||
const DataLayout *TD, GenericValue &Result) {
|
const DataLayout *TD, GenericValue &Result) {
|
||||||
ffi_cif cif;
|
ffi_cif cif;
|
||||||
FunctionType *FTy = F->getFunctionType();
|
FunctionType *FTy = F->getFunctionType();
|
||||||
@@ -245,7 +243,7 @@ static bool ffiInvoke(RawFunc Fn, Function *F,
|
|||||||
#endif // USE_LIBFFI
|
#endif // USE_LIBFFI
|
||||||
|
|
||||||
GenericValue Interpreter::callExternalFunction(Function *F,
|
GenericValue Interpreter::callExternalFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgVals) {
|
ArrayRef<GenericValue> ArgVals) {
|
||||||
TheInterpreter = this;
|
TheInterpreter = this;
|
||||||
|
|
||||||
unique_lock<sys::Mutex> Guard(*FunctionsLock);
|
unique_lock<sys::Mutex> Guard(*FunctionsLock);
|
||||||
@@ -298,9 +296,8 @@ GenericValue Interpreter::callExternalFunction(Function *F,
|
|||||||
//
|
//
|
||||||
|
|
||||||
// void atexit(Function*)
|
// void atexit(Function*)
|
||||||
static
|
static GenericValue lle_X_atexit(FunctionType *FT,
|
||||||
GenericValue lle_X_atexit(FunctionType *FT,
|
ArrayRef<GenericValue> Args) {
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
|
TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
@@ -309,17 +306,13 @@ GenericValue lle_X_atexit(FunctionType *FT,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// void exit(int)
|
// void exit(int)
|
||||||
static
|
static GenericValue lle_X_exit(FunctionType *FT, ArrayRef<GenericValue> Args) {
|
||||||
GenericValue lle_X_exit(FunctionType *FT,
|
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
TheInterpreter->exitCalled(Args[0]);
|
TheInterpreter->exitCalled(Args[0]);
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void abort(void)
|
// void abort(void)
|
||||||
static
|
static GenericValue lle_X_abort(FunctionType *FT, ArrayRef<GenericValue> Args) {
|
||||||
GenericValue lle_X_abort(FunctionType *FT,
|
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
//FIXME: should we report or raise here?
|
//FIXME: should we report or raise here?
|
||||||
//report_fatal_error("Interpreted program raised SIGABRT");
|
//report_fatal_error("Interpreted program raised SIGABRT");
|
||||||
raise (SIGABRT);
|
raise (SIGABRT);
|
||||||
@@ -328,9 +321,8 @@ GenericValue lle_X_abort(FunctionType *FT,
|
|||||||
|
|
||||||
// int sprintf(char *, const char *, ...) - a very rough implementation to make
|
// int sprintf(char *, const char *, ...) - a very rough implementation to make
|
||||||
// output useful.
|
// output useful.
|
||||||
static
|
static GenericValue lle_X_sprintf(FunctionType *FT,
|
||||||
GenericValue lle_X_sprintf(FunctionType *FT,
|
ArrayRef<GenericValue> Args) {
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
char *OutputBuffer = (char *)GVTOP(Args[0]);
|
char *OutputBuffer = (char *)GVTOP(Args[0]);
|
||||||
const char *FmtStr = (const char *)GVTOP(Args[1]);
|
const char *FmtStr = (const char *)GVTOP(Args[1]);
|
||||||
unsigned ArgNo = 2;
|
unsigned ArgNo = 2;
|
||||||
@@ -411,9 +403,8 @@ GenericValue lle_X_sprintf(FunctionType *FT,
|
|||||||
|
|
||||||
// int printf(const char *, ...) - a very rough implementation to make output
|
// int printf(const char *, ...) - a very rough implementation to make output
|
||||||
// useful.
|
// useful.
|
||||||
static
|
static GenericValue lle_X_printf(FunctionType *FT,
|
||||||
GenericValue lle_X_printf(FunctionType *FT,
|
ArrayRef<GenericValue> Args) {
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
char Buffer[10000];
|
char Buffer[10000];
|
||||||
std::vector<GenericValue> NewArgs;
|
std::vector<GenericValue> NewArgs;
|
||||||
NewArgs.push_back(PTOGV((void*)&Buffer[0]));
|
NewArgs.push_back(PTOGV((void*)&Buffer[0]));
|
||||||
@@ -424,9 +415,8 @@ GenericValue lle_X_printf(FunctionType *FT,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// int sscanf(const char *format, ...);
|
// int sscanf(const char *format, ...);
|
||||||
static
|
static GenericValue lle_X_sscanf(FunctionType *FT,
|
||||||
GenericValue lle_X_sscanf(FunctionType *FT,
|
ArrayRef<GenericValue> args) {
|
||||||
const std::vector<GenericValue> &args) {
|
|
||||||
assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
|
assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
|
||||||
|
|
||||||
char *Args[10];
|
char *Args[10];
|
||||||
@@ -440,9 +430,7 @@ GenericValue lle_X_sscanf(FunctionType *FT,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// int scanf(const char *format, ...);
|
// int scanf(const char *format, ...);
|
||||||
static
|
static GenericValue lle_X_scanf(FunctionType *FT, ArrayRef<GenericValue> args) {
|
||||||
GenericValue lle_X_scanf(FunctionType *FT,
|
|
||||||
const std::vector<GenericValue> &args) {
|
|
||||||
assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
|
assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
|
||||||
|
|
||||||
char *Args[10];
|
char *Args[10];
|
||||||
@@ -457,9 +445,8 @@ GenericValue lle_X_scanf(FunctionType *FT,
|
|||||||
|
|
||||||
// int fprintf(FILE *, const char *, ...) - a very rough implementation to make
|
// int fprintf(FILE *, const char *, ...) - a very rough implementation to make
|
||||||
// output useful.
|
// output useful.
|
||||||
static
|
static GenericValue lle_X_fprintf(FunctionType *FT,
|
||||||
GenericValue lle_X_fprintf(FunctionType *FT,
|
ArrayRef<GenericValue> Args) {
|
||||||
const std::vector<GenericValue> &Args) {
|
|
||||||
assert(Args.size() >= 2);
|
assert(Args.size() >= 2);
|
||||||
char Buffer[10000];
|
char Buffer[10000];
|
||||||
std::vector<GenericValue> NewArgs;
|
std::vector<GenericValue> NewArgs;
|
||||||
@@ -472,7 +459,7 @@ GenericValue lle_X_fprintf(FunctionType *FT,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GenericValue lle_X_memset(FunctionType *FT,
|
static GenericValue lle_X_memset(FunctionType *FT,
|
||||||
const std::vector<GenericValue> &Args) {
|
ArrayRef<GenericValue> Args) {
|
||||||
int val = (int)Args[1].IntVal.getSExtValue();
|
int val = (int)Args[1].IntVal.getSExtValue();
|
||||||
size_t len = (size_t)Args[2].IntVal.getZExtValue();
|
size_t len = (size_t)Args[2].IntVal.getZExtValue();
|
||||||
memset((void *)GVTOP(Args[0]), val, len);
|
memset((void *)GVTOP(Args[0]), val, len);
|
||||||
@@ -484,7 +471,7 @@ static GenericValue lle_X_memset(FunctionType *FT,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GenericValue lle_X_memcpy(FunctionType *FT,
|
static GenericValue lle_X_memcpy(FunctionType *FT,
|
||||||
const std::vector<GenericValue> &Args) {
|
ArrayRef<GenericValue> Args) {
|
||||||
memcpy(GVTOP(Args[0]), GVTOP(Args[1]),
|
memcpy(GVTOP(Args[0]), GVTOP(Args[1]),
|
||||||
(size_t)(Args[2].IntVal.getLimitedValue()));
|
(size_t)(Args[2].IntVal.getLimitedValue()));
|
||||||
|
|
||||||
|
@@ -67,7 +67,7 @@ Interpreter::~Interpreter() {
|
|||||||
|
|
||||||
void Interpreter::runAtExitHandlers () {
|
void Interpreter::runAtExitHandlers () {
|
||||||
while (!AtExitHandlers.empty()) {
|
while (!AtExitHandlers.empty()) {
|
||||||
callFunction(AtExitHandlers.back(), std::vector<GenericValue>());
|
callFunction(AtExitHandlers.back(), None);
|
||||||
AtExitHandlers.pop_back();
|
AtExitHandlers.pop_back();
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
@@ -75,9 +75,8 @@ void Interpreter::runAtExitHandlers () {
|
|||||||
|
|
||||||
/// run - Start execution with the specified function and arguments.
|
/// run - Start execution with the specified function and arguments.
|
||||||
///
|
///
|
||||||
GenericValue
|
GenericValue Interpreter::runFunction(Function *F,
|
||||||
Interpreter::runFunction(Function *F,
|
ArrayRef<GenericValue> ArgValues) {
|
||||||
const std::vector<GenericValue> &ArgValues) {
|
|
||||||
assert (F && "Function *F was null at entry to run()");
|
assert (F && "Function *F was null at entry to run()");
|
||||||
|
|
||||||
// Try extra hard not to pass extra args to a function that isn't
|
// Try extra hard not to pass extra args to a function that isn't
|
||||||
@@ -87,10 +86,9 @@ Interpreter::runFunction(Function *F,
|
|||||||
// parameters than it is declared to take. This does not attempt to
|
// parameters than it is declared to take. This does not attempt to
|
||||||
// take into account gratuitous differences in declared types,
|
// take into account gratuitous differences in declared types,
|
||||||
// though.
|
// though.
|
||||||
std::vector<GenericValue> ActualArgs;
|
const size_t ArgCount = F->getFunctionType()->getNumParams();
|
||||||
const unsigned ArgCount = F->getFunctionType()->getNumParams();
|
ArrayRef<GenericValue> ActualArgs =
|
||||||
for (unsigned i = 0; i < ArgCount; ++i)
|
ArgValues.slice(0, std::min(ArgValues.size(), ArgCount));
|
||||||
ActualArgs.push_back(ArgValues[i]);
|
|
||||||
|
|
||||||
// Set up the function call.
|
// Set up the function call.
|
||||||
callFunction(F, ActualArgs);
|
callFunction(F, ActualArgs);
|
||||||
|
@@ -127,7 +127,7 @@ public:
|
|||||||
/// run - Start execution with the specified function and arguments.
|
/// run - Start execution with the specified function and arguments.
|
||||||
///
|
///
|
||||||
GenericValue runFunction(Function *F,
|
GenericValue runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues) override;
|
ArrayRef<GenericValue> ArgValues) override;
|
||||||
|
|
||||||
void *getPointerToNamedFunction(StringRef Name,
|
void *getPointerToNamedFunction(StringRef Name,
|
||||||
bool AbortOnFailure = true) override {
|
bool AbortOnFailure = true) override {
|
||||||
@@ -137,7 +137,7 @@ public:
|
|||||||
|
|
||||||
// Methods used to execute code:
|
// Methods used to execute code:
|
||||||
// Place a call on the stack
|
// Place a call on the stack
|
||||||
void callFunction(Function *F, const std::vector<GenericValue> &ArgVals);
|
void callFunction(Function *F, ArrayRef<GenericValue> ArgVals);
|
||||||
void run(); // Execute instructions until nothing left to do
|
void run(); // Execute instructions until nothing left to do
|
||||||
|
|
||||||
// Opcode Implementations
|
// Opcode Implementations
|
||||||
@@ -194,7 +194,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GenericValue callExternalFunction(Function *F,
|
GenericValue callExternalFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgVals);
|
ArrayRef<GenericValue> ArgVals);
|
||||||
void exitCalled(GenericValue GV);
|
void exitCalled(GenericValue GV);
|
||||||
|
|
||||||
void addAtExitHandler(Function *F) {
|
void addAtExitHandler(Function *F) {
|
||||||
|
@@ -441,8 +441,7 @@ Function *MCJIT::FindFunctionNamed(const char *FnName) {
|
|||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericValue MCJIT::runFunction(Function *F,
|
GenericValue MCJIT::runFunction(Function *F, ArrayRef<GenericValue> ArgValues) {
|
||||||
const std::vector<GenericValue> &ArgValues) {
|
|
||||||
assert(F && "Function *F was null at entry to run()");
|
assert(F && "Function *F was null at entry to run()");
|
||||||
|
|
||||||
void *FPtr = getPointerToFunction(F);
|
void *FPtr = getPointerToFunction(F);
|
||||||
|
@@ -251,7 +251,7 @@ public:
|
|||||||
void *getPointerToFunction(Function *F) override;
|
void *getPointerToFunction(Function *F) override;
|
||||||
|
|
||||||
GenericValue runFunction(Function *F,
|
GenericValue runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues) override;
|
ArrayRef<GenericValue> ArgValues) override;
|
||||||
|
|
||||||
/// getPointerToNamedFunction - This method returns the address of the
|
/// getPointerToNamedFunction - This method returns the address of the
|
||||||
/// specified function by using the dlsym function call. As such it is only
|
/// specified function by using the dlsym function call. As such it is only
|
||||||
|
@@ -25,7 +25,7 @@ namespace orc {
|
|||||||
|
|
||||||
GenericValue
|
GenericValue
|
||||||
OrcMCJITReplacement::runFunction(Function *F,
|
OrcMCJITReplacement::runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues) {
|
ArrayRef<GenericValue> ArgValues) {
|
||||||
assert(F && "Function *F was null at entry to run()");
|
assert(F && "Function *F was null at entry to run()");
|
||||||
|
|
||||||
void *FPtr = getPointerToFunction(F);
|
void *FPtr = getPointerToFunction(F);
|
||||||
|
@@ -229,7 +229,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GenericValue runFunction(Function *F,
|
GenericValue runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues) override;
|
ArrayRef<GenericValue> ArgValues) override;
|
||||||
|
|
||||||
void setObjectCache(ObjectCache *NewCache) override {
|
void setObjectCache(ObjectCache *NewCache) override {
|
||||||
CompileLayer.setObjectCache(NewCache);
|
CompileLayer.setObjectCache(NewCache);
|
||||||
|
Reference in New Issue
Block a user