Cosmos/source/Cosmos.IL2CPU/IL/Ldarga.cs
fanoI ad960c9a1a Continuation of Float work
- Fixed Single.ToString() on special cases (infinities, NaN and 0) and aumented the range of printable values
- Fixed Double.ToString(): it always printed "Double Overrange" for a bug in opcode ldarga
- Fixed opcode ldarga: the displacement of the argument variable was off of 4 bytes
- Fixed opcodes shr, shr_un and shl when the shift was more that 32 bytes, added to BCL relative tests
- Added BLC tests regarding BitConverter and unsafe code
- Moved the meat of the code of Single.ToString() and Double.ToString() to the class StringHelper together with the analogous methods for numer types
- Re-added _floatsignbit to CosmosAssembler.cs so the neg test should not fail anymore
- Removed all code relative to x87 that I had left under #if false
- Clean up
2016-08-22 16:31:22 +02:00

65 lines
2.2 KiB
C#

using System;
using CPUx86 = Cosmos.Assembler.x86;
using Cosmos.Assembler;
using Cosmos.IL2CPU.ILOpCodes;
using Cosmos.Assembler.x86;
using XSharp.Compiler;
using SysReflection = System.Reflection;
namespace Cosmos.IL2CPU.X86.IL
{
[Cosmos.IL2CPU.OpCode( ILOpCode.Code.Ldarga )]
public class Ldarga : ILOp
{
public Ldarga( Cosmos.Assembler.Assembler aAsmblr )
: base( aAsmblr )
{
}
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
{
var xOpVar = (OpVar)aOpCode;
var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, xOpVar.Value);
/*
* The function GetArgumentDisplacement() does not give the correct displacement for the Ldarga opcode
* we need to "fix" it subtracting the argSize and 4
*/
Type xArgType;
if (aMethod.MethodBase.IsStatic)
{
xArgType = aMethod.MethodBase.GetParameters()[xOpVar.Value].ParameterType;
}
else
{
if (xOpVar.Value == 0u)
{
xArgType = aMethod.MethodBase.DeclaringType;
if (xArgType.IsValueType)
{
xArgType = xArgType.MakeByRefType();
}
}
else
{
xArgType = aMethod.MethodBase.GetParameters()[xOpVar.Value - 1].ParameterType;
}
}
uint xArgRealSize = SizeOfType(xArgType);
uint xArgSize = Align(xArgRealSize, 4);
XS.Comment("Arg type = " + xArgType.ToString());
XS.Comment("Arg real size = " + xArgRealSize + " aligned size = " + xArgSize);
xDisplacement -= (int)(xArgSize - 4);
XS.Comment("Real displacement " + xDisplacement);
XS.Set(XSRegisters.EBX, (uint)(xDisplacement));
XS.Set(XSRegisters.EAX, XSRegisters.EBP);
XS.Add(XSRegisters.EAX, XSRegisters.EBX);
XS.Push(XSRegisters.EAX);
}
}
}