Skip to content

Commit b21a8d5

Browse files
MrUser3gompoc
authored andcommitted
Use ShiftStack and move instead of push and pop in X86InstructionSet
1 parent e454c55 commit b21a8d5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Cpp2IL.Core/InstructionSets/X86InstructionSet.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
6565
private void ConvertInstructionStatement(Instruction instruction, IsilBuilder builder, MethodAnalysisContext context)
6666
{
6767
var callNoReturn = false;
68+
int operandSize;
6869

6970
switch (instruction.Mnemonic)
7071
{
@@ -238,14 +239,14 @@ private void ConvertInstructionStatement(Instruction instruction, IsilBuilder bu
238239
builder.Return(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rax"));
239240
break;
240241
case Mnemonic.Push:
241-
//var operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize();
242-
builder.Push(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rsp"), ConvertOperand(instruction, 0));
243-
//builder.ShiftStack(instruction.IP, -operandSize);
242+
operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize();
243+
builder.ShiftStack(instruction.IP, -operandSize);
244+
builder.Move(instruction.IP, InstructionSetIndependentOperand.MakeStack(0), ConvertOperand(instruction, 0));
244245
break;
245246
case Mnemonic.Pop:
246-
//var operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize();
247-
//builder.ShiftStack(instruction.IP, operandSize);
248-
builder.Pop(instruction.IP, InstructionSetIndependentOperand.MakeRegister("rsp"), ConvertOperand(instruction, 0));
247+
operandSize = instruction.Op0Kind == OpKind.Register ? instruction.Op0Register.GetSize() : instruction.MemorySize.GetSize();
248+
builder.Move(instruction.IP, ConvertOperand(instruction, 0), InstructionSetIndependentOperand.MakeStack(0));
249+
builder.ShiftStack(instruction.IP, operandSize);
249250
break;
250251
case Mnemonic.Sub:
251252
case Mnemonic.Add:

0 commit comments

Comments
 (0)