MCPcopy Create free account
hub / github.com/WheretIB/nullc / TranslateToNative

Method TranslateToNative

NULLC/Executor_X86.cpp:970–1665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

968}
969
970bool ExecutorX86::TranslateToNative()
971{
972 execError[0] = 0;
973
974 globalStartInBytecode = 0xffffffff;
975
976 if(codeRunning && functionAddress.max <= exFunctions.size() * 2)
977 {
978 unsigned *newStorage = (unsigned*)NULLC::alloc(exFunctions.size() * 3 * sizeof(unsigned));
979 oldFunctionLists.push_back(FunctionListInfo(functionAddress.data, functionAddress.count));
980 functionAddress.data = newStorage;
981 functionAddress.count = exFunctions.size() * 2;
982 functionAddress.max = exFunctions.size() * 3;
983 }else{
984 functionAddress.resize(exFunctions.size() * 2);
985 }
986
987 memset(instList.data, 0, sizeof(x86Instruction) * instList.size());
988 instList.clear();
989
990 SetParamBase((unsigned int)(long long)paramBase);
991 SetFunctionList(exFunctions.data, functionAddress.data);
992 SetContinuePtr(&callContinue);
993 SetLastInstruction(instList.data, instList.data);
994
995 CommonSetLinker(exLinker);
996
997 EMIT_OP(o_use32);
998
999 // Mirror extra global return so that jump to global return can be marked (cmdNop, because we will have some custom code)
1000 exCode.push_back(VMCmd(cmdNop));
1001 for(unsigned int i = oldJumpTargetCount, e = exLinker->jumpTargets.size(); i != e; i++)
1002 exCode[exLinker->jumpTargets[i]].cmd |= 0x80;
1003 // Remove cmdNop, because we don't want to generate code for it
1004 exCode.pop_back();
1005
1006 OptimizationLookBehind(false);
1007 unsigned int pos = lastInstructionCount;
1008 while(pos < exCode.size())
1009 {
1010 VMCmd &cmd = exCode[pos];
1011
1012 unsigned int currSize = (int)(GetLastInstruction() - instList.data);
1013 instList.count = currSize;
1014 if(currSize + 64 >= instList.max)
1015 instList.grow(currSize + 64);
1016 SetLastInstruction(instList.data + currSize, instList.data);
1017
1018 GetLastInstruction()->instID = pos + 1;
1019
1020 if(cmd.cmd & 0x80)
1021 {
1022 OptimizationLookBehind(false);
1023 cmd.cmd &= ~0x80;
1024 }
1025
1026 pos++;
1027 NULLC::cgFuncs[cmd.cmd](cmd);

Callers 1

nullcLinkCodeFunction · 0.80

Calls 15

FunctionListInfoClass · 0.85
SetParamBaseFunction · 0.85
SetFunctionListFunction · 0.85
SetContinuePtrFunction · 0.85
SetLastInstructionFunction · 0.85
CommonSetLinkerFunction · 0.85
EMIT_OPFunction · 0.85
VMCmdClass · 0.85
OptimizationLookBehindFunction · 0.85
GetLastInstructionFunction · 0.85
EMIT_OP_REGFunction · 0.85
EMIT_OP_REG_NUMFunction · 0.85

Tested by

no test coverage detected