From 72650ece37dae3910ecee4f72dc02551fa5aa222 Mon Sep 17 00:00:00 2001 From: MrUser3 Date: Fri, 27 Sep 2024 17:51:43 +0300 Subject: [PATCH] Use ShiftStack and move instead of push and pop in X86InstructionSet --- Cpp2IL.Core/InstructionSets/X86InstructionSet.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Cpp2IL.Core/InstructionSets/X86InstructionSet.cs b/Cpp2IL.Core/InstructionSets/X86InstructionSet.cs index cdb64007..95cf26d7 100644 --- a/Cpp2IL.Core/InstructionSets/X86InstructionSet.cs +++ b/Cpp2IL.Core/InstructionSets/X86InstructionSet.cs @@ -65,6 +65,7 @@ public override List GetIsilFromMethod(Met private void ConvertInstructionStatement(Instruction instruction, IsilBuilder builder, MethodAnalysisContext context) { var callNoReturn = false; + int operandSize; switch (instruction.Mnemonic) { @@ -238,14 +239,14 @@ private void ConvertInstructionStatement(Instruction instruction, IsilBuilder bu builder.Return(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rax")); break; case Mnemonic.Push: - //var operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize(); - builder.Push(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rsp"), ConvertOperand(instruction, 0)); - //builder.ShiftStack(instruction.IP, -operandSize); + operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize(); + builder.ShiftStack(instruction.IP, -operandSize); + builder.Move(instruction.IP, InstructionSetIndependentOperand.MakeStack(0), ConvertOperand(instruction, 0)); break; case Mnemonic.Pop: - //var operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize(); - //builder.ShiftStack(instruction.IP, operandSize); - builder.Pop(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rsp"), ConvertOperand(instruction, 0)); + operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize(); + builder.Move(instruction.IP, ConvertOperand(instruction, 0), InstructionSetIndependentOperand.MakeStack(0)); + builder.ShiftStack(instruction.IP, operandSize); break; case Mnemonic.Sub: case Mnemonic.Add: