diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index 1e94e3ada..1813d19ca 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -156,6 +156,8 @@ asmjit::CCFunc *JitCompiler::Codegen() LineInfo[j] = info; } + std::stable_sort(LineInfo.begin(), LineInfo.end(), [](const JitLineInfo &a, const JitLineInfo &b) { return a.InstructionIndex < b.InstructionIndex; }); + return func; } @@ -444,17 +446,15 @@ void JitCompiler::EmitNullPointerThrow(int index, EVMAbortException reason) cc.je(label); } -void JitCompiler::ThrowException(VMScriptFunction *func, VMOP *line, int reason) +void JitCompiler::ThrowException(int reason) { - ThrowAbortException(func, line, (EVMAbortException)reason, nullptr); + ThrowAbortException((EVMAbortException)reason, nullptr); } void JitCompiler::EmitThrowException(EVMAbortException reason) { - auto call = CreateCall(&JitCompiler::ThrowException); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, asmjit::imm(reason)); + auto call = CreateCall(&JitCompiler::ThrowException); + call->setArg(0, asmjit::imm(reason)); } asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason) @@ -464,6 +464,12 @@ asmjit::Label JitCompiler::EmitThrowExceptionLabel(EVMAbortException reason) cc.bind(label); EmitThrowException(reason); cc.setCursor(cursor); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); + return label; } diff --git a/src/scripting/vm/jit_flow.cpp b/src/scripting/vm/jit_flow.cpp index 0ca8bf437..96b7bcec0 100644 --- a/src/scripting/vm/jit_flow.cpp +++ b/src/scripting/vm/jit_flow.cpp @@ -330,15 +330,18 @@ void JitCompiler::EmitBOUND() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, asmjit::imm(BC)); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, asmjit::imm(BC)); cc.setCursor(cursor); cc.cmp(regD[A], (int)BC); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } void JitCompiler::EmitBOUND_K() @@ -346,15 +349,18 @@ void JitCompiler::EmitBOUND_K() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, asmjit::imm(konstd[BC])); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, asmjit::imm(konstd[BC])); cc.setCursor(cursor); cc.cmp(regD[A], (int)konstd[BC]); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } void JitCompiler::EmitBOUND_R() @@ -362,18 +368,21 @@ void JitCompiler::EmitBOUND_R() auto cursor = cc.getCursor(); auto label = cc.newLabel(); cc.bind(label); - auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); - call->setArg(0, asmjit::imm_ptr(sfunc)); - call->setArg(1, asmjit::imm_ptr(pc)); - call->setArg(2, regD[A]); - call->setArg(3, regD[B]); + auto call = CreateCall(&JitCompiler::ThrowArrayOutOfBounds); + call->setArg(0, regD[A]); + call->setArg(1, regD[B]); cc.setCursor(cursor); cc.cmp(regD[A], regD[B]); cc.jae(label); + + JitLineInfo info; + info.Label = label; + info.LineNumber = sfunc->PCToLine(pc); + LineInfo.Push(info); } -void JitCompiler::ThrowArrayOutOfBounds(VMScriptFunction *func, VMOP *line, int index, int size) +void JitCompiler::ThrowArrayOutOfBounds(int index, int size) { if (index >= size) { diff --git a/src/scripting/vm/jitintern.h b/src/scripting/vm/jitintern.h index deb0378f0..67659e6e0 100644 --- a/src/scripting/vm/jitintern.h +++ b/src/scripting/vm/jitintern.h @@ -219,8 +219,8 @@ private: void EmitThrowException(EVMAbortException reason); asmjit::Label EmitThrowExceptionLabel(EVMAbortException reason); - static void ThrowArrayOutOfBounds(VMScriptFunction *func, VMOP *line, int index, int size); - static void ThrowException(VMScriptFunction *func, VMOP *line, int reason); + static void ThrowArrayOutOfBounds(int index, int size); + static void ThrowException(int reason); asmjit::X86Gp CheckRegD(int r0, int r1); asmjit::X86Xmm CheckRegF(int r0, int r1);