Core: Change the handling of symbols inside asmjit usage

This commit is contained in:
zilmar 2024-10-31 06:50:17 +10:30
parent 17c501fa08
commit 905254615d
3 changed files with 203 additions and 357 deletions

View File

@ -2961,11 +2961,11 @@ void CX86RecompilerOps::LB_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA
{ {
if (SignExtend) if (SignExtend)
{ {
m_Assembler.MoveSxVariableToX86regByte(Reg, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); m_Assembler.MoveSxVariableToX86regByte(Reg, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 3)", PAddr).c_str());
} }
else else
{ {
m_Assembler.MoveZxVariableToX86regByte(Reg, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); m_Assembler.MoveZxVariableToX86regByte(Reg, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 3)", PAddr).c_str());
} }
} }
else else
@ -3078,11 +3078,11 @@ void CX86RecompilerOps::LH_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA
{ {
if (SignExtend) if (SignExtend)
{ {
m_Assembler.MoveSxVariableToX86regHalf(Reg, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); m_Assembler.MoveSxVariableToX86regHalf(Reg, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 2)", PAddr).c_str());
} }
else else
{ {
m_Assembler.MoveZxVariableToX86regHalf(Reg, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); m_Assembler.MoveZxVariableToX86regHalf(Reg, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 2)", PAddr).c_str());
} }
} }
else else
@ -9345,7 +9345,7 @@ void CX86RecompilerOps::UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles)
m_CodeBlock.Log(""); m_CodeBlock.Log("");
m_CodeBlock.Log(" // Updating sync CPU"); m_CodeBlock.Log(" // Updating sync CPU");
RegSet.BeforeCallDirect(); RegSet.BeforeCallDirect();
m_Assembler.PushImm32(stdstr_f("%d", Cycles).c_str(), Cycles); m_Assembler.push(Cycles);
m_Assembler.CallThis((uint32_t)g_System, AddressOf(&CN64System::UpdateSyncCPU), "CN64System::UpdateSyncCPU", 8); m_Assembler.CallThis((uint32_t)g_System, AddressOf(&CN64System::UpdateSyncCPU), "CN64System::UpdateSyncCPU", 8);
RegSet.AfterCallDirect(); RegSet.AfterCallDirect();
} }
@ -10370,7 +10370,7 @@ void CX86RecompilerOps::SB_Const(uint32_t Value, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveConstByteToVariable((PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str(), (uint8_t)Value); m_Assembler.MoveConstByteToVariable((PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 3)", PAddr).c_str(), (uint8_t)Value);
} }
break; break;
case 0x04000000: case 0x04000000:
@ -10448,7 +10448,7 @@ void CX86RecompilerOps::SB_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveX86regByteToVariable((PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str(), Reg); m_Assembler.MoveX86regByteToVariable((PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 3)", PAddr).c_str(), Reg);
} }
break; break;
default: default:
@ -10498,7 +10498,7 @@ void CX86RecompilerOps::SH_Const(uint32_t Value, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveConstHalfToVariable((PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str(), (uint16_t)Value); m_Assembler.MoveConstHalfToVariable((PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 2)", PAddr).c_str(), (uint16_t)Value);
} }
break; break;
default: default:
@ -10551,7 +10551,7 @@ void CX86RecompilerOps::SH_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveX86regHalfToVariable((PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str(), Reg); m_Assembler.MoveX86regHalfToVariable((PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (0x%X ^ 2)", PAddr).c_str(), Reg);
} }
break; break;
default: default:
@ -10613,7 +10613,7 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveConstToVariable(PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + %X", PAddr).c_str(), Value); m_Assembler.MoveConstToVariable(PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + 0x%X", PAddr).c_str(), Value);
} }
break; break;
case 0x03F00000: case 0x03F00000:
@ -11041,7 +11041,7 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr)
} }
else if (PAddr < g_MMU->RdramSize()) else if (PAddr < g_MMU->RdramSize())
{ {
m_Assembler.MoveX86regToVariable(PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + %X", PAddr).c_str(), Reg); m_Assembler.MoveX86regToVariable(PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + 0x%X", PAddr).c_str(), Reg);
} }
break; break;
case 0x04000000: case 0x04000000:

View File

@ -21,30 +21,18 @@ void CX86Ops::AdcVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable,
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
adc(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
adc(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
adc(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::AddConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::AddConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
add(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
add(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
add(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) void CX86Ops::AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const)
@ -70,60 +58,36 @@ void CX86Ops::AddVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable,
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
add(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
add(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
add(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
and_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
and_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
and_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::AndVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiply) void CX86Ops::AndVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiply)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiply >> 1));
RemoveSymbol(SymbolKey.c_str());
}
else
{
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiply >> 1));
} }
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiply >> 1));
} }
void CX86Ops::AndVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::AndVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::BreakPointNotification(const char * FileName, int32_t LineNumber) void CX86Ops::BreakPointNotification(const char * FileName, int32_t LineNumber)
@ -150,15 +114,9 @@ void CX86Ops::CallFunc(uint32_t FunctPtr, const char * FunctName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", FunctPtr); AddNumberSymbol(FunctPtr, FunctName);
AddSymbol(SymbolKey.c_str(), FunctName);
call((uint64_t)FunctPtr);
RemoveSymbol(SymbolKey.c_str());
}
else
{
call((uint64_t)FunctPtr);
} }
call((uint64_t)FunctPtr);
} }
#ifdef _MSC_VER #ifdef _MSC_VER
@ -180,30 +138,18 @@ void CX86Ops::CompConstByteToVariable(void * Variable, const char * VariableName
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
cmp(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
cmp(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
} }
cmp(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
cmp(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
cmp(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
cmp(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const) void CX86Ops::CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const)
@ -222,15 +168,9 @@ void CX86Ops::CompX86regToVariable(const asmjit::x86::Gp & Reg, void * Variable,
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
cmp(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
cmp(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
cmp(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::Fabs(void) void CX86Ops::Fabs(void)
@ -270,109 +210,109 @@ void CX86Ops::Fsub(const asmjit::x86::Mem & Mem)
void CX86Ops::JaeLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JaeLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jae(JumpLabel); jae(JumpLabel);
} }
void CX86Ops::JaLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JaLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
ja(JumpLabel); ja(JumpLabel);
} }
void CX86Ops::JbLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JbLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jb(JumpLabel); jb(JumpLabel);
} }
void CX86Ops::JbeLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JbeLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jbe(JumpLabel); jbe(JumpLabel);
} }
void CX86Ops::JecxzLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JecxzLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jecxz(JumpLabel); jecxz(JumpLabel);
} }
void CX86Ops::JeLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JeLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
je(JumpLabel); je(JumpLabel);
} }
void CX86Ops::JgeLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JgeLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jge(JumpLabel); jge(JumpLabel);
} }
void CX86Ops::JgLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JgLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jg(JumpLabel); jg(JumpLabel);
} }
void CX86Ops::JleLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JleLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jle(JumpLabel); jle(JumpLabel);
} }
void CX86Ops::JlLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JlLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jl(JumpLabel); jl(JumpLabel);
} }
void CX86Ops::JmpLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JmpLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jmp(JumpLabel); jmp(JumpLabel);
} }
void CX86Ops::JneLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JneLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jne(JumpLabel); jne(JumpLabel);
} }
void CX86Ops::JnpLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JnpLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jnp(JumpLabel); jnp(JumpLabel);
} }
void CX86Ops::JnsLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JnsLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jns(JumpLabel); jns(JumpLabel);
} }
void CX86Ops::JnzLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JnzLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jnz(JumpLabel); jnz(JumpLabel);
} }
void CX86Ops::JsLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JsLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
js(JumpLabel); js(JumpLabel);
} }
void CX86Ops::JoLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JoLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jo(JumpLabel); jo(JumpLabel);
} }
void CX86Ops::JzLabel(const char * LabelName, asmjit::Label & JumpLabel) void CX86Ops::JzLabel(const char * LabelName, asmjit::Label & JumpLabel)
{ {
AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); AddLabelSymbol(JumpLabel, LabelName);
jz(JumpLabel); jz(JumpLabel);
} }
@ -380,61 +320,37 @@ void CX86Ops::MoveConstByteToVariable(void * Variable, const char * VariableName
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
} }
mov(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::MoveConstHalfToVariable(void * Variable, const char * VariableName, uint16_t Const) void CX86Ops::MoveConstHalfToVariable(void * Variable, const char * VariableName, uint16_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::word_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::word_ptr((uint64_t)Variable), Const);
} }
mov(asmjit::x86::word_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::MoveConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::MoveConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::MoveConst64ToVariable(void * Variable, const char * VariableName, uint64_t Const) void CX86Ops::MoveConst64ToVariable(void * Variable, const char * VariableName, uint64_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::dword_ptr((uint64_t)Variable), (uint32_t)Const);
mov(asmjit::x86::dword_ptr(((uint64_t)Variable) + 4), (uint32_t)(Const >> 32));
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
mov(asmjit::x86::dword_ptr((uint64_t)Variable), (uint32_t)Const);
mov(asmjit::x86::dword_ptr(((uint64_t)Variable) + 4), (uint32_t)(Const >> 32));
} }
void CX86Ops::MoveConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const) void CX86Ops::MoveConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const)
@ -453,332 +369,198 @@ void CX86Ops::MoveSxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Var
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
movsx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
movsx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
} }
movsx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
} }
void CX86Ops::MoveSxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::MoveSxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
movsx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
movsx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
} }
movsx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
} }
void CX86Ops::MoveVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::MoveVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::MoveVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiplier) void CX86Ops::MoveVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiplier)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiplier >> 1));
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiplier >> 1));
} }
mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiplier >> 1));
} }
void CX86Ops::MoveX86regByteToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) void CX86Ops::MoveX86regByteToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::byte_ptr((uint64_t)(Variable)), Reg.r8());
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::byte_ptr((uint64_t)(Variable)), Reg.r8());
} }
mov(asmjit::x86::byte_ptr((uint64_t)(Variable)), Reg.r8());
} }
void CX86Ops::MoveX86regHalfToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) void CX86Ops::MoveX86regHalfToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::word_ptr((uint64_t)(Variable)), Reg.r16());
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::word_ptr((uint64_t)(Variable)), Reg.r16());
} }
mov(asmjit::x86::word_ptr((uint64_t)(Variable)), Reg.r16());
} }
void CX86Ops::MoveX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) void CX86Ops::MoveX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
mov(asmjit::x86::dword_ptr((uint64_t)(Variable)), Reg);
RemoveSymbol(SymbolKey.c_str());
}
else
{
mov(asmjit::x86::dword_ptr((uint64_t)(Variable)), Reg);
} }
mov(asmjit::x86::dword_ptr((uint64_t)(Variable)), Reg);
} }
void CX86Ops::MoveZxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::MoveZxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
movzx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
movzx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
} }
movzx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable));
} }
void CX86Ops::MoveZxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::MoveZxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
movzx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
movzx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
} }
movzx(Reg, asmjit::x86::word_ptr((uint64_t)Variable));
} }
void CX86Ops::OrConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::OrConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::OrVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::OrVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
or_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
or_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
or_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::OrX86RegToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) void CX86Ops::OrX86RegToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Reg);
RemoveSymbol(SymbolKey.c_str());
}
else
{
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Reg);
} }
or_(asmjit::x86::dword_ptr((uint64_t)Variable), Reg);
} }
void CX86Ops::PushImm32(const char * String, uint32_t Value) void CX86Ops::PushImm32(const char * String, uint32_t Value)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
stdstr_f SymbolKey("0x%X", Value); AddNumberSymbol(Value, String);
AddSymbol(SymbolKey.c_str(), String);
push(Value);
RemoveSymbol(SymbolKey.c_str());
}
else
{
push(Value);
} }
push(Value);
} }
void CX86Ops::SetaVariable(void * Variable, const char * VariableName) void CX86Ops::SetaVariable(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
seta(asmjit::x86::byte_ptr((uint32_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
seta(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
seta(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
void CX86Ops::SetbVariable(void * Variable, const char * VariableName) void CX86Ops::SetbVariable(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
setb(asmjit::x86::byte_ptr((uint32_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
setb(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
setb(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
void CX86Ops::SetgVariable(void * Variable, const char * VariableName) void CX86Ops::SetgVariable(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
setg(asmjit::x86::byte_ptr((uint32_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
setg(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
setg(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
void CX86Ops::SetlVariable(void * Variable, const char * VariableName) void CX86Ops::SetlVariable(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
setl(asmjit::x86::byte_ptr((uint32_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
setl(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
setl(asmjit::x86::byte_ptr((uint32_t)Variable));
} }
void CX86Ops::SbbVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::SbbVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
sbb(Reg, asmjit::x86::dword_ptr((uint32_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
sbb(Reg, asmjit::x86::dword_ptr((uint32_t)Variable));
} }
sbb(Reg, asmjit::x86::dword_ptr((uint32_t)Variable));
} }
void CX86Ops::SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName) void CX86Ops::SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
sub(asmjit::x86::dword_ptr((uint32_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
sub(asmjit::x86::dword_ptr((uint32_t)Variable), Const);
} }
sub(asmjit::x86::dword_ptr((uint32_t)Variable), Const);
} }
void CX86Ops::SubVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::SubVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
sub(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
sub(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
sub(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::TestVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::TestVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
test(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
test(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
test(asmjit::x86::dword_ptr((uint64_t)Variable), Const);
} }
void CX86Ops::XorVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) void CX86Ops::XorVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
xor_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
xor_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
xor_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable));
} }
void CX86Ops::fpuCompp(int32_t & StackPos) void CX86Ops::fpuCompp(int32_t & StackPos)
@ -797,15 +579,9 @@ void CX86Ops::fpuLoadControl(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
fldcw(asmjit::x86::ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
fldcw(asmjit::x86::ptr((uint64_t)Variable));
} }
fldcw(asmjit::x86::ptr((uint64_t)Variable));
} }
void CX86Ops::fpuLoadDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg) void CX86Ops::fpuLoadDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg)
@ -854,15 +630,9 @@ void CX86Ops::fpuStoreControl(void * Variable, const char * VariableName)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())
{ {
std::string SymbolKey = VariableSymbol(Variable); AddNumberSymbol((uint32_t)Variable, VariableName);
AddSymbol(SymbolKey.c_str(), VariableName);
fnstcw(asmjit::x86::ptr((uint64_t)Variable));
RemoveSymbol(SymbolKey.c_str());
}
else
{
fnstcw(asmjit::x86::ptr((uint64_t)Variable));
} }
fnstcw(asmjit::x86::ptr((uint64_t)Variable));
} }
void CX86Ops::fpuStoreDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop) void CX86Ops::fpuStoreDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop)
@ -1049,35 +819,105 @@ asmjit::Error CX86Ops::_log(const char * data, size_t size) noexcept
{ {
stdstr AsmjitLog(std::string(data, size)); stdstr AsmjitLog(std::string(data, size));
AsmjitLog.Trim("\n"); AsmjitLog.Trim("\n");
for (SymbolMap::const_iterator itr = m_Symbols.begin(); itr != m_Symbols.end(); itr++) std::string::size_type Pos = AsmjitLog.find("0x");
if (m_NumberSymbols.size() > 0 && Pos != std::string::npos)
{ {
AsmjitLog.Replace(itr->first, itr->second); uint32_t Value = 0;
if (AsmjitLog[Pos] == '0' && (AsmjitLog[Pos+1] == 'x' || AsmjitLog[Pos+1] == 'X'))
{
Pos += 2;
}
for (int i = 0; i < 8; i++)
{
char c = AsmjitLog[Pos + i];
if (c >= '0' && c <= '9')
{
Value = (Value << 4) | (c - '0');
}
else if (c >= 'a' && c <= 'f')
{
Value = (Value << 4) | (c - 'a' + 10);
}
else if (c >= 'A' && c <= 'F')
{
Value = (Value << 4) | (c - 'A' + 10);
}
else
{
break;
}
}
NumberSymbolMap::iterator itr = m_NumberSymbols.find(Value);
if (itr != m_NumberSymbols.end())
{
std::string::size_type endPos = Pos + 2;
for (std::string::size_type LenSize = AsmjitLog.length(); (endPos < LenSize && isxdigit((unsigned char)AsmjitLog[endPos])); endPos++)
{
}
std::string hexStr = AsmjitLog.substr(Pos, endPos - Pos);
AsmjitLog.replace(Pos, hexStr.length(), itr->second.Symbol);
itr->second.Count -= 1;
if (itr->second.Count == 0)
{
m_NumberSymbols.erase(itr);
}
}
}
Pos = AsmjitLog.find("L");
if (m_LabelSymbols.size() > 0 && Pos != std::string::npos)
{
NumberSymbolMap::iterator itr = m_LabelSymbols.find(std::stoul(&AsmjitLog[Pos + 1], nullptr, 10));
if (itr != m_LabelSymbols.end())
{
std::string::size_type endPos = Pos + 1;
for (std::string::size_type LenSize = AsmjitLog.length(); (endPos < LenSize && isdigit((unsigned char)AsmjitLog[endPos])); endPos++)
{
}
std::string LabelStr = AsmjitLog.substr(Pos, endPos - Pos);
AsmjitLog.replace(Pos, LabelStr.length(), itr->second.Symbol);
itr->second.Count -= 1;
if (itr->second.Count == 0)
{
m_LabelSymbols.erase(itr);
}
}
} }
m_CodeBlock.Log(" %s", AsmjitLog.c_str()); m_CodeBlock.Log(" %s", AsmjitLog.c_str());
return asmjit::kErrorOk; return asmjit::kErrorOk;
} }
void CX86Ops::AddSymbol(const char * SymbolKey, const char * SymbolValue) void CX86Ops::AddLabelSymbol(const asmjit::Label & Label, const char * Symbol)
{ {
m_Symbols.emplace(std::make_pair(SymbolKey, SymbolValue)); NumberSymbolMap::iterator itr = m_LabelSymbols.find(Label.id());
} if (itr != m_LabelSymbols.end())
void CX86Ops::RemoveSymbol(const char * SymbolKey)
{
SymbolMap::iterator itr = m_Symbols.find(SymbolKey);
if (itr != m_Symbols.end())
{ {
m_Symbols.erase(itr); __debugbreak();
}
else
{
m_LabelSymbols.emplace(std::make_pair(Label.id(), NumberSymbol{Symbol, 1}));
} }
} }
std::string CX86Ops::VariableSymbol(void * Variable) const void CX86Ops::AddNumberSymbol(uint32_t Value, const char * Symbol)
{ {
if (int64_t(Variable) < 0) NumberSymbolMap::iterator itr = m_NumberSymbols.find(Value);
if (itr != m_NumberSymbols.end())
{ {
return stdstr_f("-0x%0X", (uint32_t)(~(int64_t(Variable)) + 1)); if (strcmp(itr->second.Symbol.c_str(), Symbol) == 0)
{
itr->second.Count += 1;
}
else
{
__debugbreak();
}
}
else
{
m_NumberSymbols.emplace(std::make_pair(Value, NumberSymbol{Symbol, 1}));
} }
return stdstr_f("0x%X", (uint32_t)Variable);
} }
#endif #endif

View File

@ -144,15 +144,21 @@ private:
static x86Reg RegValue(const asmjit::x86::Gp & Reg); static x86Reg RegValue(const asmjit::x86::Gp & Reg);
asmjit::Error _log(const char * data, size_t size) noexcept; asmjit::Error _log(const char * data, size_t size) noexcept;
void AddSymbol(const char * SymbolKey, const char * SymbolValue); void AddLabelSymbol(const asmjit::Label & Label, const char * Symbol);
void RemoveSymbol(const char * SymbolKey); void AddNumberSymbol(uint32_t Value, const char * Symbol);
std::string VariableSymbol(void * Variable) const;
static void BreakPointNotification(const char * FileName, int32_t LineNumber); static void BreakPointNotification(const char * FileName, int32_t LineNumber);
typedef std::map<std::string, std::string> SymbolMap; typedef struct
{
std::string Symbol;
uint32_t Count;
} NumberSymbol;
SymbolMap m_Symbols; typedef std::map<uint32_t, NumberSymbol> NumberSymbolMap;
NumberSymbolMap m_LabelSymbols;
NumberSymbolMap m_NumberSymbols;
CCodeBlock & m_CodeBlock; CCodeBlock & m_CodeBlock;
}; };