Skip to content

Commit

Permalink
Use ShiftStack and move instead of push and pop in X86InstructionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
MrUser3 authored and gompoc committed Oct 24, 2024
1 parent e454c55 commit b21a8d5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Cpp2IL.Core/InstructionSets/X86InstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
private void ConvertInstructionStatement(Instruction instruction, IsilBuilder builder, MethodAnalysisContext context)
{
var callNoReturn = false;
int operandSize;

switch (instruction.Mnemonic)
{
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b21a8d5

Please sign in to comment.