Skip to content

Commit

Permalink
-Unwind ManagedPointer changes (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed May 20, 2023
1 parent e338101 commit 95d7ed9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
21 changes: 14 additions & 7 deletions Source/Mosa.Compiler.Framework/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ public BaseInstruction GetLoadParamInstruction(ElementType elementType)
ElementType.Object => IRInstruction.LoadParamObject,
ElementType.I when Is32BitPlatform => IRInstruction.LoadParam32,
ElementType.I when Is64BitPlatform => IRInstruction.LoadParam64,
ElementType.ManagedPointer => IRInstruction.LoadParamManagedPointer,
ElementType.ManagedPointer when Is32BitPlatform => IRInstruction.LoadParam32,
ElementType.ManagedPointer when Is64BitPlatform => IRInstruction.LoadParam64,
_ => throw new InvalidOperationException(),
};
}
Expand All @@ -982,7 +983,8 @@ public BaseInstruction GetReturnInstruction(PrimitiveType primitiveType)
PrimitiveType.R8 => IRInstruction.SetReturnR8,
PrimitiveType.Object => IRInstruction.SetReturnObject,
PrimitiveType.ValueType => IRInstruction.SetReturnCompound,
PrimitiveType.ManagedPointer => IRInstruction.SetReturnManagedPointer,
PrimitiveType.ManagedPointer when Is32BitPlatform => IRInstruction.SetReturn32,
PrimitiveType.ManagedPointer when Is64BitPlatform => IRInstruction.SetReturn64,
_ => throw new InvalidOperationException(),
};
}
Expand Down Expand Up @@ -1026,7 +1028,8 @@ public BaseInstruction GetLoadInstruction(ElementType elementType)
ElementType.Object => IRInstruction.LoadObject,
ElementType.I when Is32BitPlatform => IRInstruction.Load32,
ElementType.I when Is64BitPlatform => IRInstruction.Load64,
ElementType.ManagedPointer => IRInstruction.LoadManagedPointer,
ElementType.ManagedPointer when Is32BitPlatform => IRInstruction.Load32,
ElementType.ManagedPointer when Is64BitPlatform => IRInstruction.Load64,
_ => throw new CompilerException($"Invalid ElementType = {elementType}"),
};
}
Expand All @@ -1048,7 +1051,8 @@ public BaseInstruction GetMoveInstruction(ElementType elementType)
ElementType.Object => IRInstruction.MoveObject,
ElementType.I when Is32BitPlatform => IRInstruction.Move32,
ElementType.I when Is64BitPlatform => IRInstruction.Move64,
ElementType.ManagedPointer => IRInstruction.MoveManagedPointer,
ElementType.ManagedPointer when Is32BitPlatform => IRInstruction.Move32,
ElementType.ManagedPointer when Is64BitPlatform => IRInstruction.Move64,
_ => throw new CompilerException($"Invalid ElementType = {elementType}"),
};
}
Expand All @@ -1062,7 +1066,8 @@ public BaseInstruction GetMoveInstruction(PrimitiveType type)
PrimitiveType.Int64 => IRInstruction.Move64,
PrimitiveType.R4 => IRInstruction.MoveR4,
PrimitiveType.R8 => IRInstruction.MoveR8,
PrimitiveType.ManagedPointer => IRInstruction.MoveManagedPointer,
PrimitiveType.ManagedPointer when Is32BitPlatform => IRInstruction.Move32,
PrimitiveType.ManagedPointer when Is64BitPlatform => IRInstruction.Move64,
PrimitiveType.ValueType => IRInstruction.MoveCompound,
_ => throw new CompilerException($"Invalid StackType = {type}"),
};
Expand All @@ -1085,7 +1090,8 @@ public BaseInstruction GetStoreInstruction(ElementType elementType)
ElementType.Object => IRInstruction.StoreObject,
ElementType.I when Is32BitPlatform => IRInstruction.Store32,
ElementType.I when Is64BitPlatform => IRInstruction.Store64,
ElementType.ManagedPointer => IRInstruction.StoreManagedPointer,
ElementType.ManagedPointer when Is32BitPlatform => IRInstruction.Store32,
ElementType.ManagedPointer when Is64BitPlatform => IRInstruction.Store64,
_ => throw new CompilerException($"Invalid ElementType = {elementType}"),
};
}
Expand All @@ -1107,7 +1113,8 @@ public BaseInstruction GetStoreParamInstruction(ElementType elementType)
ElementType.Object => IRInstruction.StoreParamObject,
ElementType.I when Is32BitPlatform => IRInstruction.StoreParam32,
ElementType.I when Is64BitPlatform => IRInstruction.StoreParam64,
ElementType.ManagedPointer => IRInstruction.StoreParamManagedPointer,
ElementType.ManagedPointer when Is32BitPlatform => IRInstruction.StoreParam32,
ElementType.ManagedPointer when Is64BitPlatform => IRInstruction.StoreParam64,
_ => throw new CompilerException($"Invalid ElementType = {elementType}"),
};
}
Expand Down
29 changes: 5 additions & 24 deletions Source/Mosa.Compiler.Framework/Stages/CILDecoderStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,28 +1276,19 @@ private bool Add(Context context, Stack<StackEntry> stack)
return true;
}

