Skip to content

Commit

Permalink
Merge pull request #236 from charsleysa/bugfix
Browse files Browse the repository at this point in the history
Bugfix
tgiphil committed Aug 2, 2015
2 parents e168803 + 90e167a commit 4fc4023
Showing 3 changed files with 34 additions and 44 deletions.
57 changes: 25 additions & 32 deletions Source/Mosa.Compiler.Framework/Stages/CILTransformationStage.cs
Original file line number Diff line number Diff line change
@@ -56,22 +56,7 @@ void CIL.ICILVisitor.Ldarga(Context context)
void CIL.ICILVisitor.Ldloc(Context context)
{
Debug.Assert(context.MosaType == null);

var instruction = IRInstruction.Move;

var type = context.Operand1.Type;

if (MustSignExtendOnLoad(type))
{
instruction = IRInstruction.SignExtendedMove;
}
else if (MustZeroExtendOnLoad(type))
{
instruction = IRInstruction.ZeroExtendedMove;
}

var size = GetInstructionSize(type);
context.SetInstruction(instruction, size, context.Result, context.Operand1);
ProcessLoadInstruction(context);
}

/// <summary>
@@ -924,10 +909,6 @@ void CIL.ICILVisitor.Pop(Context context)
context.Empty();
}

#endregion ICILVisitor

#region ICILVisitor - Unused

/// <summary>
/// Visitation function for Break instruction.
/// </summary>
@@ -984,6 +965,19 @@ void CIL.ICILVisitor.Ldfld(Context context)
Operand objectOperand = context.Operand1;
MosaField field = context.MosaField;

if (!objectOperand.IsPointer && objectOperand.Type.IsUserValueType)
{
var userStruct = objectOperand;
if (!userStruct.IsStackLocal)
{
var originalOperand = userStruct;
userStruct = MethodCompiler.StackLayout.AddStackLocal(userStruct.Type);
context.InsertBefore().SetInstruction(IRInstruction.Move, userStruct, originalOperand);
}
objectOperand = MethodCompiler.CreateVirtualRegister(userStruct.Type.ToManagedPointer());
context.InsertBefore().SetInstruction(IRInstruction.AddressOf, objectOperand, userStruct);
}

int offset = TypeLayout.GetFieldOffset(field);
Operand offsetOperand = Operand.CreateConstant(TypeSystem, offset);

@@ -1319,6 +1313,10 @@ void CIL.ICILVisitor.Unbox(Context context)
return;
}

#endregion ICILVisitor

#region ICILVisitor - Unused

/// <summary>
/// Visitation function for Refanyval instruction.
/// </summary>
@@ -2023,27 +2021,22 @@ private bool CanSkipDueToRecursiveSystemObjectCtorCall(Context context)
/// <param name="context">Provides the transformation context.</param>
private void ProcessLoadInstruction(Context context)
{
Operand source = context.Operand1;
Operand destination = context.Result;
var source = context.Operand1;
var destination = context.Result;
var size = GetInstructionSize(source.Type);

BaseInstruction extension = null;
var instruction = IRInstruction.Move;

if (MustSignExtendOnLoad(source.Type))
{
extension = IRInstruction.SignExtendedMove;
instruction = IRInstruction.SignExtendedMove;
}
else if (MustZeroExtendOnLoad(source.Type))
{
extension = IRInstruction.ZeroExtendedMove;
}

if (extension != null)
{
context.SetInstruction(extension, destination, source);
return;
instruction = IRInstruction.ZeroExtendedMove;
}

context.ReplaceInstructionOnly(IRInstruction.Move);
context.SetInstruction(instruction, size, destination, source);
}

/// <summary>
19 changes: 8 additions & 11 deletions Source/Mosa.Compiler.Framework/Stages/ConvertCompoundStage.cs
Original file line number Diff line number Diff line change
@@ -47,8 +47,7 @@ private void ProcessInstruction(InstructionNode node)
{
if (node.Instruction == IRInstruction.Load)
{
if (node.MosaType != null &&
TypeLayout.IsCompoundType(node.MosaType) && !node.MosaType.IsUI8 && !node.MosaType.IsR8)
if (node.MosaType != null && TypeLayout.IsCompoundType(node.MosaType))
{
if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result))
{
@@ -59,8 +58,7 @@ private void ProcessInstruction(InstructionNode node)
}
else if (node.Instruction == IRInstruction.Store)
{
if (node.MosaType != null &&
TypeLayout.IsCompoundType(node.MosaType) && !node.MosaType.IsUI8 && !node.MosaType.IsR8)
if (node.MosaType != null && TypeLayout.IsCompoundType(node.MosaType))
{
if (node.Operand3.IsVirtualRegister && !repl.ContainsKey(node.Operand3))
{
@@ -71,8 +69,7 @@ private void ProcessInstruction(InstructionNode node)
}
else if (node.Instruction == IRInstruction.Move)
{
if (node.Result.Type.Equals(node.Operand1.Type) &&
TypeLayout.IsCompoundType(node.Result.Type) && !node.Result.Type.IsUI8 && !node.Result.Type.IsR8)
if (node.Result.Type.Equals(node.Operand1.Type) && TypeLayout.IsCompoundType(node.Result.Type))
{
var prevNode = node.Previous;
var nextNode = node.Next;
@@ -99,10 +96,7 @@ private void ProcessInstruction(InstructionNode node)
&& prevNode.Result == node.Operand1)
{
if (repl.ContainsKey(prevNode.Result))
{
repl[node.Result] = repl[prevNode.Result];
repl.Remove(prevNode.Result);
}
prevNode.Result = node.Result;

node.Empty();
@@ -119,11 +113,14 @@ private void ProcessInstruction(InstructionNode node)
}
node.ReplaceInstructionOnly(IRInstruction.CompoundMove);
}
else if (node.Result.Type.Equals(node.Operand1.Type) && node.Result.IsStackLocal && node.Operand1.IsStackLocal)
{
node.ReplaceInstructionOnly(IRInstruction.CompoundMove);
}
}
else if (node.Instruction == IRInstruction.Call)
{
if (node.Result != null &&
TypeLayout.IsCompoundType(node.Result.Type) && !node.Result.Type.IsUI8 && !node.Result.Type.IsR8)
if (node.Result != null && TypeLayout.IsCompoundType(node.Result.Type))
{
if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result))
{
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x86/Stages/IRTransformationStage.cs
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ void IIRVisitor.AddressOf(Context context)
context.Result = register;
context.ReplaceInstructionOnly(X86.Lea);

context.AppendInstruction(X86.Mov, result, register);
context.AppendInstruction(X86.Mov, NativeInstructionSize, result, register);
}

/// <summary>

0 comments on commit 4fc4023

Please sign in to comment.