From 47955bf68c1f573dd723980e74b90cb8764b3cca Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Mon, 23 Aug 2010 16:59:41 +0000 Subject: [PATCH] --- source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldc_I4.cs | 2 +- .../IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs | 4 +- .../IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs | 4 +- .../IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs | 8 ++-- source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs | 40 ++++++++----------- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldc_I4.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldc_I4.cs index d0a515007..3fe4676df 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldc_I4.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldc_I4.cs @@ -13,7 +13,7 @@ namespace Cosmos.IL2CPU.X86.IL public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) { - new CPUx86.Push { DestinationValue = ( ( OpInt )aOpCode ).Value }; + new CPUx86.Push { DestinationValue = (uint)( ( OpInt )aOpCode ).Value }; Assembler.Stack.Push( 4, typeof( int ) ); } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs index a9bfa2cc6..f346d1a48 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs @@ -5,9 +5,9 @@ using System.Text; namespace Cosmos.IL2CPU.ILOpCodes { public class OpInt : ILOpCode { - public readonly UInt32 Value; + public readonly Int32 Value; - public OpInt(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + public OpInt(Code aOpCode, int aPos, int aNextPos, Int32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs index 9d9539ebb..3640831c1 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs @@ -5,9 +5,9 @@ using System.Text; namespace Cosmos.IL2CPU.ILOpCodes { public class OpSig : ILOpCode { - public readonly UInt32 Value; + public readonly Int32 Value; - public OpSig(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + public OpSig(Code aOpCode, int aPos, int aNextPos, Int32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs index 16817097b..0b56288f0 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs @@ -6,7 +6,7 @@ using System.Reflection; namespace Cosmos.IL2CPU.ILOpCodes { public class OpToken : ILOpCode { - public readonly UInt32 Value; + public readonly Int32 Value; public readonly FieldInfo ValueField; public readonly Type ValueType; @@ -41,16 +41,16 @@ namespace Cosmos.IL2CPU.ILOpCodes { } } - public OpToken(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + public OpToken(Code aOpCode, int aPos, int aNextPos, Int32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; if (ValueIsField) { - ValueField = aModule.ResolveField((int)Value, aTypeGenericArgs, aMethodGenericArgs); + ValueField = aModule.ResolveField(Value, aTypeGenericArgs, aMethodGenericArgs); } if (ValueIsType) { - ValueType = aModule.ResolveType((int)Value, aTypeGenericArgs, aMethodGenericArgs); + ValueType = aModule.ResolveType(Value, aTypeGenericArgs, aMethodGenericArgs); } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs index 51eff05d8..23b9d3c6b 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs @@ -184,7 +184,7 @@ namespace Cosmos.IL2CPU { xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 8, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_M1: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0xFFFFFFFF, xCurrentHandler); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, -1, xCurrentHandler); break; case ILOpCode.Code.Ldloc_0: xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 0, xCurrentHandler); @@ -279,7 +279,7 @@ namespace Cosmos.IL2CPU { #endregion } case OperandType.InlineBrTarget: { - int xTarget = xPos + 4 + (Int32)ReadUInt32(xIL, xPos); + int xTarget = xPos + 4 + (Int32)ReadInt32(xIL, xPos); CheckBranch(xTarget, xIL.Length); xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 4, xTarget, xCurrentHandler); xPos = xPos + 4; @@ -289,24 +289,16 @@ namespace Cosmos.IL2CPU { case OperandType.ShortInlineI: switch (xOpCodeVal) { case ILOpCode.Code.Ldc_I4_S: - // x = x & 0xFFFFFFFC; - // The above code produces: - // ldc.i4.s -4 - // But its getting loaded into a I4, so we have to "extend" it - // - // First we have to cast it to a signed byte, so .NET will extend it properly to a uint. - sbyte xSVal = (sbyte)xIL[xPos]; - uint xVal = (uint)xSVal; - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xVal, xCurrentHandler); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, ((sbyte)xIL[xPos]), xCurrentHandler); break; default: - xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); + xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, ((sbyte)xIL[xPos]), xCurrentHandler); break; } xPos = xPos + 1; break; case OperandType.InlineI: - xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), xCurrentHandler); + xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadInt32(xIL, xPos), xCurrentHandler); xPos = xPos + 4; break; case OperandType.InlineI8: @@ -325,7 +317,7 @@ namespace Cosmos.IL2CPU { // The operand is a 32-bit metadata token. case OperandType.InlineField: { - var xValue = aMethod.Module.ResolveField((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); + var xValue = aMethod.Module.ResolveField((int)ReadInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); xILOpCode = new ILOpCodes.OpField(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; @@ -333,7 +325,7 @@ namespace Cosmos.IL2CPU { // The operand is a 32-bit metadata token. case OperandType.InlineMethod: { - var xValue = aMethod.Module.ResolveMethod((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); + var xValue = aMethod.Module.ResolveMethod((int)ReadInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); xILOpCode = new ILOpCodes.OpMethod(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; @@ -342,22 +334,22 @@ namespace Cosmos.IL2CPU { // 32-bit metadata signature token. case OperandType.InlineSig: //TODO: What are these used for? A breakpoint causes no breaks with current tests... - xILOpCode = new ILOpCodes.OpSig(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), xCurrentHandler); + xILOpCode = new ILOpCodes.OpSig(xOpCodeVal, xOpPos, xPos + 4, ReadInt32(xIL, xPos), xCurrentHandler); xPos = xPos + 4; break; case OperandType.InlineString: - xILOpCode = new ILOpCodes.OpString(xOpCodeVal, xOpPos, xPos + 4, aMethod.Module.ResolveString((int)ReadUInt32(xIL, xPos)), xCurrentHandler); + xILOpCode = new ILOpCodes.OpString(xOpCodeVal, xOpPos, xPos + 4, aMethod.Module.ResolveString((int)ReadInt32(xIL, xPos)), xCurrentHandler); xPos = xPos + 4; break; case OperandType.InlineSwitch: { - int xCount = (int)ReadUInt32(xIL, xPos); + int xCount = (int)ReadInt32(xIL, xPos); xPos = xPos + 4; int xNextOpPos = xPos + xCount * 4; int[] xBranchLocations = new int[xCount]; for (int i = 0; i < xCount; i++) { - xBranchLocations[i] = xNextOpPos + (int)ReadUInt32(xIL, xPos + i * 4); + xBranchLocations[i] = xNextOpPos + (int)ReadInt32(xIL, xPos + i * 4); CheckBranch(xBranchLocations[i], xIL.Length); } xILOpCode = new ILOpCodes.OpSwitch(xOpCodeVal, xOpPos, xPos, xBranchLocations, xCurrentHandler); @@ -367,13 +359,13 @@ namespace Cosmos.IL2CPU { // The operand is a FieldRef, MethodRef, or TypeRef token. case OperandType.InlineTok: - xILOpCode = new ILOpCodes.OpToken(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), aMethod.Module, xTypeGenArgs, xMethodGenArgs, xCurrentHandler); + xILOpCode = new ILOpCodes.OpToken(xOpCodeVal, xOpPos, xPos + 4, ReadInt32(xIL, xPos), aMethod.Module, xTypeGenArgs, xMethodGenArgs, xCurrentHandler); xPos = xPos + 4; break; // 32-bit metadata token. case OperandType.InlineType: { - var xValue = aMethod.Module.ResolveType((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); + var xValue = aMethod.Module.ResolveType((int)ReadInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); xILOpCode = new ILOpCodes.OpType(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; @@ -424,8 +416,8 @@ namespace Cosmos.IL2CPU { return (UInt16)(aBytes[aPos + 1] << 8 | aBytes[aPos]); } - private UInt32 ReadUInt32(byte[] aBytes, int aPos) { - return (UInt32)(aBytes[aPos + 3] << 24 | aBytes[aPos + 2] << 16 | aBytes[aPos + 1] << 8 | aBytes[aPos]); + private Int32 ReadInt32(byte[] aBytes, int aPos) { + return (Int32)(aBytes[aPos + 3] << 24 | aBytes[aPos + 2] << 16 | aBytes[aPos + 1] << 8 | aBytes[aPos]); } private UInt64 ReadUInt64(byte[] aBytes, int aPos) { @@ -437,4 +429,4 @@ namespace Cosmos.IL2CPU { } } -} \ No newline at end of file +}