case PrimitiveType.ManagedPointer when entry2.PrimitiveType == PrimitiveType.ManagedPointer:
{
var result = MethodCompiler.VirtualRegisters.AllocateManagedPointer();
context.AppendInstruction(IRInstruction.AddManagedPointer, result, entry1.Operand, entry2.Operand);
PushStack(stack, new StackEntry(result));
return true;
}

case PrimitiveType.Int32 when entry2.PrimitiveType == PrimitiveType.ManagedPointer && Is32BitPlatform:
case PrimitiveType.ManagedPointer when entry2.PrimitiveType == PrimitiveType.Int32 && Is32BitPlatform:
{
var result = MethodCompiler.VirtualRegisters.AllocateManagedPointer();
context.AppendInstruction(IRInstruction.AddManagedPointer, result, entry2.Operand, entry1.Operand);
context.AppendInstruction(IRInstruction.Add32, result, entry2.Operand, entry1.Operand);
PushStack(stack, new StackEntry(result));
return true;
}

case PrimitiveType.Int64 when entry2.PrimitiveType == PrimitiveType.ManagedPointer && Is64BitPlatform:
case PrimitiveType.ManagedPointer when entry2.PrimitiveType == PrimitiveType.Int64 && Is64BitPlatform:
{
var result = MethodCompiler.VirtualRegisters.AllocateManagedPointer();
context.AppendInstruction(IRInstruction.AddManagedPointer, result, entry2.Operand, entry1.Operand);
context.AppendInstruction(IRInstruction.Add64, result, entry2.Operand, entry1.Operand);
PushStack(stack, new StackEntry(result));
return true;
}
Expand All @@ -1307,7 +1298,7 @@ private bool Add(Context context, Stack<StackEntry> stack)
var result = MethodCompiler.VirtualRegisters.AllocateManagedPointer();
var v1 = MethodCompiler.VirtualRegisters.Allocate64();
context.AppendInstruction(IRInstruction.SignExtend32x64, v1, entry1.Operand);
context.AppendInstruction(IRInstruction.AddManagedPointer, result, v1, entry2.Operand);
context.AppendInstruction(IRInstruction.Add64, result, v1, entry2.Operand);
PushStack(stack, new StackEntry(result));
return true;
}
Expand All @@ -1317,7 +1308,7 @@ private bool Add(Context context, Stack<StackEntry> stack)
var result = MethodCompiler.VirtualRegisters.AllocateManagedPointer();
var v1 = MethodCompiler.VirtualRegisters.Allocate64();
context.AppendInstruction(IRInstruction.SignExtend32x64, v1, entry2.Operand);
context.AppendInstruction(IRInstruction.AddManagedPointer, result, entry1.Operand, v1);
context.AppendInstruction(IRInstruction.Add64, result, entry1.Operand, v1);
PushStack(stack, new StackEntry(result));
return true;
}
Expand Down Expand Up @@ -1850,6 +1841,7 @@ private bool Compare(Context context, Stack<StackEntry> stack, ConditionCode con
default:

// TODO: Managed Pointers

return false;
}
}
Expand Down Expand Up @@ -3361,10 +3353,6 @@ private bool InitObj(Context context, Stack<StackEntry> stack, MosaInstruction i
{
context.AppendInstruction(IRInstruction.StoreObject, null, entry.Operand, ConstantZero, Operand.NullObject);
}
else if (type.IsManagedPointer)
{
context.AppendInstruction(IRInstruction.StoreManagedPointer, null, entry.Operand, ConstantZero, Operand.NullObject);
}
else
{
var size = Operand.CreateConstant32(TypeLayout.GetTypeLayoutSize(type));
Expand Down Expand Up @@ -4892,13 +4880,6 @@ private bool Stsfld(Context context, Stack<StackEntry> stack, MosaInstruction in

context.AppendInstruction(IRInstruction.StoreObject, null, staticReference, ConstantZero, source);
}
else if (type.IsManagedPointer)
{
var symbol = GetStaticSymbol(field);
var staticReference = Operand.CreateLabel(symbol.Name, Is32BitPlatform);

context.AppendInstruction(IRInstruction.StoreManagedPointer, null, staticReference, ConstantZero, source);
}
else
{
context.AppendInstruction(storeInstruction, null, fieldOperand, ConstantZero, source);
Expand Down

0 comments on commit 95d7ed9

Please sign in to comment.