mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-13 16:07:45 +00:00
- create ScriptCall function pointer on VMScriptFunction
This commit is contained in:
parent
137ef034d1
commit
e930dfaae7
5 changed files with 53 additions and 27 deletions
|
@ -417,7 +417,8 @@ int JitCompiler::DoCall(VMFrameStack *stack, VMFunction *call, int b, int c, VMV
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VMCalls[0]++;
|
VMCalls[0]++;
|
||||||
numret = VMExec(static_cast<VMScriptFunction *>(call), param, b, returns, c);
|
auto sfunc = static_cast<VMScriptFunction *>(call);
|
||||||
|
numret = sfunc->ScriptCall(sfunc, param, b, returns, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return numret;
|
return numret;
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include "r_state.h"
|
#include "r_state.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "vmintern.h"
|
#include "vmintern.h"
|
||||||
#include "jit.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern cycle_t VMCycles[10];
|
extern cycle_t VMCycles[10];
|
||||||
|
|
|
@ -711,7 +711,8 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VMCalls[0]++;
|
VMCalls[0]++;
|
||||||
numret = Exec(static_cast<VMScriptFunction *>(call), reg.param + f->NumParam - b, b, returns, C);
|
auto sfunc = static_cast<VMScriptFunction *>(call);
|
||||||
|
numret = sfunc->ScriptCall(sfunc, reg.param + f->NumParam - b, b, returns, C);
|
||||||
}
|
}
|
||||||
assert(numret == C && "Number of parameters returned differs from what was expected by the caller");
|
assert(numret == C && "Number of parameters returned differs from what was expected by the caller");
|
||||||
f->NumParam -= B;
|
f->NumParam -= B;
|
||||||
|
@ -753,7 +754,8 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
|
||||||
else
|
else
|
||||||
{ // FIXME: Not a true tail call
|
{ // FIXME: Not a true tail call
|
||||||
VMCalls[0]++;
|
VMCalls[0]++;
|
||||||
return Exec(static_cast<VMScriptFunction *>(call), reg.param + f->NumParam - B, B, ret, numret);
|
auto sfunc = static_cast<VMScriptFunction *>(call);
|
||||||
|
return sfunc->ScriptCall(sfunc, reg.param + f->NumParam - B, B, ret, numret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NEXTOP;
|
NEXTOP;
|
||||||
|
@ -2051,26 +2053,6 @@ static int Exec(VMScriptFunction *func, VMValue *params, int numparams, VMReturn
|
||||||
VMFillParams(params, newf, numparams);
|
VMFillParams(params, newf, numparams);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!func->JitCompiled)
|
|
||||||
{
|
|
||||||
func->JitFunc = JitCompile(func);
|
|
||||||
func->JitCompiled = true;
|
|
||||||
}
|
|
||||||
if (func->JitFunc)
|
|
||||||
{
|
|
||||||
JitExceptionInfo exceptInfo;
|
|
||||||
exceptInfo.reason = -1;
|
|
||||||
int result = func->JitFunc(stack, ret, numret, &exceptInfo);
|
|
||||||
if (exceptInfo.reason != -1)
|
|
||||||
{
|
|
||||||
if (exceptInfo.cppException)
|
|
||||||
std::rethrow_exception(exceptInfo.cppException);
|
|
||||||
else
|
|
||||||
ThrowAbortException(func, exceptInfo.pcOnJitAbort, (EVMAbortException)exceptInfo.reason, nullptr);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
numret = ExecScriptFunc(stack, ret, numret);
|
numret = ExecScriptFunc(stack, ret, numret);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
|
|
|
@ -213,6 +213,45 @@ int VMScriptFunction::PCToLine(const VMOP *pc)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VMScriptFunction::FirstScriptCall(VMScriptFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret)
|
||||||
|
{
|
||||||
|
func->JitFunc = JitCompile(func);
|
||||||
|
if (func->JitFunc)
|
||||||
|
func->ScriptCall = &VMScriptFunction::JitCall;
|
||||||
|
else
|
||||||
|
func->ScriptCall = VMExec;
|
||||||
|
|
||||||
|
return func->ScriptCall(func, params, numparams, ret, numret);
|
||||||
|
}
|
||||||
|
|
||||||
|
int VMScriptFunction::JitCall(VMScriptFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret)
|
||||||
|
{
|
||||||
|
VMFrameStack *stack = &GlobalVMStack;
|
||||||
|
VMFrame *newf = stack->AllocFrame(func);
|
||||||
|
VMFillParams(params, newf, numparams);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JitExceptionInfo exceptInfo;
|
||||||
|
exceptInfo.reason = -1;
|
||||||
|
int result = func->JitFunc(stack, ret, numret, &exceptInfo);
|
||||||
|
if (exceptInfo.reason != -1)
|
||||||
|
{
|
||||||
|
if (exceptInfo.cppException)
|
||||||
|
std::rethrow_exception(exceptInfo.cppException);
|
||||||
|
else
|
||||||
|
ThrowAbortException(func, exceptInfo.pcOnJitAbort, (EVMAbortException)exceptInfo.reason, nullptr);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
stack->PopFrame();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
stack->PopFrame();
|
||||||
|
return numret;
|
||||||
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// VMFrame :: InitRegS
|
// VMFrame :: InitRegS
|
||||||
|
@ -464,7 +503,8 @@ int VMCall(VMFunction *func, VMValue *params, int numparams, VMReturn *results,
|
||||||
{
|
{
|
||||||
VMCycles[0].Clock();
|
VMCycles[0].Clock();
|
||||||
VMCalls[0]++;
|
VMCalls[0]++;
|
||||||
int numret = VMExec(static_cast<VMScriptFunction *>(func), params, numparams, results, numresults);
|
auto sfunc = static_cast<VMScriptFunction *>(func);
|
||||||
|
int numret = sfunc->ScriptCall(sfunc, params, numparams, results, numresults);
|
||||||
VMCycles[0].Unclock();
|
VMCycles[0].Unclock();
|
||||||
return numret;
|
return numret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -478,11 +478,15 @@ public:
|
||||||
VM_UBYTE NumArgs; // Number of arguments this function takes
|
VM_UBYTE NumArgs; // Number of arguments this function takes
|
||||||
TArray<FTypeAndOffset> SpecialInits; // list of all contents on the extra stack which require construction and destruction
|
TArray<FTypeAndOffset> SpecialInits; // list of all contents on the extra stack which require construction and destruction
|
||||||
|
|
||||||
bool JitCompiled = false;
|
int(*ScriptCall)(VMScriptFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret) = &VMScriptFunction::FirstScriptCall;
|
||||||
JitFuncPtr JitFunc = nullptr;
|
|
||||||
|
|
||||||
void InitExtra(void *addr);
|
void InitExtra(void *addr);
|
||||||
void DestroyExtra(void *addr);
|
void DestroyExtra(void *addr);
|
||||||
int AllocExtraStack(PType *type);
|
int AllocExtraStack(PType *type);
|
||||||
int PCToLine(const VMOP *pc);
|
int PCToLine(const VMOP *pc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int FirstScriptCall(VMScriptFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret);
|
||||||
|
static int JitCall(VMScriptFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret);
|
||||||
|
JitFuncPtr JitFunc = nullptr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue