add sign check for choose right asm instruction in LdLoc

This commit is contained in:
Trivalik_cp 2011-09-14 21:10:56 +00:00
parent 96d3fde47c
commit 6f1efc4bcb
4 changed files with 45 additions and 1 deletions

View file

@ -64,6 +64,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MoveZeroExtend.cs" />
<Compile Include="MoveSignExtend.cs" />
<Compile Include="Lgdt.cs" />
<Compile Include="Lidt.cs" />

View file

@ -0,0 +1,24 @@
namespace Cosmos.Compiler.Assembler.X86 {
[OpCode("movzx")]
public class MoveZeroExtend : InstructionWithDestinationAndSourceAndSize
{
public override void WriteText(Assembler aAssembler, System.IO.TextWriter aOutput)
{
if (Size == 0)
{
Size = 32;
}
aOutput.Write(mMnemonic);
if (!DestinationEmpty)
{
aOutput.Write(" ");
aOutput.Write(this.GetDestinationAsString());
aOutput.Write(", ");
aOutput.Write(SizeToString(Size));
aOutput.Write(" ");
aOutput.Write(this.GetSourceAsString());
}
}
}
}

View file

@ -36,7 +36,11 @@ namespace Cosmos.IL2CPU.X86.IL
case 1:
case 2:
{
new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset };
bool signed = IsIntegerSigned(xVar.LocalType);
if (signed)
new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset };
else
new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset };
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
break;
}

View file

@ -229,6 +229,21 @@ namespace Cosmos.IL2CPU.X86 {
}
}
public static bool IsIntegerSigned(Type aType)
{
switch (aType.FullName)
{
case "System.SByte":
case "System.Int16":
case "System.Int32":
case "System.Int64":
//TODO not sure about this case "System.IntPtr":
//TODO not sure aobut this case "System.Enum":
return true;
}
return false;
}
public static uint SizeOfType(Type aType)
{
if (aType.FullName == "System.Void")