Fix out of bounds crash and missing comments

This commit is contained in:
Magnus Norddahl 2020-05-17 20:27:01 +02:00
parent de78134e58
commit 4ff426f722
2 changed files with 14 additions and 11 deletions

View file

@ -23,7 +23,7 @@ JitFuncPtr JitCompile(VMScriptFunction* sfunc)
JitCompiler compiler(&context, sfunc);
IRFunction* func = compiler.Codegen();
jit->add(&context);
//std::string text = context->getFunctionAssembly(func);
std::string text = context.getFunctionAssembly(func);
return reinterpret_cast<JitFuncPtr>(jit->getPointerToFunction(func->name));
}
catch (...)
@ -123,6 +123,8 @@ IRFunction* JitCompiler::Codegen()
EmitOpcode();
// Add line info to first instruction emitted for the opcode
if (labels[i].block->code.size() != labels[i].index)
{
IRInst* inst = labels[i].block->code[labels[i].index];
inst->fileIndex = 0;
inst->lineNumber = curLine;
@ -130,6 +132,7 @@ IRFunction* JitCompiler::Codegen()
inst->comment = lineinfo.GetChars();
else
inst->comment = lineinfo.GetChars() + ("; " + inst->comment);
}
pc++;
}

View file

@ -86,7 +86,7 @@ void JitCompiler::EmitVMCall(IRValue* vmfunc, VMFunction* target)
IRValue* scriptcall = Load(ToInt8PtrPtr(vmfunc, myoffsetof(VMScriptFunction, ScriptCall)));
IRInst* call = cc.CreateCall(cc.CreateBitCast(scriptcall, GetFunctionType5<int, VMFunction*, VMValue*, int, VMReturn*, int>()), { vmfunc, paramsptr, ConstValueD(B), GetCallReturns(), ConstValueD(C) });
call->comment = target ? target->PrintableName.GetChars() : "VMCall";
call->comment = std::string("call ") + (target ? target->PrintableName.GetChars() : "VMCall");
LoadInOuts();
LoadReturns(pc + 1, C);
@ -448,8 +448,8 @@ void JitCompiler::EmitNativeCall(VMNativeFunction *target)
}
}
IRValue* result = cc.CreateCall(cc.CreateBitCast(ConstValueA(target->DirectNativeCall), GetFuncSignature()), args);
//result->setComment(target->PrintableName.GetChars());
IRInst* result = cc.CreateCall(cc.CreateBitCast(ConstValueA(target->DirectNativeCall), GetFuncSignature()), args);
result->comment = std::string("call ") + target->PrintableName.GetChars();
if (startret == 1 && numret > 0)
{