Revert "AsmJit update"

This reverts commit 747b3dfcfe.

# Conflicts:
#	libraries/asmjit/asmjit/core/compiler.h

This had to be reverted because it breaks exception handling which is a critical problem.
With the updated code any exception thrown inside code that had a JITed call stack would crash.
This commit is contained in:
Christoph Oelckers 2019-10-07 20:34:55 +02:00
commit 523fd0bf3a
166 changed files with 45117 additions and 51918 deletions

View file

@ -17,13 +17,6 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc)
using namespace asmjit;
StringLogger logger;
// Keep annotations to make it easier to process the debug log in case of error.
logger.setFlags(
FormatOptions::kFlagDebugRA |
FormatOptions::kFlagRegCasts |
FormatOptions::kFlagAnnotations);
try
{
ThrowingErrorHandler errorHandler;
@ -58,11 +51,11 @@ void JitDumpLog(FILE *file, VMScriptFunction *sfunc)
JitCompiler compiler(&code, sfunc);
compiler.Codegen();
fwrite(logger.data(), logger.dataSize(), 1, file);
fwrite(logger.getString(), logger.getLength(), 1, file);
}
catch (const std::exception &e)
{
fwrite(logger.data(), logger.dataSize(), 1, file);
fwrite(logger.getString(), logger.getLength(), 1, file);
FString err;
err.Format("Unexpected JIT error: %s\n", e.what());
@ -76,7 +69,7 @@ void JitDumpLog(FILE *file, VMScriptFunction *sfunc)
static void OutputJitLog(const asmjit::StringLogger &logger)
{
// Write line by line since I_FatalError seems to cut off long strings
const char *pos = logger.data();
const char *pos = logger.getString();
const char *end = pos;
while (*end)
{
@ -101,7 +94,7 @@ static const char *OpNames[NUM_OPS] =
#undef xx
};
asmjit::FuncNode *JitCompiler::Codegen()
asmjit::CCFunc *JitCompiler::Codegen()
{
Setup();
@ -136,7 +129,7 @@ asmjit::FuncNode *JitCompiler::Codegen()
cc.comment(lineinfo.GetChars(), lineinfo.Len());
}
labels[i].cursor = cc.cursor();
labels[i].cursor = cc.getCursor();
ResetTemp();
EmitOpcode();
@ -148,7 +141,7 @@ asmjit::FuncNode *JitCompiler::Codegen()
cc.endFunc();
cc.finalize();
auto code = cc.code();
auto code = cc.getCode ();
for (unsigned int j = 0; j < LineInfo.Size (); j++)
{
auto info = LineInfo[j];
@ -158,7 +151,7 @@ asmjit::FuncNode *JitCompiler::Codegen()
continue;
}
info.InstructionIndex = code->labelOffset(info.Label);
info.InstructionIndex = code->getLabelOffset (info.Label);
LineInfo[j] = info;
}
@ -184,7 +177,7 @@ void JitCompiler::EmitOpcode()
void JitCompiler::BindLabels()
{
asmjit::BaseNode *cursor = cc.cursor();
asmjit::CBNode *cursor = cc.getCursor();
unsigned int size = labels.Size();
for (unsigned int i = 0; i < size; i++)
{
@ -202,7 +195,7 @@ void JitCompiler::CheckVMFrame()
{
if (!vmframeAllocated)
{
auto cursor = cc.cursor();
auto cursor = cc.getCursor();
cc.setCursor(vmframeCursor);
auto vmstack = cc.newStack(sfunc->StackSize, 16, "vmstack");
@ -214,11 +207,11 @@ void JitCompiler::CheckVMFrame()
}
}
asmjit::x86::Gp JitCompiler::GetCallReturns()
asmjit::X86Gp JitCompiler::GetCallReturns()
{
if (!callReturnsAllocated)
{
auto cursor = cc.cursor();
auto cursor = cc.getCursor();
cc.setCursor(callReturnsCursor);
auto stackalloc = cc.newStack(sizeof(VMReturn) * MAX_RETURNS, alignof(VMReturn), "stackalloc");
callReturns = cc.newIntPtr("callReturns");
@ -252,14 +245,14 @@ void JitCompiler::Setup()
ret = cc.newIntPtr("ret"); // VMReturn *ret
numret = cc.newInt32("numret"); // int numret
func = cc.addFunc(FuncSignatureT<int, VMFunction *, void *, int, void *, int>());
func = cc.addFunc(FuncSignature5<int, VMFunction *, void *, int, void *, int>());
cc.setArg(0, unusedFunc);
cc.setArg(1, args);
cc.setArg(2, numargs);
cc.setArg(3, ret);
cc.setArg(4, numret);
callReturnsCursor = cc.cursor();
callReturnsCursor = cc.getCursor();
konstd = sfunc->KonstD;
konstf = sfunc->KonstF;
@ -299,7 +292,7 @@ void JitCompiler::SetupSimpleFrame()
// This is a simple frame with no constructors or destructors. Allocate it on the stack ourselves.
vmframeCursor = cc.cursor();
vmframeCursor = cc.getCursor();
int argsPos = 0;
int regd = 0, regf = 0, rega = 0;
@ -367,7 +360,7 @@ void JitCompiler::SetupFullVMFrame()
stack = cc.newIntPtr("stack");
auto allocFrame = CreateCall<VMFrameStack *, VMScriptFunction *, VMValue *, int>(CreateFullVMFrame);
allocFrame->setRet(0, stack);
allocFrame->setArg(0, imm(sfunc));
allocFrame->setArg(0, imm_ptr(sfunc));
allocFrame->setArg(1, args);
allocFrame->setArg(2, numargs);
@ -408,7 +401,7 @@ void JitCompiler::IncrementVMCalls()
// VMCalls[0]++
auto vmcallsptr = newTempIntPtr();
auto vmcalls = newTempInt32();
cc.mov(vmcallsptr, asmjit::imm(VMCalls));
cc.mov(vmcallsptr, asmjit::imm_ptr(VMCalls));
cc.mov(vmcalls, asmjit::x86::dword_ptr(vmcallsptr));
cc.add(vmcalls, (int)1);
cc.mov(asmjit::x86::dword_ptr(vmcallsptr), vmcalls);
@ -467,7 +460,7 @@ void JitCompiler::EmitThrowException(EVMAbortException reason)
asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason)
{
auto label = cc.newLabel();
auto cursor = cc.cursor();
auto cursor = cc.getCursor();
cc.bind(label);
EmitThrowException(reason);
cc.setCursor(cursor);
@ -480,7 +473,7 @@ asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason)
return label;
}
asmjit::x86::Gp JitCompiler::CheckRegD(int r0, int r1)
asmjit::X86Gp JitCompiler::CheckRegD(int r0, int r1)
{
if (r0 != r1)
{
@ -494,7 +487,7 @@ asmjit::x86::Gp JitCompiler::CheckRegD(int r0, int r1)
}
}
asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1)
asmjit::X86Xmm JitCompiler::CheckRegF(int r0, int r1)
{
if (r0 != r1)
{
@ -508,7 +501,7 @@ asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1)
}
}
asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1, int r2)
asmjit::X86Xmm JitCompiler::CheckRegF(int r0, int r1, int r2)
{
if (r0 != r1 && r0 != r2)
{
@ -522,7 +515,7 @@ asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1, int r2)
}
}
asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1, int r2, int r3)
asmjit::X86Xmm JitCompiler::CheckRegF(int r0, int r1, int r2, int r3)
{
if (r0 != r1 && r0 != r2 && r0 != r3)
{
@ -536,7 +529,7 @@ asmjit::x86::Xmm JitCompiler::CheckRegF(int r0, int r1, int r2, int r3)
}
}
asmjit::x86::Gp JitCompiler::CheckRegS(int r0, int r1)
asmjit::X86Gp JitCompiler::CheckRegS(int r0, int r1)
{
if (r0 != r1)
{
@ -550,7 +543,7 @@ asmjit::x86::Gp JitCompiler::CheckRegS(int r0, int r1)
}
}
asmjit::x86::Gp JitCompiler::CheckRegA(int r0, int r1)
asmjit::X86Gp JitCompiler::CheckRegA(int r0, int r1)
{
if (r0 != r1)
{