diff --git a/source/MatthijsTest/Program.cs b/source/MatthijsTest/Program.cs index 8ffa6da7f..ededf931d 100644 --- a/source/MatthijsTest/Program.cs +++ b/source/MatthijsTest/Program.cs @@ -38,6 +38,19 @@ namespace MatthijsTest #endregion public static void Init(){ + try + { + Console.WriteLine("Try"); + throw new Exception("Error message"); + } + catch(Exception E) + { + Console.Write("Error: "); + Console.WriteLine(E.ToString()); + } + Console.WriteLine("Klaar"); + while (true) + ; var xInit = true; if (xInit) { diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Castclass.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Castclass.cs index 0bac746ef..dbaa90832 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Castclass.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Castclass.cs @@ -35,7 +35,7 @@ namespace Cosmos.IL2CPU.X86.IL Assembler.Stack.Push( new StackContents.Item( 4, typeof( object ) ) ); Assembler.Stack.Push( new StackContents.Item( 4, typeof( object ) ) ); System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" ); - new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) ); + new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler ) ); new Label( xCurrentMethodLabel + "_After_IsInstance_Call" ); Assembler.Stack.Pop(); new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Isinst.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Isinst.cs index 885abaa0e..87ae7742a 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Isinst.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Isinst.cs @@ -33,7 +33,7 @@ namespace Cosmos.IL2CPU.X86.IL System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" ); - new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance) ); + new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler)); new Label( GetLabel( aMethod, aOpCode ) + "_After_IsInstance_Call" ); Assembler.Stack.Pop(); diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Throw.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Throw.cs index a21497b0f..7eccfc61b 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Throw.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Throw.cs @@ -15,13 +15,12 @@ namespace Cosmos.IL2CPU.X86.IL public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) { #warning TODO: Implement exception -// new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; -// new CPUx86.Move { DestinationRef = ElementReference.New( DataMember.GetStaticFieldName( Assembler.Assembler.CurrentExceptionRef ) ), DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EAX }; + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Move { DestinationRef = ElementReference.New( DataMember.GetStaticFieldName( ExceptionHelperRefs.CurrentExceptionRef ) ), DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EAX }; //new CPUx86.Call { DestinationLabel = aExceptionOccurredLabel }; - //new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceValue = 3 }; - //Call.EmitExceptionLogic( Assembler, ( uint )aCurrentILOffset, aMethodInfo, null, false, null ); - new CPUx86.ClrInterruptFlag(); - new CPUx86.Halt(); + new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceValue = 3 }; + Call.EmitExceptionLogic( Assembler,aMethod, aOpCode, false, null ); + Assembler.Stack.Pop(); diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox.cs index a4169cc3f..68d42872d 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox.cs @@ -38,7 +38,7 @@ namespace Cosmos.IL2CPU.X86.IL new CPUx86.Push { DestinationRef = ElementReference.New( xTypeID ), DestinationIsIndirect = true }; Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) ); System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" ); - new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) ); + new Call(Assembler).Execute(aMethod, new OpMethod(ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler)); new Label( BaseLabel + "_After_IsInstance_Call" ); new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox_Any.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox_Any.cs index 0a74e6349..9e4fd3859 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox_Any.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Unbox_Any.cs @@ -38,7 +38,7 @@ namespace Cosmos.IL2CPU.X86.IL new CPUx86.Push { DestinationRef = ElementReference.New( xTypeID ), DestinationIsIndirect = true }; Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) ); System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" ); - new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) ); + new Call(Assembler).Execute(aMethod, new OpMethod(ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler)); new Label( BaseLabel + "_After_IsInstance_Call" ); new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs index c26f72f1c..d51c2c5f6 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs @@ -19,12 +19,12 @@ namespace Cosmos.IL2CPU.X86 { Assembler = (Assembler)aAsmblr; } - protected void Jump_Exception(MethodInfo aMethod) { + protected static void Jump_Exception(MethodInfo aMethod) { // todo: port to numeric labels new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AssemblerNasm.EndOfMethodLabelNameException }; } - protected void Jump_End(MethodInfo aMethod) { + protected static void Jump_End(MethodInfo aMethod) { new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AssemblerNasm.EndOfMethodLabelNameNormal }; } @@ -123,5 +123,74 @@ namespace Cosmos.IL2CPU.X86 { orderby item.Offset descending select item.Offset + item.Size).FirstOrDefault(); } + + public static void EmitExceptionLogic(Assembler aAssembler, MethodInfo aMethodInfo, ILOpCode aCurrentOpCode, bool aDoTest, Action aCleanup) + { + string xJumpTo = null; + if (aCurrentOpCode != null && aCurrentOpCode.CurrentExceptionHandler != null) + { + // todo add support for nested handlers, see comment in Engine.cs + //if (!((aMethodInfo.CurrentHandler.HandlerOffset < aCurrentOpOffset) || (aMethodInfo.CurrentHandler.HandlerLength + aMethodInfo.CurrentHandler.HandlerOffset) <= aCurrentOpOffset)) { + new Comment(String.Format("CurrentOffset = {0}, HandlerStartOffset = {1}", aCurrentOpCode.Position, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset)); + if (aCurrentOpCode.CurrentExceptionHandler.HandlerOffset > aCurrentOpCode.Position) + { + switch (aCurrentOpCode.CurrentExceptionHandler.Flags) + { + case ExceptionHandlingClauseOptions.Clause: + { + xJumpTo = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset); + break; + } + case ExceptionHandlingClauseOptions.Finally: + { + xJumpTo = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset); + break; + } + default: + { + throw new Exception("ExceptionHandlerType '" + aCurrentOpCode.CurrentExceptionHandler.Flags.ToString() + "' not supported yet!"); + } + } + } + } + if (!aDoTest) + { + //new CPUx86.Call("_CODE_REQUESTED_BREAK_"); + if (xJumpTo == null) + { + Jump_End(aMethodInfo); + } + else + { + new CPUx86.Jump { DestinationLabel = xJumpTo }; + } + + } + else + { + new CPUx86.Test { DestinationReg = CPUx86.Registers.ECX, SourceValue = 2 }; + + if (aCleanup != null) + { + new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Equal, DestinationLabel = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.NextPosition) }; + aCleanup(); + if (xJumpTo == null) + { + Jump_End(aMethodInfo); + } + else + { new CPUx86.Jump { DestinationLabel = xJumpTo }; } + } + else + { + if (xJumpTo == null) + { + Jump_End(aMethodInfo); + } + else + { new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo }; } + } + } + } } } \ No newline at end of file diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ExceptionHelper.cs b/source2/IL2PCU/Cosmos.IL2CPU/ExceptionHelper.cs index 08301b7ce..ed0c4d415 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ExceptionHelper.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ExceptionHelper.cs @@ -2,12 +2,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Reflection; namespace Cosmos.IL2CPU { public static class ExceptionHelper { + public static Exception CurrentException; + public static void ThrowNotImplemented(string aError) { Console.WriteLine(aError); throw new NotImplementedException(aError); } } + + public static class ExceptionHelperRefs + { + public static readonly FieldInfo CurrentExceptionRef; + static ExceptionHelperRefs() + { + CurrentExceptionRef = typeof(ExceptionHelper).GetField("CurrentException"); + } + } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCode.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCode.cs index 106bab033..64e9a674e 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCode.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCode.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using SR = System.Reflection; namespace Cosmos.IL2CPU { // ILOpcode represents the opcode during for scanning. @@ -248,10 +249,13 @@ namespace Cosmos.IL2CPU { // position of the next instruction public readonly int NextPosition; - protected ILOpCode(Code aOpCode, int aPos, int aNextPos) { + public readonly SR.ExceptionHandlingClause CurrentExceptionHandler; + + protected ILOpCode(Code aOpCode, int aPos, int aNextPos, SR.ExceptionHandlingClause aCurrentExceptionHandler) { OpCode = aOpCode; Position = aPos; NextPosition = aNextPos; + CurrentExceptionHandler = aCurrentExceptionHandler; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpBranch.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpBranch.cs index b39d0054f..5c2df8785 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpBranch.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpBranch.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpBranch : ILOpCode { public readonly int Value; - public OpBranch(Code aOpCode, int aPos, int aNextPos, int aValue) - : base(aOpCode, aPos, aNextPos) { + public OpBranch(Code aOpCode, int aPos, int aNextPos, int aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpDouble.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpDouble.cs index 4ff151a38..b68e4abc5 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpDouble.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpDouble.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpDouble : ILOpCode { public readonly Double Value; - public OpDouble(Code aOpCode, int aPos, int aNextPos, Double aValue) - : base(aOpCode, aPos, aNextPos) { + public OpDouble(Code aOpCode, int aPos, int aNextPos, Double aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpField.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpField.cs index 53679e79a..9e8cbed22 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpField.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpField.cs @@ -8,8 +8,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpField : ILOpCode { public readonly FieldInfo Value; - public OpField(Code aOpCode, int aPos, int aNextPos, FieldInfo aValue) - : base(aOpCode, aPos, aNextPos) { + public OpField(Code aOpCode, int aPos, int aNextPos, FieldInfo aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs index 85d46e9f3..a9bfa2cc6 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpInt : ILOpCode { public readonly UInt32 Value; - public OpInt(Code aOpCode, int aPos, int aNextPos, UInt32 aValue) - : base(aOpCode, aPos, aNextPos) { + public OpInt(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt64.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt64.cs index a78b4b7e3..008a3bfac 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt64.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpInt64.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpInt64 : ILOpCode { public readonly UInt64 Value; - public OpInt64(Code aOpCode, int aPos, int aNextPos, UInt64 aValue) - : base(aOpCode, aPos, aNextPos) { + public OpInt64(Code aOpCode, int aPos, int aNextPos, UInt64 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs index 2cd226015..7b60fd01a 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs @@ -11,8 +11,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public MethodBase BaseMethod; public uint BaseMethodUID; - public OpMethod(Code aOpCode, int aPos, int aNextPos, MethodBase aValue) - : base(aOpCode, aPos, aNextPos) { + public OpMethod(Code aOpCode, int aPos, int aNextPos, MethodBase aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpNone.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpNone.cs index 795ff44ea..a4aa7fcd9 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpNone.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpNone.cs @@ -6,8 +6,8 @@ using System.Text; namespace Cosmos.IL2CPU.ILOpCodes { public class OpNone : ILOpCode { - public OpNone(Code aOpCode, int aPos, int aNextPos) - : base(aOpCode, aPos, aNextPos) { + public OpNone(Code aOpCode, int aPos, int aNextPos, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs index 1488ffb15..9d9539ebb 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSig.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpSig : ILOpCode { public readonly UInt32 Value; - public OpSig(Code aOpCode, int aPos, int aNextPos, UInt32 aValue) - : base(aOpCode, aPos, aNextPos) { + public OpSig(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSingle.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSingle.cs index 8d63a01b8..844d5120a 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSingle.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSingle.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpSingle : ILOpCode { public readonly Single Value; - public OpSingle(Code aOpCode, int aPos, int aNextPos, Single aValue) - : base(aOpCode, aPos, aNextPos) { + public OpSingle(Code aOpCode, int aPos, int aNextPos, Single aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpString.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpString.cs index d55c05bc3..ba2b26dfb 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpString.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpString.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpString : ILOpCode { public readonly string Value; - public OpString(Code aOpCode, int aPos, int aNextPos, string aValue) - : base(aOpCode, aPos, aNextPos) { + public OpString(Code aOpCode, int aPos, int aNextPos, string aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSwitch.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSwitch.cs index 6511dcf32..b16a0ef94 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSwitch.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpSwitch.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpSwitch : ILOpCode { public readonly int[] BranchLocations; - public OpSwitch(Code aOpCode, int aPos, int aNextPos, int[] aBranchLocations) - : base(aOpCode, aPos, aNextPos) { + public OpSwitch(Code aOpCode, int aPos, int aNextPos, int[] aBranchLocations, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { BranchLocations = aBranchLocations; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs index 2fc99ae75..16817097b 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpToken.cs @@ -41,8 +41,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { } } - public OpToken(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs) - : base(aOpCode, aPos, aNextPos) { + public OpToken(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; if (ValueIsField) { diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpType.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpType.cs index 32c8e4532..3c31472b7 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpType.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpType.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpType : ILOpCode { public readonly Type Value; - public OpType(Code aOpCode, int aPos, int aNextPos, Type aValue) - : base(aOpCode, aPos, aNextPos) { + public OpType(Code aOpCode, int aPos, int aNextPos, Type aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpVar.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpVar.cs index 0fa3e8b4d..358d7dc28 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpVar.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/OpVar.cs @@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes { public class OpVar : ILOpCode { public readonly UInt16 Value; - public OpVar(Code aOpCode, int aPos, int aNextPos, UInt16 aValue) - : base(aOpCode, aPos, aNextPos) { + public OpVar(Code aOpCode, int aPos, int aNextPos, UInt16 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler) + : base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) { Value = aValue; } } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs index a05c88127..f18e8943f 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs @@ -60,7 +60,68 @@ namespace Cosmos.IL2CPU { var xIL = xBody.GetILAsByteArray(); int xPos = 0; while (xPos < xIL.Length) { - ILOpCode.Code xOpCodeVal; + ExceptionHandlingClause xCurrentHandler = null; + #region Determine current handler + // todo: add support for nested handlers using a stack or so.. + foreach (ExceptionHandlingClause xHandler in xBody.ExceptionHandlingClauses) + { + if (xHandler.TryOffset > 0) + { + if (xHandler.TryOffset <= xPos && (xHandler.TryLength + xHandler.TryOffset + 1) > xPos) // + 1 because index should be less than the try + { + if (xCurrentHandler == null) + { + xCurrentHandler = xHandler; + continue; + } + else if (xHandler.TryOffset > xCurrentHandler.TryOffset && (xHandler.TryLength + xHandler.TryOffset) < (xCurrentHandler.TryLength + xCurrentHandler.TryOffset)) + { + // only replace if the current found handler is narrower + xCurrentHandler = xHandler; + continue; + } + } + } + if (xHandler.HandlerOffset > 0) + { + if (xHandler.HandlerOffset <= xPos && (xHandler.HandlerOffset + xHandler.HandlerLength + 1) > xPos) + { + if (xCurrentHandler == null) + { + xCurrentHandler = xHandler; + continue; + } + else if (xHandler.HandlerOffset > xCurrentHandler.HandlerOffset && (xHandler.HandlerOffset + xHandler.HandlerLength) < (xCurrentHandler.HandlerOffset + xCurrentHandler.HandlerLength)) + { + // only replace if the current found handler is narrower + xCurrentHandler = xHandler; + continue; + } + } + } + if ((xHandler.Flags & ExceptionHandlingClauseOptions.Filter) > 0) + { + if (xHandler.FilterOffset > 0) + { + if (xHandler.FilterOffset <= xPos) + { + if (xCurrentHandler == null) + { + xCurrentHandler = xHandler; + continue; + } + else if (xHandler.FilterOffset > xCurrentHandler.FilterOffset) + { + // only replace if the current found handler is narrower + xCurrentHandler = xHandler; + continue; + } + } + } + } + } + #endregion + ILOpCode.Code xOpCodeVal; OpCode xOpCode; int xOpPos = xPos; if (xIL[xPos] == 0xFE) { @@ -82,73 +143,73 @@ namespace Cosmos.IL2CPU { // by allowing them to ignore the shortcuts switch (xOpCodeVal) { case ILOpCode.Code.Ldarg_0: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 0); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 0, xCurrentHandler); break; case ILOpCode.Code.Ldarg_1: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 1); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 1, xCurrentHandler); break; case ILOpCode.Code.Ldarg_2: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 2); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 2, xCurrentHandler); break; case ILOpCode.Code.Ldarg_3: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 3); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 3, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_0: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_1: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 1); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 1, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_2: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 2); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 2, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_3: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 3); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 3, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_4: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 4); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 4, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_5: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 5); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 5, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_6: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 6); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 6, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_7: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 7); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 7, xCurrentHandler); break; case ILOpCode.Code.Ldc_I4_8: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 8); + 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); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0xFFFFFFFF, xCurrentHandler); break; case ILOpCode.Code.Ldloc_0: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 0); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 0, xCurrentHandler); break; case ILOpCode.Code.Ldloc_1: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 1); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 1, xCurrentHandler); break; case ILOpCode.Code.Ldloc_2: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 2); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 2, xCurrentHandler); break; case ILOpCode.Code.Ldloc_3: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 3); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 3, xCurrentHandler); break; case ILOpCode.Code.Stloc_0: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 0); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 0, xCurrentHandler); break; case ILOpCode.Code.Stloc_1: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 1); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 1, xCurrentHandler); break; case ILOpCode.Code.Stloc_2: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 2); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 2, xCurrentHandler); break; case ILOpCode.Code.Stloc_3: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 3); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 3, xCurrentHandler); break; default: - xILOpCode = new ILOpCodes.OpNone(xOpCodeVal, xOpPos, xPos); + xILOpCode = new ILOpCodes.OpNone(xOpCodeVal, xOpPos, xPos, xCurrentHandler); break; } break; @@ -162,49 +223,49 @@ namespace Cosmos.IL2CPU { CheckBranch(xTarget, xIL.Length); switch (xOpCodeVal) { case ILOpCode.Code.Beq_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Beq, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Beq, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Bge_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Bge_Un_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge_Un, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Bgt_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Bgt_Un_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt_Un, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Ble_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Ble_Un_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble_Un, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Blt_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Blt_Un_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt_Un, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Bne_Un_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bne_Un, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bne_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Br_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Br, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Br, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Brfalse_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brfalse, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brfalse, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Brtrue_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brtrue, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brtrue, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; case ILOpCode.Code.Leave_S: - xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Leave, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Leave, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; default: - xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 1, xTarget); + xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 1, xTarget, xCurrentHandler); break; } xPos = xPos + 1; @@ -213,7 +274,7 @@ namespace Cosmos.IL2CPU { case OperandType.InlineBrTarget: { int xTarget = xPos + 4 + (Int32)ReadUInt32(xIL, xPos); CheckBranch(xTarget, xIL.Length); - xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 4, xTarget); + xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 4, xTarget, xCurrentHandler); xPos = xPos + 4; break; } @@ -221,36 +282,36 @@ namespace Cosmos.IL2CPU { case OperandType.ShortInlineI: switch (xOpCodeVal) { case ILOpCode.Code.Ldc_I4_S: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; default: - xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; } xPos = xPos + 1; break; case OperandType.InlineI: - xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos)); + xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), xCurrentHandler); xPos = xPos + 4; break; case OperandType.InlineI8: - xILOpCode = new ILOpCodes.OpInt64(xOpCodeVal, xOpPos, xPos + 8, ReadUInt64(xIL, xPos)); + xILOpCode = new ILOpCodes.OpInt64(xOpCodeVal, xOpPos, xPos + 8, ReadUInt64(xIL, xPos), xCurrentHandler); xPos = xPos + 8; break; case OperandType.ShortInlineR: - xILOpCode = new ILOpCodes.OpSingle(xOpCodeVal, xOpPos, xPos + 4, BitConverter.ToSingle(xIL, xPos)); + xILOpCode = new ILOpCodes.OpSingle(xOpCodeVal, xOpPos, xPos + 4, BitConverter.ToSingle(xIL, xPos), xCurrentHandler); xPos = xPos + 4; break; case OperandType.InlineR: - xILOpCode = new ILOpCodes.OpDouble(xOpCodeVal, xOpPos, xPos + 8, BitConverter.ToDouble(xIL, xPos)); + xILOpCode = new ILOpCodes.OpDouble(xOpCodeVal, xOpPos, xPos + 8, BitConverter.ToDouble(xIL, xPos), xCurrentHandler); xPos = xPos + 8; break; // The operand is a 32-bit metadata token. case OperandType.InlineField: { var xValue = aMethod.Module.ResolveField((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs); - xILOpCode = new ILOpCodes.OpField(xOpCodeVal, xOpPos, xPos + 4, xValue); + xILOpCode = new ILOpCodes.OpField(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; } @@ -258,7 +319,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); - xILOpCode = new ILOpCodes.OpMethod(xOpCodeVal, xOpPos, xPos + 4, xValue); + xILOpCode = new ILOpCodes.OpMethod(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; } @@ -266,12 +327,12 @@ 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)); + xILOpCode = new ILOpCodes.OpSig(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(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))); + xILOpCode = new ILOpCodes.OpString(xOpCodeVal, xOpPos, xPos + 4, aMethod.Module.ResolveString((int)ReadUInt32(xIL, xPos)), xCurrentHandler); xPos = xPos + 4; break; @@ -284,21 +345,21 @@ namespace Cosmos.IL2CPU { xBranchLocations[i] = xNextOpPos + (int)ReadUInt32(xIL, xPos + i * 4); CheckBranch(xBranchLocations[i], xIL.Length); } - xILOpCode = new ILOpCodes.OpSwitch(xOpCodeVal, xOpPos, xPos, xBranchLocations); + xILOpCode = new ILOpCodes.OpSwitch(xOpCodeVal, xOpPos, xPos, xBranchLocations, xCurrentHandler); xPos = xNextOpPos; break; } // 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); + xILOpCode = new ILOpCodes.OpToken(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(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); - xILOpCode = new ILOpCodes.OpType(xOpCodeVal, xOpPos, xPos + 4, xValue); + xILOpCode = new ILOpCodes.OpType(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler); xPos = xPos + 4; break; } @@ -306,31 +367,31 @@ namespace Cosmos.IL2CPU { case OperandType.ShortInlineVar: switch (xOpCodeVal) { case ILOpCode.Code.Ldloc_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; case ILOpCode.Code.Ldloca_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloca, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloca, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; case ILOpCode.Code.Ldarg_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; case ILOpCode.Code.Ldarga_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarga, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarga, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; case ILOpCode.Code.Starg_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Starg, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Starg, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; case ILOpCode.Code.Stloc_S: - xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; default: - xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos]); + xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); break; } xPos = xPos + 1; break; case OperandType.InlineVar: - xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 2, ReadUInt16(xIL, xPos)); + xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 2, ReadUInt16(xIL, xPos), xCurrentHandler); xPos = xPos + 2; break; diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs index b3f22cda3..7ef6ed62a 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs @@ -243,6 +243,7 @@ namespace Cosmos.IL2CPU { Queue(xThrowHelper.GetMethod("ThrowInvalidOperationException", BindingFlags.NonPublic | BindingFlags.Static), null, "Explicit Entry"); Queue(typeof(MulticastDelegate).GetMethod("GetInvocationList"), null, "Explicit Entry"); + Queue(ExceptionHelperRefs.CurrentExceptionRef, null, "Explicit Entry"); //System_Delegate____System_MulticastDelegate_GetInvocationList__ // Start from entry point of this program