diff --git a/source/Indy.IL2CPU.IL.X86/Call.cs b/source/Indy.IL2CPU.IL.X86/Call.cs index b50b1cea3..13b1ec41a 100644 --- a/source/Indy.IL2CPU.IL.X86/Call.cs +++ b/source/Indy.IL2CPU.IL.X86/Call.cs @@ -28,7 +28,7 @@ namespace Indy.IL2CPU.IL.X86 { Initialize(aMethod, aCurrentILOffset); } - public static void EmitExceptionLogic(Assembler.Assembler aAssembler, int aCurrentOpOffset, MethodInformation aMethodInfo, string aNextLabel, bool aDoTest) { + public static void EmitExceptionLogic(Assembler.Assembler aAssembler, int aCurrentOpOffset, MethodInformation aMethodInfo, string aNextLabel, bool aDoTest, Action aCleanup) { string xJumpTo = MethodFooterOp.EndOfMethodLabelNameException; if (aMethodInfo != null && aMethodInfo.CurrentHandler != null) { if (aMethodInfo.CurrentHandler.HandlerOffset >= aCurrentOpOffset && (aMethodInfo.CurrentHandler.HandlerLength + aMethodInfo.CurrentHandler.HandlerOffset) <= aCurrentOpOffset) { @@ -53,7 +53,13 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.JumpAlways(xJumpTo); } else { new CPUx86.Test("ecx", "2"); - new CPUx86.JumpIfNotEquals(xJumpTo); + if (aCleanup != null) { + new CPUx86.JumpIfEquals(aNextLabel); + aCleanup(); + new CPUx86.JumpAlways(xJumpTo); + } else { + new CPUx86.JumpIfNotEquals(xJumpTo); + } } } @@ -106,7 +112,7 @@ namespace Indy.IL2CPU.IL.X86 { } public void Assemble(string aMethod, int aArgumentCount) { new CPUx86.Call(aMethod); - EmitExceptionLogic(Assembler, mCurrentILOffset, mMethodInfo, mNextLabelName, true); + EmitExceptionLogic(Assembler, mCurrentILOffset, mMethodInfo, mNextLabelName, true, null); for (int i = 0; i < aArgumentCount; i++) { Assembler.StackContents.Pop(); } diff --git a/source/Indy.IL2CPU.IL.X86/Callvirt.cs b/source/Indy.IL2CPU.IL.X86/Callvirt.cs index a72b9be8b..ad198ddff 100644 --- a/source/Indy.IL2CPU.IL.X86/Callvirt.cs +++ b/source/Indy.IL2CPU.IL.X86/Callvirt.cs @@ -67,7 +67,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Pushd(CPUx86.Registers.AtEAX); new CPUx86.Pushd("0" + mMethodIdentifier.ToString("X") + "h"); new CPUx86.Call(CPU.Label.GenerateLabelName(VTablesImplRefs.GetMethodAddressForTypeRef)); - Call.EmitExceptionLogic(Assembler, mCurrentILOffset, mCurrentMethodInfo, mLabelName + "_AfterAddressCheck", true); + Call.EmitExceptionLogic(Assembler, mCurrentILOffset, mCurrentMethodInfo, mLabelName + "_AfterAddressCheck", true, xEmitCleanup); new CPU.Label(mLabelName + "_AfterAddressCheck"); if (mTargetMethodInfo.Arguments[0].ArgumentType == typeof(object)) { new CPUx86.Push("eax"); diff --git a/source/Indy.IL2CPU.IL.X86/Castclass.cs b/source/Indy.IL2CPU.IL.X86/Castclass.cs index 28a9ef19c..fa202785f 100644 --- a/source/Indy.IL2CPU.IL.X86/Castclass.cs +++ b/source/Indy.IL2CPU.IL.X86/Castclass.cs @@ -52,7 +52,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPU.Label(mReturnNullLabel); new CPUx86.Add("esp", "4"); Newobj.Assemble(Assembler, typeof(InvalidCastException).GetConstructor(new Type[0]), Engine.RegisterType(typeof(InvalidCastException)), mThisLabel, mMethodInfo, mCurrentILOffset); - Call.EmitExceptionLogic(Assembler, mCurrentILOffset, mMethodInfo, mNextOpLabel, false); + Call.EmitExceptionLogic(Assembler, mCurrentILOffset, mMethodInfo, mNextOpLabel, false, null); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Newobj.cs b/source/Indy.IL2CPU.IL.X86/Newobj.cs index c8e1f2a05..12162a461 100644 --- a/source/Indy.IL2CPU.IL.X86/Newobj.cs +++ b/source/Indy.IL2CPU.IL.X86/Newobj.cs @@ -102,7 +102,7 @@ namespace Indy.IL2CPU.IL.X86 { foreach (var xStackInt in aAssembler.StackContents) { new CPUx86.Add("esp", xStackInt.Size.ToString()); } - Call.EmitExceptionLogic(aAssembler, aCurrentILOffset, aCurrentMethodInformation, aCurrentLabel + "_NO_ERROR_4", false); + Call.EmitExceptionLogic(aAssembler, aCurrentILOffset, aCurrentMethodInformation, aCurrentLabel + "_NO_ERROR_4", false, null); new CPU.Label(aCurrentLabel + "_NO_ERROR_4"); new CPUx86.Pop(CPUx86.Registers.EAX); // aAssembler.StackSizes.Pop(); diff --git a/source/Indy.IL2CPU.IL.X86/Op.cs b/source/Indy.IL2CPU.IL.X86/Op.cs index 321d2c32e..e3ad5ab19 100644 --- a/source/Indy.IL2CPU.IL.X86/Op.cs +++ b/source/Indy.IL2CPU.IL.X86/Op.cs @@ -30,7 +30,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Call(Label.GenerateLabelName(CPU.Assembler.CurrentExceptionOccurredRef)); new CPUx86.Move("ecx", "3"); aEmitCleanupMethod(); - Call.EmitExceptionLogic(aAssembler, aCurrentILOffset, aMethodInfo, aNextLabel, false); + Call.EmitExceptionLogic(aAssembler, aCurrentILOffset, aMethodInfo, aNextLabel, false, null); } public Op(ILReader aReader, MethodInformation aMethodInfo) diff --git a/source/Indy.IL2CPU.IL.X86/Throw.cs b/source/Indy.IL2CPU.IL.X86/Throw.cs index 7de89d676..45c644032 100644 --- a/source/Indy.IL2CPU.IL.X86/Throw.cs +++ b/source/Indy.IL2CPU.IL.X86/Throw.cs @@ -23,7 +23,7 @@ namespace Indy.IL2CPU.IL.X86 { Engine.QueueMethod(CPU.Assembler.CurrentExceptionOccurredRef); new CPUx86.Call(CPU.Label.GenerateLabelName(CPU.Assembler.CurrentExceptionOccurredRef)); new CPUx86.Move("ecx", "3"); - Call.EmitExceptionLogic(aAssembler,aCurrentILOffset, aMethodInfo, null, false); + Call.EmitExceptionLogic(aAssembler, aCurrentILOffset, aMethodInfo, null, false, null); aAssembler.StackContents.Pop(); }