Esempio n. 1
0
        public static void EmitExceptionLogic(Cosmos.Assembler.Assembler aAssembler, MethodInfo aMethodInfo, ILOpCode aCurrentOpCode, bool aDoTest, Action aCleanup, string aJumpTargetNoException)
        {
            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 is true, we check ECX for exception flags
            if (!aDoTest)
            {
                //new CPU.Call("_CODE_REQUESTED_BREAK_");
                if (xJumpTo == null)
                {
                    Jump_Exception(aMethodInfo);
                }
                else
                {
                    new CPU.Jump {
                        DestinationLabel = xJumpTo
                    };
                }
            }
            else
            {
                new CPU.Test {
                    DestinationReg = CPU.Registers.ECX, SourceValue = 2
                };

                if (aCleanup != null)
                {
                    new CPU.ConditionalJump {
                        Condition = CPU.ConditionalTestEnum.Equal, DestinationLabel = aJumpTargetNoException
                    };
                    aCleanup();
                    if (xJumpTo == null)
                    {
                        new CPU.ConditionalJump {
                            Condition = CPU.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssembler.EndOfMethodLabelNameException
                        };
                    }
                    else
                    {
                        new CPU.ConditionalJump {
                            Condition = CPU.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo
                        };
                    }
                }
                else
                {
                    if (xJumpTo == null)
                    {
                        new CPU.ConditionalJump {
                            Condition = CPU.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssembler.EndOfMethodLabelNameException
                        };
                    }
                    else
                    {
                        new CPU.ConditionalJump {
                            Condition = CPU.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo
                        };
                    }
                }
            }
        }
Esempio n. 2
0
 public static void EmitExceptionLogic(Cosmos.Assembler.Assembler aAssembler, MethodInfo aMethodInfo, ILOpCode aCurrentOpCode, bool aDoTest, Action aCleanup)
 {
     EmitExceptionLogic(aAssembler, aMethodInfo, aCurrentOpCode, aDoTest, aCleanup, ILOp.GetLabel(aMethodInfo, aCurrentOpCode.NextPosition));
 }